> ## Documentation Index
> Fetch the complete documentation index at: https://docs.postsyncer.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Create Label

> Create a new label to categorize your social media posts

## Create Label

Creates a new label to help categorize and organize your social media posts. Labels can be used to group related content together for better organization and filtering.

### Request

<ParamField body="workspace_id" type="integer" required>
  The ID of the workspace where the label will be created
</ParamField>

<ParamField body="name" type="string" required max="255">
  The name of the label
</ParamField>

<ParamField body="color" type="string" required>
  Hex color code for the label (e.g., "#ff0000" for red)
</ParamField>

<RequestExample>
  ```json theme={null}
  {
    "workspace_id": 1,
    "name": "Product Launch",
    "color": "#ff0000"
  }
  ```
</RequestExample>

### Response

<ResponseField name="id" type="integer">
  Unique identifier for the created label
</ResponseField>

<ResponseField name="name" type="string">
  The name of the label
</ResponseField>

<ResponseField name="color" type="string">
  The hex color code of the label
</ResponseField>

<ResponseField name="workspace" type="object">
  Information about the label's workspace
</ResponseField>

<ResponseField name="created_at" type="string">
  Creation timestamp in workspace timezone
</ResponseField>

<ResponseField name="updated_at" type="string">
  Last update timestamp in workspace timezone
</ResponseField>

<ResponseExample>
  ```json theme={null}
  { 
    "id": 16,
    "name": "Product Launch",
    "color": "#ff0000",
    "workspace": {
        "id": 12,
        "name": "abdulmejidshemsuawel",
        "slug": "abdulmejidshemsuawel",
        "type": "PERSONAL",
        "logo": null,
        "timezone": "Africa/Addis_Ababa",
        "language": "en"
    } 
  }
  ```
</ResponseExample>

### Code Examples

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST "https://postsyncer.com/api/v1/labels" \
    -H "Authorization: Bearer YOUR_API_TOKEN" \
    -H "Content-Type: application/json" \
    -d '{
      "workspace_id": 1,
      "name": "Product Launch",
      "color": "#ff0000"
    }'
  ```

  ```javascript Node.js theme={null}
  const axios = require('axios');

  const createLabel = async () => {
    try {
      const response = await axios.post('https://postsyncer.com/api/v1/labels', {
        workspace_id: 1,
        name: 'Product Launch',
        color: '#ff0000'
      }, {
        headers: {
          'Authorization': 'Bearer YOUR_API_TOKEN',
          'Content-Type': 'application/json'
        }
      });
      
      console.log('Label created:', response.data);
    } catch (error) {
      console.error('Error creating label:', error.response?.data || error.message);
    }
  };

  createLabel();
  ```

  ```php PHP theme={null}
  <?php

  $data = [
      'workspace_id' => 1,
      'name' => 'Product Launch',
      'color' => '#ff0000'
  ];

  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, 'https://postsyncer.com/api/v1/labels');
  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
  curl_setopt($ch, CURLOPT_HTTPHEADER, [
      'Authorization: Bearer YOUR_API_TOKEN',
      'Content-Type: application/json'
  ]);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

  $response = curl_exec($ch);
  $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  curl_close($ch);

  if ($httpCode === 201) {
      $label = json_decode($response, true);
      echo "Label created: " . $label['id'];
  } else {
      echo "Error: " . $response;
  }
  ?>
  ```

  ```python Python theme={null}
  import requests
  import json

  data = {
      'workspace_id': 1,
      'name': 'Product Launch',
      'color': '#ff0000'
  }

  headers = {
      'Authorization': 'Bearer YOUR_API_TOKEN',
      'Content-Type': 'application/json'
  }

  response = requests.post(
      'https://postsyncer.com/api/v1/labels',
      json=data,
      headers=headers
  )

  if response.status_code == 201:
      label = response.json()
      print(f"Label created: {label['id']}")
  else:
      print(f"Error: {response.status_code}")
      print(response.text)
  ```
</CodeGroup>

### Error Codes

<ResponseField name="400" type="Bad Request">
  Validation errors or invalid parameters
</ResponseField>

<ResponseField name="401" type="Unauthorized">
  Missing or invalid API token
</ResponseField>

<ResponseField name="403" type="Forbidden">
  Token does not have 'labels' permission
</ResponseField>

<ResponseField name="404" type="Not Found">
  Workspace not found or user does not have access to the workspace.
</ResponseField>

<ResponseField name="422" type="Unprocessable Entity">
  Validation errors in request data
</ResponseField>
