Skip to content
Docs

Overview

Instagram direct messages, profiles, followers, posts, comments and likes from your own connected Instagram accounts, on Unipile's v1 paths, fields and errors.

Early access. Tell us what you're building and we'll set you up. Contact us

Lempile's Instagram API works with your own Instagram accounts. Each account signs in once, then lives in its own browser, behind its own IP. A call does in that browser what the account's owner would do on instagram.com: read the inbox, send a message, read a profile, follow, like, comment or post.

Paths, fields, status codes and error types are Unipile's (v1). A client written for Unipile's Instagram routes changes two things: its base URL and its API key. Anything Lempile doesn't do answers Unipile's own 501 errors/feature_not_implemented, so such a client can tell. Route by route: Unipile Compatibility.

Instagram is in early access: connecting an account needs your workspace to be open for it. Write to support@lempile.com to join.

Before You Start#

  1. Connect an Instagram account: in the dashboard's Accounts page, through a hosted link, or with POST /accounts. The first sign-in from a new IP usually brings a code from Instagram (by email, SMS, WhatsApp or an authenticator app). See Accounts And Connecting.
  2. Create an API key in the dashboard: Access Tokens → Generate a token. Reads need accounts.read; writes need accounts.write.
  3. Send the key in the X-API-KEY header, to https://api.lempile.com/api/v1 (Unipile's own path). https://api.lempile.com/v1 and https://api.lempile.com reach the same routes.

Every route names the account with account_id: its Lempile id (a UUID), its Instagram user id (the number) or its username.

Your First Message#

List the account's chats, then answer one:

Shell
curl -sS "https://api.lempile.com/api/v1/chats?account_id=$ACCOUNT_ID&limit=5" \
  -H "X-API-KEY: $LEMPILE_API_KEY"
Shell
curl -sS -X POST "https://api.lempile.com/api/v1/chats/$CHAT_ID/messages" \
  -H "X-API-KEY: $LEMPILE_API_KEY" \
  -H "Idempotency-Key: answer-jane-1" \
  -H "Content-Type: application/json" \
  -d '{ "account_id": "'"$ACCOUNT_ID"'", "text": "Thanks, talk tomorrow." }'
JSON
{
  "object": "MessageSent",
  "message_id": "340282366841710301244276026398105347911_cAAAAB3xYz9wQkLmNo"
}

Add "dry_run": true to check a message without sending it (see Dry Runs).

IDs#

Thing Its id Also accepted
A person provider_id: Instagram's user id, a number ("48210937561"). public_identifier is the username. The username, @username or the profile link, wherever a person is named. A number works only for a person one of the account's reads has already shown (a profile, a comment, a like, a follower, a conversation); any other answers 400: pass the username.
A person, to message provider_messaging_id: Instagram's separate messaging id. Unipile's POST /chats asks for it in attendees_ids. provider_id, the username or the profile link.
A chat Instagram's own chat id: the number in instagram.com/direct/t/<id>/. That link.
A message <chat id>_<Instagram's message id>. provider_id is Instagram's message id alone.
An attachment <message provider_id>_<position>, from 0.
A post provider_id: Instagram's media id, a number. The shortcode, or the post or reel link, on every route that takes a post.
A follow The person's provider_id (Unipile calls it an invitation).

A message id carries its chat, so GET /messages/{message_id} and its attachments and reactions need nothing else.

How Writes Behave#

  • A key per write. Messages, new chats, comments, posts, follows and unfollows need an Idempotency-Key header. Likes, message reactions, answers to follow requests and profile edits take one too; sent without one, Lempile makes one and gives it back in the answer's Idempotency-Key header. The same key with the same request answers the first answer again, with Idempotent-Replayed: true, so a retry never writes twice. See Errors And Limits.
  • Not sure means not sure. When Instagram doesn't confirm in time, a write answers 504 errors/request_timeout, and it may or may not be on Instagram. Read GET /writes/{key} before sending it again.
  • A 4xx means nothing was done on Instagram. A 5xx after the send means not sure.
  • A human pace. Each account has its own limits per kind of write, 10 writes an hour in all, and a warm-up after it signs in (below).

