> ## 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.

# Update Label

> Update an existing label with new information

## Update Label

Updates an existing label with new name or color information.

### Request

<ParamField path="id" type="integer" required>
  The ID of the label to update
</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}
  {
    "name": "Updated Product Launch",
    "color": "#00ff00"
  }
  ```
</RequestExample>

### Response

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

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

<ResponseField name="color" type="string">
  The updated 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": "Updated Product Launch",
    "color": "#00ff00"
    "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 PUT "https://postsyncer.com/api/v1/labels/123" \
    -H "Authorization: Bearer YOUR_API_TOKEN" \
    -H "Content-Type: application/json" \
    -d '{
      "name": "Updated Product Launch",
      "color": "#00ff00"
    }'
  ```

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

  const updateLabel = async (labelId) => {
    try {
      const response = await axios.put(`https://postsyncer.com/api/v1/labels/${labelId}`, {
        name: 'Updated Product Launch',
        color: '#00ff00'
      }, {
        headers: {
          'Authorization': 'Bearer YOUR_API_TOKEN',
          'Content-Type': 'application/json'
        }
      });
      
      console.log('Label updated:', response.data);
    } catch (error) {
      console.error('Error updating label:', error.response?.data || error.message);
    }
  };

  updateLabel(123);
  ```

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

  $labelId = 123;
  $data = [
      'name' => 'Updated Product Launch',
      'color' => '#00ff00'
  ];

  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, "https://postsyncer.com/api/v1/labels/{$labelId}");
  curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
  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 === 200) {
      $label = json_decode($response, true);
      echo "Label updated: " . $label['id'];
  } else {
      echo "Error: " . $response;
  }
  ?>
  ```

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

  label_id = 123
  data = {
      'name': 'Updated Product Launch',
      'color': '#00ff00'
  }

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

  response = requests.put(
      f'https://postsyncer.com/api/v1/labels/{label_id}',
      json=data,
      headers=headers
  )

  if response.status_code == 200:
      label = response.json()
      print(f"Label updated: {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">
  Label not found or user does not have access to the label's workspace
</ResponseField>

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