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

# Create Content from Template

> Create new content based on an existing template

Creates a new content item using an existing template as a starting point. The new content inherits the template's structure, ContentType, and package version.

## Path Parameters

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

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

## Request Body

<ParamField body="templateId" type="string" required>
  ID of the template content to use
</ParamField>

<ParamField body="name" type="string" required>
  Display name for the new content
</ParamField>

<ParamField body="description" type="string">
  Description for the new content (overrides template description)
</ParamField>

<ParamField body="content" type="object">
  Content data that overrides template values. Merged with template content.
</ParamField>

<ParamField body="tags" type="string[]">
  Tags for the new content (replaces template tags if provided)
</ParamField>

<ParamField body="folderId" type="string">
  Folder ID for organization
</ParamField>

### Example Request

```json theme={null}
{
  "templateId": "cont123",
  "name": "My New Article",
  "description": "Custom Article. A personalized article based on the template.",
  "content": {
    "title": "Custom Title",
    "subtitle": "My custom subtitle",
    "author": "John Smith",
    "components": [
      {
        "type": "ArticleParagraph",
        "text": "This is my custom opening paragraph..."
      }
    ]
  }
}
```

## Response

Returns the created Content object.

```json theme={null}
{
  "id": "cont126",
  "typeId": "ct123",
  "typeVersion": 1,
  "version": null,
  "lastPublishedVersion": null,
  "packageVersion": "1.0.0",
  "name": "My New Article",
  "description": "Custom Article. A personalized article based on the template.",
  "status": "draft",
  "isTemplate": false,
  "content": {
    "title": "Custom Title",
    "subtitle": "My custom subtitle",
    "heroImage": "asset123",
    "author": "John Smith",
    "publishDate": "2024-03-21",
    "components": [
      {
        "type": "ArticleParagraph",
        "text": "This is my custom opening paragraph..."
      }
    ]
  },
  "compiled": "const body = () => { ... }",
  "tags": ["Template", "Article"],
  "metadata": {
    "author": "user123",
    "locale": "en-US"
  },
  "createdAt": "2024-03-22T10:00:00Z",
  "updatedAt": "2024-03-22T10:00:00Z"
}
```

<Note>
  Content created from a template inherits the template's `typeId`, `typeVersion`, and `packageVersion`. The provided `content` object is merged with the template's content, allowing you to override specific fields.
</Note>

## Error Responses

### Template Not Found

```json theme={null}
{
  "error": {
    "code": "TEMPLATE_NOT_FOUND",
    "message": "Template content not found",
    "details": {
      "templateId": "cont123"
    }
  }
}
```

### Not a Template

```json theme={null}
{
  "error": {
    "code": "NOT_A_TEMPLATE",
    "message": "Content is not marked as a template",
    "details": {
      "contentId": "cont123"
    }
  }
}
```

### Validation Failed

```json theme={null}
{
  "error": {
    "code": "VALIDATION_FAILED",
    "message": "Merged content does not match schema",
    "details": {
      "errors": [...]
    }
  }
}
```

## Code Examples

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST "https://api.metabind.ai/app/v1/organizations/org123/projects/proj456/content/from-template" \
    -H "Authorization: Bearer YOUR_JWT" \
    -H "Content-Type: application/json" \
    -d '{
      "templateId": "cont123",
      "name": "My New Article",
      "content": {
        "title": "Custom Title",
        "author": "John Smith"
      }
    }'
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch(
    'https://api.metabind.ai/app/v1/organizations/org123/projects/proj456/content/from-template',
    {
      method: 'POST',
      headers: {
        'Authorization': 'Bearer YOUR_JWT',
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({
        templateId: 'cont123',
        name: 'My New Article',
        content: {
          title: 'Custom Title',
          author: 'John Smith'
        }
      })
    }
  );

  const content = await response.json();
  console.log(`Created content from template: ${content.id}`);
  ```
</CodeGroup>
