Skip to main content
Glama

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
NameRequiredDescriptionDefault
image_urlNoURL of the image to publish (must be publicly accessible)
video_urlNoURL of the video to publish (must be publicly accessible)
captionNoCaption for the post (optional)
location_idNoFacebook location ID for geotagging (optional)

Implementation Reference

  • 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"] }],
      },
    },

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/mcpware/instagram-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server