createContent
The createContent function creates a new content entry of a given model. It is the JavaScript/TypeScript counterpart of the POST /content REST endpoint.
Example:
// Using the previously created clientconst { id } = await client.createContent({ contentType: 'post', name: 'My first post', content: [ { language: 'en', fields: [ { name: 'title', value: 'Hello world' }, { name: 'body', value: 'This was created via the API client.' }, ], }, ],});console.log(id);Interface
export interface ApiClient { createContent: (params: CreateContentParams) => Promise<CreateContentResponse>; // ... other methods}
export interface CreateContentParams { contentType: string; name: string; content?: Array<{ language?: LanguageCode; fields: Array<{ name: string; value: any; }>; }>;}
export interface CreateContentResponse { id: string;}Parameters
The function accepts a single CreateContentParams object.
| Name | Description |
|---|---|
contentType | The name of the model the new content belongs to. Must match an existing model in your project (e.g. 'post'). |
name | Human-readable name of the new content entry. This is the name shown in the dashboard’s Content tab. |
content | Optional. Array of language entries. Each entry contains the fields to populate for that language. If language is omitted on an entry, the project’s default language is used. |
Output
The function returns a Promise<CreateContentResponse> resolving to an object with the id of the new content:
const response = await client.createContent({ contentType: 'post', name: 'My first post',});// response.id → '660f5b8a3a1c2d4e7f8b9012'Use that id afterwards to update individual field values with updateContentFieldValue or to publish the entry with publishContent.