Facebook Pages

Learn how to answer conversations and publish as a Facebook Page with Unipile API.

A Facebook account can administer Pages. There is no separate account to link for a Page: once it is activated on the Facebook account, you can use the same account_id to:

  • Read and answer the Page's inbox.
  • Publish posts, comments, and reactions as the Page.
  • Receive the realtime events of the Page's inbox.

Activate Pages

Pages are activated when the account is linked or reconnected, through the page product. By default, every Page the account administers is activated. See Link accounts to restrict them or to let the user choose.

Calling a Page that is not activated on the account returns 403 api/insufficient_permissions.


Find the Page IDs

To list the activated Pages, use List all Inboxes. Each one appears as an inbox with the ID PAGE_<page_id>_INBOX, next to the inboxes of the personal account.

const { data } = await messagingApi.getInboxesList({
  path: {
    account_id: "acc_123456789",
  },
});
inboxes = messaging_api.get_inboxes_list("acc_123456789")
curl --request GET \
     --url https://api.unipile.com/v2/acc_123456789/inboxes \
     --header 'X-API-KEY: api-key' \
     --header 'accept: application/json'
{
  "data": [
    { "object": "Inbox", "id": "INBOX", "description": "Primary inbox", "disabled": false },
    { "object": "Inbox", "id": "PAGE_1357020157484056_INBOX", "description": "Acme Page inbox", "disabled": false }
  ]
}

Here, the Page ID is 1357020157484056.

Page ID and profile ID

A Page on Facebook's new Pages experience has two IDs: its Page ID, and the ID of the profile it publishes under (for instance, 61594095837269 for the Page 1357020157484056).

WhereExpected ID
PAGE_<page_id>_INBOX, Page-scoped chat IDs, page_ids, page_<page_id> productsPage ID
post_as, comment_as, react_as, user_id of List all User's PostsPage ID or profile ID
Author of a post or comment written by the Page, and the start of its post IDReturned as the profile ID
🚧

Recognizing what a Page wrote

The author of a Page's post can have a different ID than the Page, so don't compare it with the Page ID. Authors that are Pages are reported with the organization type.


Answer the Page's inbox

List the Page's chats

List all Chats only returns the chats of the personal account. To get those of a Page, use List inbox Chats with the Page's inbox ID.

const { data } = await messagingApi.getInboxChatsList({
  path: {
    account_id: "acc_123456789",
    inbox_id: "PAGE_1357020157484056_INBOX",
  },
});
chats = messaging_api.get_inbox_chats_list(
    "PAGE_1357020157484056_INBOX",
    "acc_123456789",
)
curl --request GET \
     --url https://api.unipile.com/v2/acc_123456789/inboxes/PAGE_1357020157484056_INBOX/chats \
     --header 'X-API-KEY: api-key' \
     --header 'accept: application/json'

Every chat of a Page has an ID of the form PAGE_<page_id>_<thread_key>. The prefix tells Unipile to act as the Page, so a chat of the Page can't be mistaken for the personal chat of the account with the same person.

Reply as the Page

Use the Page-scoped chat ID with the usual messaging methods. For instance, Send a Message replies as the Page:

const { data } = await messagingApi.sendMessage({
  path: {
    account_id: "acc_123456789",
    chat_id: "PAGE_1357020157484056_100001234567890",
  },
  body: {
    text: "Thanks for contacting us!",
  },
});
message = messaging_api.send_message(
    "PAGE_1357020157484056_100001234567890",
    "acc_123456789",
    {"text": "Thanks for contacting us!"},
)
curl --request POST \
     --url https://api.unipile.com/v2/acc_123456789/chats/PAGE_1357020157484056_100001234567890/messages/send \
     --header 'X-API-KEY: api-key' \
     --header 'accept: application/json' \
     --header 'content-type: application/json' \
     --data '
{
  "text": "Thanks for contacting us!"
}
'
📘

Page inbox limitations

  • A Page answers the people who wrote to it: it can't start a conversation. Start a Chat from an Inbox returns 501 api/not_implemented with a Page inbox.
  • A Page can't delete its messages. Delete a Message returns 501 api/not_implemented.

Be notified about the Page's messages

Webhook events of a Page carry the Page-scoped chat_id, so you can route them with the PAGE_<page_id>_ prefix. See Configure a webhook.


Publish as a Page

The Posts API acts as the personal account by default. To act as a Page, set one of these fields to the Page ID:

const { data } = await postsApi.createPost({
  path: {
    account_id: "acc_123456789",
  },
  body: {
    text: "Hello from our Page!",
    post_as: "1357020157484056",
  },
});
post = posts_api.create_post(
    "acc_123456789",
    {
        "text": "Hello from our Page!",
        "post_as": "1357020157484056",
    },
)
curl --request POST \
     --url https://api.unipile.com/v2/acc_123456789/posts \
     --header 'X-API-KEY: api-key' \
     --header 'accept: application/json' \
     --header 'content-type: application/json' \
     --data '
{
  "text": "Hello from our Page!",
  "post_as": "1357020157484056"
}
'

These fields accept the account itself (me) or one of its activated Pages. Anything else returns a 403 error.

Unipile finds the right identity on its own when editing or deleting:

  • A post or comment written by a Page is edited or deleted by that Page.
  • A Page can delete what others wrote under its own posts.

To read the Page's content, use its Page ID as user_id in List all User's Posts, List all User's Comments, or List all User's Reactions.


Monitor the connection of a Page

Each activated Page has its own connection, with its own status in the metadata.products_connection_status field of the account, under the key page_<page_id>. A Page that goes down does not affect the personal inbox or the other Pages. The account's overall status becomes partial or degraded meanwhile.

{
  "status": "partial",
  "metadata": {
    "products_connection_status": {
      "messaging": "running",
      "page_1357020157484056": "disconnected"
    }
  }
}

If the account no longer administers a Page, because it was deleted or the admin rights were revoked, its product becomes disconnected until the account is reconnected. See Status & Lifecycle and Reconnect an account.


What’s Next

Continue with Facebook messaging and posts.

Did this page help you?