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

# Update Component Status

> Update the status of a component

## Path Parameters

<ParamField path="organizationId" type="string" required>
  Organization ID
</ParamField>

<ParamField path="projectId" type="string" required>
  Project ID
</ParamField>

<ParamField path="id" type="string" required>
  Component ID
</ParamField>

## Request Body

<ParamField body="status" type="string" required>
  New status: `draft`, `modified`, `published`, or `deleted`
</ParamField>

```json theme={null}
{
  "status": "deleted"
}
```

<Warning>
  Components cannot be manually set to `published` status. Components are published automatically when included in a package. To publish a component, create a new package.
</Warning>

## Status Transitions

| From        | To          | Allowed                                |
| ----------- | ----------- | -------------------------------------- |
| `draft`     | `deleted`   | Yes                                    |
| `modified`  | `deleted`   | Yes                                    |
| `published` | `deleted`   | Yes                                    |
| `deleted`   | `draft`     | Yes (restore)                          |
| `deleted`   | `modified`  | Yes (restore, if previously published) |
| Any         | `published` | No (use package creation)              |

## Response

Returns the updated Component object.

```json theme={null}
{
  "id": "c123",
  "name": "ProductCard",
  "status": "deleted",
  "version": 3,
  "lastPublishedVersion": 3,
  "content": "...",
  "metadata": {
    "deletedAt": "2024-03-22T10:00:00Z",
    "deletedBy": "user123"
  },
  "createdAt": "2024-03-20T10:00:00Z",
  "updatedAt": "2024-03-22T10:00:00Z"
}
```

## Use Cases

### Soft Delete a Component

Set status to `deleted` to prevent future use while maintaining existing package references:

```json theme={null}
{
  "status": "deleted"
}
```

### Restore a Deleted Component

Set status back to `draft` or `modified` to restore a deleted component:

```json theme={null}
{
  "status": "draft"
}
```

## Error Responses

### Invalid Status Transition

```json theme={null}
{
  "error": {
    "code": "BAD_REQUEST",
    "message": "Validation failed",
    "details": {
      "status": "Use publish() method to publish component"
    }
  }
}
```

### Cannot Restore Deleted Component

```json theme={null}
{
  "error": {
    "code": "BAD_REQUEST",
    "message": "Validation failed",
    "details": {
      "status": "Deleted components can only be restored to draft status"
    }
  }
}
```

## Code Examples

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST "https://api.metabind.ai/app/v1/organizations/org123/projects/proj456/components/c123/status" \
    -H "Authorization: Bearer YOUR_JWT" \
    -H "Content-Type: application/json" \
    -d '{"status": "deleted"}'
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch(
    'https://api.metabind.ai/app/v1/organizations/org123/projects/proj456/components/c123/status',
    {
      method: 'POST',
      headers: {
        'Authorization': 'Bearer YOUR_JWT',
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({ status: 'deleted' })
    }
  );

  const component = await response.json();
  ```
</CodeGroup>
