publish_media
Upload and publish images or videos to Instagram with captions and optional location tagging for content sharing.
Instructions
Upload and publish an image or video to Instagram with caption and optional location
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| image_url | No | URL of the image to publish (must be publicly accessible) | |
| video_url | No | URL of the video to publish (must be publicly accessible) | |
| caption | No | Caption for the post (optional) | |
| location_id | No | Facebook location ID for geotagging (optional) |
Implementation Reference
- src/client.ts:285-304 (handler)The implementation of `publishMedia` in the `InstagramClient` class, which handles creating the media container and then publishing it.
async publishMedia(opts: { imageUrl?: string; videoUrl?: string; caption?: string; locationId?: string; }): Promise<IGPublishResult> { const id = this.aid(); const body: Record<string, any> = {}; if (opts.caption) body.caption = opts.caption; if (opts.imageUrl) body.image_url = opts.imageUrl; else if (opts.videoUrl) body.video_url = opts.videoUrl; else throw new InstagramAPIError("Either imageUrl or videoUrl is required"); if (opts.locationId) body.location_id = opts.locationId; const container = await this.request("POST", `${id}/media`, { body }); const result = await this.request("POST", `${id}/media_publish`, { body: { creation_id: container.id }, }); return { id: result.id }; } - src/index.ts:99-113 (registration)The definition and schema registration for the `publish_media` tool.
{ name: "publish_media", description: "Upload and publish an image or video to Instagram with caption and optional location", inputSchema: { type: "object" as const, properties: { image_url: { type: "string", format: "uri", description: "URL of the image to publish (must be publicly accessible)" }, video_url: { type: "string", format: "uri", description: "URL of the video to publish (must be publicly accessible)" }, caption: { type: "string", description: "Caption for the post (optional)" }, location_id: { type: "string", description: "Facebook location ID for geotagging (optional)" }, }, anyOf: [{ required: ["image_url"] }, { required: ["video_url"] }], }, },