skip to Main Content

I’m trying to create a bot which interacts with Facebook Messenger. I’ve set up my webhook and can receive messages coming from Facebook. However, when I try to send a message, I get the following error back from Facebook:

{"error":{"message":"(#100) The parameter recipient is required","type":"OAuthException","code":100,"fbtrace_id":"F3iVNecj10i"}}

However, I’ve definitely got the recipient ID in my request. I’ve sent the request with my bot, cURL and the Chrome Poster extension and get the same result each time. The JSON I send is:

{"recipient":{"id":"XXXXXXXXXXXXXX"},"message":{"text":"hello, world!"}}

When using cURL, I took the example directly from the Facebook documentation and send this:

curl -k -X POST -H "Content-Type: application/json" -d '{"recipient":{"id":"XXXXXXXXXXXXXXXX"},"message":{"text":"hello, world!"}}' "https://graph.facebook.com/v2.6/me/messages?access_token=ACCESS_TOKEN"

The only difference between this and the example on Facebook is the -k which stops cURL from checking the SSL certificate. I’m tunneling through to my app using ngrok for the incoming messages but sending my requests direct to the Facebook Graph API. The fact that it’s happening in my app, cURL and Chrome Poster makes me think that it’s something to do with the request (but I can’t see what) or my Facebook app setup. Any help is greatly appreciated.

3

Answers


  1. Chosen as BEST ANSWER

    Turns out there were a few issues. The cURL request didn't include the quotes in the JSON so the quotes had to be escaped with characters. The Chrome Poster request didn't work because "content-type: application/json" wasn't set in the header. And my webapp didn't work because the JSON had a ";" at the end of it.

    So, the Facebook message was an indication of poorly formatted JSON, just not a very direct one!


  2. Check that the JSON payload is well formed.

    I used the Postman.app to help me out with this — it’s also available on Windows.

    Steps

    • Copy the URL into the “Enter request URL field”. This would include the access_token
    • Change the HTTP verb to GET
    • Under the “Headers” header, set Content-Type to application/json
    • Under the “Body” header, select “raw” and paste your JSON payload there. Make sure that this JSON payload is well formed by watching the error indicator displayed beside the line numbers.

    Once I got this fixed, I was able to move on to the next step.

    Login or Signup to reply.
  3. I got similar error some time back. Try using Postman. I tried the same request and replaced the user id and the page access token. It works fine.

    Click on the Import button on the top and paste your curl request under raw. Then try running the call. If you get the same error, go to the body and modify it. Make sure you put this in the body part of the Postman request. Replace the recipient id with yours.

    {
        "recipient":
        {
            "id":"123456789"
        },
        "message":
        {
            "text":"hello, world!"
        }
    
    }
    

    This is the full cURL call : Change Recipient ID and Page Access Token

    curl -X POST -H "Content-Type: application/json" -d '{ "recipient":{"id":"1234567" }, "message":{ "text":"hello from bot" }}' "https://graph.facebook.com/v2.6/me/messages?access_token=PASTETHETOKENHERE"
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search