i am trying to send a batch request with graph api batch request using axios. When I tried with postman i tried the following - I am trying to post a send api with batch request.
url = https://graph.facebook.com?access_token=EA...`.
raw body = `{
"batch":[
{
"method": "POST",
"relative_url": "me/messages?access_token=<ACCESS_TOKEN>",
"body": "{ \"messaging_type\": \"MESSAGE_TAG\",\r\n \"tag\": \"ISSUE_RESOLUTION\",\r\n \"recipient\": {\r\n \"id\": \"1111944272264076\"\r\n },\r\n \"message\": {\r\n \"text\": \"hello, world!\"\r\n }}"
}
]
}
and the response is
[
{
"code": 400,
"headers": [
{
"name": "WWW-Authenticate",
"value": "OAuth \"Facebook Platform\" \"invalid_request\" \"(#100) The parameter recipient is required\""
},
{
"name": "Expires",
"value": "Sat, 01 Jan 2000 00:00:00 GMT"
},
{
"name": "Strict-Transport-Security",
"value": "max-age=15552000; preload"
},
{
"name": "Facebook-API-Version",
"value": "v2.10"
},
{
"name": "Content-Type",
"value": "text/javascript; charset=UTF-8"
},
{
"name": "X-App-Usage",
"value": "{\"call_count\":0,\"total_cputime\":0,\"total_time\":0}"
},
{
"name": "Access-Control-Allow-Origin",
"value": "*"
},
{
"name": "Cache-Control",
"value": "no-store"
},
{
"name": "Vary",
"value": "Accept-Encoding"
},
{
"name": "Pragma",
"value": "no-cache"
}
],
"body": "{\"error\":{\"message\":\"(#100) The parameter recipient is required\",\"type\":\"OAuthException\",\"code\":100,\"fbtrace_id\":\"BdrR5exbYCu\"}}"
}
]
response code is 200. i have given recipient in body.
You don't need to URL encode the entire body. Only the content of each parameter. Try this as the body for request:
{
"batch":[
{
"method":"POST",
"relative_url":"me/messages",
"body": "recipient={\"id\": \"1111944272264076\"}&message={\"text\": \"hello, world!\"}"
}
]
}
Note: Instead of URL coding, I just escaped the characters. Makes the code much more readable
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With