Send a Messenger message
const url = 'https://api.siprtc.io/v1/Accounts/example/Integrations/Meta/Messenger/Messages';const options = { method: 'POST', headers: {Authorization: 'Basic <credentials>', 'Content-Type': 'application/json'}, body: '{"message":"Hello from Acme support","pageAccessToken":"","pageId":"100000000000001","recipientId":"7000000000000001"}'};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}curl --request POST \ --url https://api.siprtc.io/v1/Accounts/example/Integrations/Meta/Messenger/Messages \ --header 'Authorization: Basic <credentials>' \ --header 'Content-Type: application/json' \ --data '{ "message": "Hello from Acme support", "pageAccessToken": "", "pageId": "100000000000001", "recipientId": "7000000000000001" }'Sends a text message from a connected Facebook page to a person through the Messenger Send API. The page’s stored token is used: the page is looked up in this account’s integration, then in its parent account’s. pageAccessToken, when sent, is used instead of any stored token. If Facebook reports the token expired, the login’s token is refreshed once and the send retried. Facebook’s answer is returned as is: on success its recipient_id and message_id; on a Facebook error, Facebook’s HTTP status and error body. Messenger’s own rules apply (for example the 24-hour standard messaging window). Authentication: HTTP Basic with the account’s Auth ID and Auth Secret. The operation always applies to the authenticated account; {auth_id} should be its Auth ID (with a parent account’s credentials on a sub-account’s path, the parent’s own integration is used, not the sub-account’s).
Authorizations
Section titled “ Authorizations ”Parameters
Section titled “ Parameters ”Path Parameters
Section titled “ Path Parameters ”Auth ID of the authenticated account
Request Bodyrequired
Section titled “ Request Bodyrequired ”Page, recipient and text
object
Message is the text to send. Required.
Example
Hello from Acme supportPageAccessToken is a page access token to send with instead of a stored one; it takes precedence over pageId. Optional.
Example
PageID is the connected Facebook page to send from; its stored page token is used. Required unless pageAccessToken is sent.
Example
100000000000001RecipientID is the person’s page-scoped id (PSID) on that page. Required.
Example
7000000000000001Responses
Section titled “ Responses ”OK
object
MessageID is Facebook’s id of the sent message.
RecipientID is the recipient’s page-scoped id.
Example
{ "message_id": "m_fake-message-id", "recipient_id": "7000000000000001"}Invalid body, recipientId or message missing (message only, no status), neither pageId nor pageAccessToken, no stored token for the page, or a network error reaching Facebook
object
Message says what went wrong.
Status is always “failed” on an error (some validation errors omit it).
Example
{ "message": "error message", "status": "failed"}Missing or invalid credentials; the body is the JSON string Authentication failed
Example generated
exampledefault
Section titled “ default ”Facebook refused the send: Facebook’s status and error body, passed through
object
Error is Facebook’s error object.
object
Code is Facebook’s error code.
ErrorSubcode is Facebook’s error subcode, when given.
FbtraceID is Facebook’s trace id for support.
Message is Facebook’s description of the error.
Type is Facebook’s error type.
Example
{ "error": { "code": 100, "error_subcode": 2018001, "fbtrace_id": "AAAAAAAAAAA", "message": "(#100) No matching user found", "type": "OAuthException" }}