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

# Migrate Content

> Migrate content to a new ContentType version

Updates content to use a newer ContentType version, updating the derived `packageVersion` and validating against the new schema.

## 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>
  Content ID
</ParamField>

## Request Body

<ParamField body="targetTypeVersion" type="number" required>
  The ContentType version to migrate to
</ParamField>

### Example Request

```json theme={null}
{
  "targetTypeVersion": 3
}
```

## Response

Returns the updated Content object with the new `typeVersion` and derived `packageVersion`.

```json theme={null}
{
  "id": "cont123",
  "typeId": "ct123",
  "typeVersion": 3,
  "version": 2,
  "lastPublishedVersion": 2,
  "packageVersion": "2.0.0",
  "name": "Getting Started Guide",
  "status": "modified",
  "isTemplate": false,
  "content": { ... },
  "compiled": "const body = () => { ... }",
  "tags": ["Tutorial"],
  "metadata": { ... },
  "createdAt": "2024-03-20T10:00:00Z",
  "updatedAt": "2024-03-23T10:00:00Z"
}
```

<Warning>
  Migration changes the `typeVersion` and `packageVersion`. The content's status changes to `modified` and must be published to make the migration live. Ensure the content is compatible with the new schema before publishing.
</Warning>

## Error Responses

### ContentType Version Not Found

```json theme={null}
{
  "error": {
    "code": "TYPE_VERSION_NOT_FOUND",
    "message": "ContentType version 3 not found"
  }
}
```

### Validation Failed

If the content doesn't match the new schema:

```json theme={null}
{
  "error": {
    "code": "VALIDATION_FAILED",
    "message": "Content does not match target ContentType schema",
    "details": {
      "errors": [
        {
          "path": "/content/components/0/type",
          "message": "Component type 'OldComponent' not allowed in version 3"
        }
      ]
    }
  }
}
```

### Cannot Downgrade

```json theme={null}
{
  "error": {
    "code": "INVALID_MIGRATION",
    "message": "Cannot migrate to an older ContentType version",
    "details": {
      "currentVersion": 3,
      "targetVersion": 2
    }
  }
}
```

## Code Examples

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

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

  const content = await response.json();
  console.log(`Migrated to type version ${content.typeVersion}, package ${content.packageVersion}`);
  ```
</CodeGroup>
