create_publishing_post
Schedule a future social media post with text and optional media to one or more profiles, adding it to Sprout Social's publishing calendar.
Instructions
Create a new publishing post in Sprout Social to be published at a future time. The post will appear in Sprout's publishing calendar.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| profile_ids | Yes | Array of customer_profile_id values the post will be published to. | |
| text | Yes | The text content of the post. | |
| scheduled_time | Yes | ISO 8601 datetime when the post should be published (e.g. '2026-06-30T18:00:00Z'). | |
| media_ids | No | Array of media IDs (from upload_media) to attach to the post. | |
| is_draft | No | If true, creates the post as a draft (default: false). | |
| tags | No | Array of tag IDs to apply to the post. |
Implementation Reference
- src/index.ts:404-457 (registration)The server.tool() call that registers the 'create_publishing_post' tool with its name, description, schema, and handler callback.
server.tool( "create_publishing_post", "Create a new publishing post in Sprout Social to be published at a future time. " + "The post will appear in Sprout's publishing calendar.", { profile_ids: z .array(z.string()) .describe( "Array of customer_profile_id values the post will be published to." ), text: z.string().describe("The text content of the post."), scheduled_time: z .string() .describe( "ISO 8601 datetime when the post should be published (e.g. '2026-06-30T18:00:00Z')." ), media_ids: z .array(z.string()) .optional() .describe( "Array of media IDs (from upload_media) to attach to the post." ), is_draft: z .boolean() .optional() .describe("If true, creates the post as a draft (default: false)."), tags: z .array(z.string()) .optional() .describe("Array of tag IDs to apply to the post."), }, async ({ profile_ids, text, scheduled_time, media_ids, is_draft, tags }) => { const entries = profile_ids.map((profileId) => { const entry: Record<string, unknown> = { customer_profile_id: profileId, text, scheduled_time, is_draft: is_draft ?? false, }; if (media_ids && media_ids.length > 0) { entry.media = media_ids.map((id) => ({ id })); } if (tags && tags.length > 0) { entry.tags = tags; } return entry; }); const data = await sproutRequest("POST", "/publishing/posts", { entries, }); return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] }; } ); - src/index.ts:435-456 (handler)The handler function that executes the tool logic: maps profile_ids to entries, optionally attaches media and tags, then POSTs to /publishing/posts via sproutRequest.
async ({ profile_ids, text, scheduled_time, media_ids, is_draft, tags }) => { const entries = profile_ids.map((profileId) => { const entry: Record<string, unknown> = { customer_profile_id: profileId, text, scheduled_time, is_draft: is_draft ?? false, }; if (media_ids && media_ids.length > 0) { entry.media = media_ids.map((id) => ({ id })); } if (tags && tags.length > 0) { entry.tags = tags; } return entry; }); const data = await sproutRequest("POST", "/publishing/posts", { entries, }); return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] }; } - src/index.ts:408-434 (schema)Zod schema defining the input parameters: profile_ids (required array of strings), text, scheduled_time, plus optional media_ids, is_draft, tags.
{ profile_ids: z .array(z.string()) .describe( "Array of customer_profile_id values the post will be published to." ), text: z.string().describe("The text content of the post."), scheduled_time: z .string() .describe( "ISO 8601 datetime when the post should be published (e.g. '2026-06-30T18:00:00Z')." ), media_ids: z .array(z.string()) .optional() .describe( "Array of media IDs (from upload_media) to attach to the post." ), is_draft: z .boolean() .optional() .describe("If true, creates the post as a draft (default: false)."), tags: z .array(z.string()) .optional() .describe("Array of tag IDs to apply to the post."), }, - src/index.ts:29-59 (helper)The sproutRequest helper function used by the handler to make authenticated HTTP requests to the Sprout Social API.
async function sproutRequest( method: "GET" | "POST", path: string, body?: Record<string, unknown> ): Promise<unknown> { const { apiKey, customerId } = getConfig(); const url = `${SPROUT_API_BASE}/v1/${customerId}${path}`; const headers: Record<string, string> = { Authorization: `Bearer ${apiKey}`, Accept: "application/json", }; const options: RequestInit = { method, headers }; if (body) { headers["Content-Type"] = "application/json"; options.body = JSON.stringify(body); } const response = await fetch(url, options); if (!response.ok) { const errorText = await response.text(); throw new Error( `Sprout Social API error (${response.status}): ${errorText}` ); } return response.json(); } - src/index.ts:9-27 (helper)The getConfig helper used to retrieve API key and customer ID from environment variables.
function getConfig() { const apiKey = process.env.SPROUT_SOCIAL_API_KEY; if (!apiKey) { throw new Error( "SPROUT_SOCIAL_API_KEY environment variable is required. " + "Set it to your Sprout Social API token." ); } const customerId = process.env.SPROUT_SOCIAL_CUSTOMER_ID; if (!customerId) { throw new Error( "SPROUT_SOCIAL_CUSTOMER_ID environment variable is required. " + "Set it to your Sprout Social customer ID." ); } return { apiKey, customerId }; }