Create posts

Learn how to publish Instagram posts with Unipile API.

Publish a post

To publish a post on Instagram, use the Create a Post endpoint.

Instagram publishing usually relies on media attachments, with the text field used as the caption.

const pictureFile = await readFile("picture.jpg");

const { data } = await postsApi.createPost({
  path: {
    account_id: "acc_123456789",
  },
  body: {
    text: "Hello from Instagram with Unipile!",
    attachments: [
      {
        content: pictureFile.toString("base64"),
        content_type: "image/jpeg",
        filename: "picture.jpg",
      },
    ],
    specifics: {
      instagram: {},
    },
  },
});
import base64

with open("picture.jpg", "rb") as f:
    picture_file = base64.b64encode(f.read()).decode("utf-8")

post = posts_api.create_post(
    "acc_123456789",
    {
        "text": "Hello from Instagram with Unipile!",
        "attachments": [
            {
                "content": picture_file,
                "content_type": "image/jpeg",
                "filename": "picture.jpg",
            },
        ],
        "specifics": {
            "instagram": {},
        },
    },
)
curl --request POST \
     --url https://api.unipile.com/v2/account_id/posts \
     --header 'accept: application/json' \
     --header 'content-type: application/json' \
     --data '
{
  "text": "Hello from Instagram with Unipile!",
  "attachments": [
    {
      "content": "base64",
      "content_type": "image/jpeg",
      "filename": "picture.jpg"
    }
  ],
  "specifics": {
    "instagram": {}
  }
}
'

Tag a location

Instagram posts can include a tagged location. To do so, pass the location in specifics.instagram.location.

Use the Instagram-specific Search locations method to retrieve the location ID you want to attach to the post.

const { data } = await postsApi.createPost({
  path: {
    account_id: "acc_123456789",
  },
  body: {
    text: "Posting from Paris",
    attachments: [
      {
        content: pictureFile.toString("base64"),
        content_type: "image/jpeg",
        filename: "picture.jpg",
      },
    ],
    specifics: {
      instagram: {
        location: {
          id: "123456789012345",
        },
      },
    },
  },
});
post = posts_api.create_post(
    "acc_123456789",
    {
        "text": "Posting from Paris",
        "attachments": [
            {
                "content": picture_file,
                "content_type": "image/jpeg",
                "filename": "picture.jpg",
            },
        ],
        "specifics": {
            "instagram": {
                "location": {
                    "id": "123456789012345",
                },
            },
        },
    },
)