Pace#

Every account is paced on its own. Two API keys using one account share its pace.

Write Per account
Start a chat (POST /chats) 20 a day, 3 minutes apart
Send in a chat (POST /chats/{chat_id}/messages) 80 a day, 20 seconds apart
Follow, unfollow 20 a day, 2 minutes apart
Comment 20 a day, 2 minutes apart
Like a post or comment 60 a day, 30 seconds apart
React to a message 60 a day
Create a post 3 a day
All writes together 10 an hour, 100 a day

A newly connected account starts lower: no new chats, follows, comments or posts for 72 hours after its first sign-in, then limits that grow over four weeks (Warm-up).

Reads have no Lempile limit, but each one opens Instagram in the account's browser: read at a human rate. "A day" is the last 24 hours.

A write past a limit answers 429 errors/too_many_requests with retry_after (seconds to wait) and retry_at (when). Nothing was sent, and it doesn't count. Dry runs aren't paced.

When Instagram itself says "Try again later", that call answers 429 errors/too_many_requests with retry_after: 86400: wait a day before writing from the account again. When it says "We restrict certain activity", the call answers 403 errors/account_restricted.

Dry Runs#

Every write takes "dry_run": true in its body (or ?dry_run=true in the address, handy on a DELETE). Lempile checks every field, opens the account's page up to the last step, checks that Instagram would let the account do it, and stops there. The answer is 200 with not_sent: true, and checks, the list of what was checked:

JSON
{ "object": "MessageDryRun", "not_sent": true, "checks": [] }

A dry run of something already so (a post already liked, a person already followed, the same bio, a message already reacted to) also answers 200 with not_sent: true, and its checks hold { "check": "already", "already": true, "ok": true }.

A dry run needs no Idempotency-Key, keeps no receipt and counts toward no pace. A message's dry run never types anything: on Instagram, typing in a chat shows the other person "typing…" as it happens. A comment's dry run types and clears the comment box, because Instagram shows nothing while someone types a comment.

What Instagram's Own Rules Mean#

  • Message requests. A message to someone who doesn't follow the account lands in their requests, not their inbox. Until they accept, Instagram allows one message, text only: a second answers 422 errors/cant_send_message. Requests the account receives are chats with folder: ["PENDING"].
  • Some people can't be messaged. Their settings, or a block, stop the account: 422 errors/user_unreachable. Nobody by that name: 422 errors/invalid_recipient.
  • "Seen". Reading a conversation's messages opens it, and Instagram then normally shows the other person "Seen", exactly as when the owner opens it. Lempile avoids that where Instagram's own page allows; an answer that did open a conversation says marks_seen: true. Listing chats never opens one.
  • One reaction per message. A new reaction replaces the account's last one.
  • Private accounts. Following one sends a follow request; it shows as has_sent_invitation: true until they accept.
  • A blocked or signed-out account. When Instagram signs the account out, it answers 401 errors/disconnected_account until it signs in again. When Instagram blocks an action or asks for a check, it answers 403 errors/account_restricted: someone has to look at the account on Instagram.

What's Here#

Page Routes
Accounts And Connecting GET /accounts, POST /accounts, checkpoints, hosted links, reconnect, statuses
Chats And Messages chats, messages, attachments, reactions, attendees, sending, starting a chat
Users profiles, followers, following, follow and unfollow, follow requests, profile edit
Posts a post, a person's posts, comments, likes, creating a post
Webhooks messaging events, account_status events (signed out, security check, suspended)
Errors And Limits every error, the pace, write receipts
Unipile Compatibility every Unipile v1 Instagram route, and what Lempile does with it

Was this page helpful?