publish_entry
Publishes content entries to specified environments and locales in Contentstack, ensuring accurate content distribution across platforms and regions.
Instructions
Publishes an entry to a specified environment and locale.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| content_type_uid | Yes | Content type UID | |
| entry_uid | Yes | Entry UID to publish | |
| environment | Yes | Environment to publish to | |
| locale | No | Locale code (defaults to en-us) | en-us |
Implementation Reference
- src/index.ts:1083-1129 (handler)The handler function for the 'publish_entry' tool. It fetches the current entry to get its version, prepares a publish payload with the specified environment and locale, and sends a POST request to the Contentstack API's publish endpoint.async ({ content_type_uid, entry_uid, environment, locale }) => { try { // First get the entry to find its current version const entryResponse = await axios.get<EntryResponse>( `${API_BASE_URL}/content_types/${content_type_uid}/entries/${entry_uid}`, { headers: getHeaders(), }, ) const version = entryResponse.data.entry._version // Prepare publish payload const payload = { entry: { environments: [environment], locales: [locale], }, } // Publish the entry const response = await axios.post( `${API_BASE_URL}/content_types/${content_type_uid}/entries/${entry_uid}/publish`, payload, { headers: getHeaders() }, ) return { content: [ { type: 'text', text: `Entry "${entry_uid}" published successfully to environment "${environment}" in locale "${locale}".`, }, ], } } catch (error) { return { content: [ { type: 'text', text: handleError(error as ApiError), }, ], isError: true, } } },
- src/index.ts:1077-1082 (schema)Zod schema defining the input parameters for the 'publish_entry' tool: content_type_uid, entry_uid, environment, and locale (with default 'en-us').{ content_type_uid: z.string().describe('Content type UID'), entry_uid: z.string().describe('Entry UID to publish'), environment: z.string().describe('Environment to publish to'), locale: z.string().default('en-us').describe('Locale code (defaults to en-us)'), },
- src/index.ts:1075-1130 (registration)Registration of the 'publish_entry' tool using server.tool(), including name, description, input schema, and handler function.'publish_entry', 'Publishes an entry to a specified environment and locale.', { content_type_uid: z.string().describe('Content type UID'), entry_uid: z.string().describe('Entry UID to publish'), environment: z.string().describe('Environment to publish to'), locale: z.string().default('en-us').describe('Locale code (defaults to en-us)'), }, async ({ content_type_uid, entry_uid, environment, locale }) => { try { // First get the entry to find its current version const entryResponse = await axios.get<EntryResponse>( `${API_BASE_URL}/content_types/${content_type_uid}/entries/${entry_uid}`, { headers: getHeaders(), }, ) const version = entryResponse.data.entry._version // Prepare publish payload const payload = { entry: { environments: [environment], locales: [locale], }, } // Publish the entry const response = await axios.post( `${API_BASE_URL}/content_types/${content_type_uid}/entries/${entry_uid}/publish`, payload, { headers: getHeaders() }, ) return { content: [ { type: 'text', text: `Entry "${entry_uid}" published successfully to environment "${environment}" in locale "${locale}".`, }, ], } } catch (error) { return { content: [ { type: 'text', text: handleError(error as ApiError), }, ], isError: true, } } }, )