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

# Discard Changes

> Discard unpublished changes and revert to last published version

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

No request body required.

## Behavior

Discard resets a component to its last published version:

1. Only works for components with `draft` or `modified` status
2. Component must have been previously published (have a `lastPublishedVersion`)
3. All unpublished changes are permanently discarded
4. Status returns to `published`

<Warning>
  This action cannot be undone. All unpublished changes will be permanently lost.
</Warning>

## Response

Returns the Component object with `published` status.

```json theme={null}
{
  "data": {
    "id": "c123",
    "name": "ProductCard",
    "status": "published",
    "version": 2,
    "lastPublishedVersion": 2,
    "content": "// Content reset to match version 2",
    "compiled": "...",
    "schema": {...},
    "metadata": {
      "discardedAt": "2024-03-22T10:00:00Z",
      "discardedBy": "user123"
    },
    "createdAt": "2024-03-20T10:00:00Z",
    "updatedAt": "2024-03-22T10:00:00Z"
  },
  "message": "Component draft changes discarded successfully"
}
```

## Error Responses

### Invalid Status

Only `draft` or `modified` components can have changes discarded.

```json theme={null}
{
  "error": {
    "code": "INVALID_STATUS",
    "message": "Only draft or modified components can be discarded"
  }
}
```

### No Published Version

Draft components that have never been published cannot be discarded.

```json theme={null}
{
  "error": {
    "code": "NO_PUBLISHED_VERSION",
    "message": "Cannot discard a component that has never been published"
  }
}
```

## Code Examples

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

  ```javascript JavaScript theme={null}
  const response = await fetch(
    'https://api.metabind.ai/app/v1/organizations/org123/projects/proj456/components/c123/discard',
    {
      method: 'POST',
      headers: {
        'Authorization': 'Bearer YOUR_JWT'
      }
    }
  );

  const { data: component } = await response.json();
  ```
</CodeGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.