Facebook Messenger bot error: The parameter recipient is required - facebook-graph-api

the bash command I used to connect the bot is: curl -ik -X POST 'https://graph.facebook.com/v2.6/me/messages?access_token=#AccessToken'
My error message is:
{"error":{"message":"(#100) The parameter recipient is
required","type":"OAuthException","code":100,"fbtrace_id":"EFqWAGq2ABs"}}
Do anyone how to solve it ?

Just in case anyone missed this, I encountered this issue when I accidentally use the wrong content type - I was using application/x-www-form-urlencoded instead of application/json
So my advise overall is,
Check if you are indeed passing the parameter
Double check the characters and encoding
Make sure to use the correct endpoint
and Make sure to use the correct content type when posting the JSON Request.

You need to send the recipient id param. Try:
curl -X POST -H "Content-Type: application/json" -d '{ "recipient":{"id":"YOUR RECIPIENT ID" }, "message":{ "text":"hello from bot" }}' "https://graph.facebook.com/v2.6/me/messages?access_token=YOUR_ACCESSTOKEN"
Best regards.

There is another reason for this error message: when you send incorrect characters (like a -tab-) Facebook return this error as well so check your return text on special chars.

Please use the "thread_settings" endpoint "https://graph.facebook.com/v2.6/me/thread_settings" as your API endpoint.
You are using the messages endpoint.

It comes down to the logic of your bot. I got this error as well just recently and it took me days to debug it. The problem for me was I called the callSendAPI(messageData) method outside of the function that compiled the messageData object.
Obviously, passing messageData outside of the function that compiles it sends an empty object instead of the compiled one. Thus the error message (#100) The parameter recipient is required. Simply because the empty object doesn't have any receipientId defined.
Please check your code's logic to ensure you didn't do the same mistake as I. Hope this helps :) Happy programming.

The endpoint is wrong. Instead of https://graph.facebook.com/v2.6/me/messages?access_token=#AccessToken, use this endpoint
https://graph.facebook.com/v2.6/me/messenger_profile?access_token=<PAGE_ACCESS_TOKEN>
This happens when we do not read the documentation., the info is right here https://developers.facebook.com/docs/messenger-platform/discovery/welcome-screen#,
right under the "Setting the Get Started Button Postback".

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"

This issue may also occur when you have an error in your code (syntax or logic error). In my case, I had this part in my code in webhook.php (which is my registered callback page in Facebook)
$message = $input['entry'][0]['messaging'][0]['message']['text'];
"message":{
"text":"Sorry, we currently do not have an article related to "'.$message.'"."
}
By the time I registered https://domain.com/webhook.php as callback, it wouldn't receive any $message yet so it causes an error and wouldn't accept my callback url.
Check your code and make sure you echo only the challenge.
$challenge = $_REQUEST['hub_challenge'];
$verify_token = $_REQUEST['hub_verify_token'];
if ($verify_token === 'verify_token') {
echo $challenge;
}

Related

How to send a post request with parameter?

I created a WebAPI with Visual Studio 2017 using its .Net Core template. I am able to test my Get() code with Postman and everything works correctly. Now, I would like to send a Post request so it calls the following code.
[HttpPost]
public void Post([FromBody] string value)
{
Console.WriteLine("value" + value);
}
However, I get the following error when call
https://localhost:44364/api/carbon?value=100
{
"": [
"A non-empty request body is required."
]
}
I am sure the problem lies with they way my Postman is setup but it looks correct.
Any suggestions? Thank you!
Updated per suggestion
I added key/value to the body and received "The input was not valid."
You do not need to use Query string.You need to post the string with raw json, and do not forget the double quotation marks.Refer to here to get more details on post methods by Postman.
The error message you're receiving is very descriptive of the problem - you haven't provided a body in your request.
Click "Body" in Postman (next to "Headers") then select the type of body you want to send, for example x-www-form-urlencoded and then add a key/value pair beneath, e.g. test and hello world.
Hit "Send".

GET request with body timing out with URLSession and Alamofire

I'm working with a slightly unconventional API that is expecting a JSON body with a GET request and I have no control over this. Unfortunately, every time I attempt to make the request, it seems to completely disappear and never make it to the API. I originally wrote the request using a standard URLSession and then switched to try Alamofire in an attempt to fix it but ended with the same result. My request looks like this:
Alamofire.request("http://192.168.1.1:8000/connect/", method: .get, parameters: ["test": "test"], encoding: JSONEncoding.default)
.responseJSON { response in
let body = response.request?.httpBody
guard response.result.isSuccess else {
onCompletion(nil)
return
}
onCompletion(response.result.value as! [String : Any]?)
}
This exact code works for a different request where there is no JSON in the body, but seemingly the moment I add it, it just times out. This has already been discussed on the alamofire github repo (https://github.com/Alamofire/Alamofire/issues/1819) but the final comment with what should be working code isn't really any different to mine, so doesn't provide any help, nor do the other linked issues.
Printing the request with debugPrint gives me this curl command
$ curl -i \
-H "Content-Type: application/json" \
-d "{\"test\":\"test\"}" \
"http://192.168.1.1:8000/connect/"
Which is missing the -X GET flag, but when I add that in, the request works as expected and the server responds, so I know the API itself is working and is happy processing the JSON in the body, so I'm at a loss as to what's going on.
I've installed Timberjack to attempt to trace things, which didn't give me any more info at all, just what I already knew
Request: GET http://192.168.1.1:8000/connect/
Headers: [
Content-Type : application/json
Content-Length : 24
]
Although I'm not sure if it's supposed to be showing me the body as well which it isn't?
In both cases (URLSession and Alamofire) the request gives the following output which I don't see at any other time:
2017-01-22 23:31:09.797453 my-app[3755:1349066] [] nw_endpoint_flow_service_writes [2 192.168.1.1:8000 ready socket-flow (satisfied)] Write request has 4294967295 frame count, 0 byte count
2017-01-22 23:32:04.484182 my-app[3755:1349066] [] __tcp_connection_write_eof_block_invoke Write close callback received error: [89] Operation canceled
Anyone have any ideas on what's going on as I'm completely at a loss at this point.
Update
I've done some more digging. If I change the endpoint to https://httpbin.org/get then the request goes through just fine and I get a response. Whilst this kind of suggests the API server is refusing to process the request, it's still working with the cURL command so that can't really be the issue.
I also forgot to mention (although not sure it should make a difference) that the API I'm trying to communicate with is connected via an ad-hoc wifi. Other requests to it work just fine though so I can definitely communicate with it.
Update 2
So I've been able to switch the server to using POST instead of GET and unsurprisingly it now works, however I would still love to know of a solution to the original problem
URLSession and CFHTTPMessage cannot send a message body for a GET request. They send the content length for the body, but do not send the body itself. This results in a timeout.
In order to resolve this issue I've used libcurl to handle the GET requests which have a message body to my project. I use URLSession everywhere else. When you add a body to a request using libcurl it changes the request to a POST, but that can be changed back to a GET after setting the body and before submitting the request.

What does the Jawbone endpoint_error "Not found" mean and how do I fix it?

I'm working on jawbone, I got the token
accesstoken
refreshtoken
When I try to get the basic information on the url :
https://jawbone.com/nudge/api/v.1.0/users/#me follow the jawbone api : https://jawbone.com/up/developer/endpoints/user
I received the error :
{"data":{},
"meta":{"message":"Not Found",
"time":1380614680,
"error_type":"endpoint_error",
"error_detail":"Unsupported API version: 1.0",
"code":404}
}
What does this error mean and how do I fix it?
I got the same problem so I ask to the support and here's the answer:
this error message is a little misleading, it actually means it wasn't
able to identify your OAuth token
Did you forget to put the "Authorization: Bearer" in the http header?
I didn't but i still got that error!
At the moment the jawbone api works fine ...

Error with Flex HTTPService and Django, even though POST is successful

(This is the first time I've done this actually.)
<mx:HTTPService id="post_update" method="POST" result="{Dumper.info('bye')}"/>
The result handler above is just for debugging purposes, but its never hit, even though what I'm uploading via POST...
post_update.url = getPath(parentDocument.url)+"update";
post_update.send(new_sel);
...is received and handled successfully by my Django view:
def wc_post(request) :
request.session['wc'] = request.POST
return http.HttpResponse("<ok/>", mimetype="text/xml")
As far as what I'm sending back from Django, I'm following the guidelines here:
Sending Images From Flex to a Server
I just don't want it to generate an error on the Flex side considering Django is actually receiving and processing the data. Any help appreciated. Can't remember the text of the error in Flex at the moment.
UPDATE: new_sel (what I'm posting from Flex) is just a Flex Object, with various text fields.
UPDATE: various error messages from event.message (in fault handler):
faultCode = "Server.Error.Request"
faultString = "HTTP request error"; DSStatusCode = 500; errorID = 2032; type = "ioError"
This is more grasping at straws than answers, but do I have to send a particular type of header back from Django- the default sent by Django includes a 200 success status code, and the response I was sending of "<ok/>" with mime type of "text/xml" was following the example exactly that I provided from that other source.
And also the url I'm sending the POST to is localhost:8000/wr_view1/wr_webcube/update, and I previously successfully did a GET to localhost:8000/wr_view1/wr_webcube/webcube.xml, and despite the .xml extension in the case of GET, it was still being handled by Django (and without errors in Flex). In the case of this POST, once again, the data is actually succesfully sent and handled by Django, but Flex is returning Error 2032, which I found out can mean numerous different things including cross domain issues, but don't see how that's the case here.
Just had to return HttpResponse("ok") Didn't like it being sent as xml for some reason. So much ado about nothing I guess.

how to PUT multiple query parameter in REST web service

Do anyone know how to PUT multiple query parameter in REST web service?
I have write using java.My curl sample is like this:
curl -X PUT http://localhost:8080/project/resources/user/directory/sub-directory?name=shareuser&type=Read -v
My program is :
#PUT
#Path("{user}/{directory:.+}")
public Response doshare(#PathParam("user")String name,
#PathParam("directory")String dir,
#QueryParam("name")String sharename,
#QueryParam("type")String type){
mongoDAOImpl impl=new mongoDAOImpl();
Mongo mongo=impl.getConnection("127.0.0.1","27017");
DB db=impl.getDataBase(mongo,"public");
DBCollection coll=impl.getColl(db,name);
DBCollection coll2=impl.getColl(db,"sharedb");
shareDTO sharedto=new shareDTO();
String authority=type.toLowerCase();
if(authority.equals("rd")){
sharedto.setAuthority("4");
}else if(authority.equals("rw")){
sharedto.setAuthority("12");
}
sharedto.setTargetuser(sharename);
sharedto.setRealURI("/home/public/"+name+"/"+dir);
sharedto.setIdentifier(name);
sharedto.setParentURI("/home/public/"+sharename);
boolean bool = false;
sharefun=new sharefunction();
if(sharefun.checksubfoldershared(coll, coll2, sharedto)){
bool=sharefun.sharefiles(coll, coll2, sharedto);
}else{
System.out.println("Error");
}
// ...
But I only get the name query parameter.How to get or how to type in curl command in order to get all query parameter?
Your code is fine - the problem is with the way you're invoking curl. When passing a URL to curl that contains a '&', you have to put quotes around the URL. Otherwise, the shell will interpret the stuff after the '&' as a separate command.
EDIT: My text is getting munged when I submit it as a comment. Here's what you need to do:
curl -X PUT 'http://localhost:8080/project/resources/user/directory/sub-directory?name=shareuser&type=Read' -v
Have you tried using the -d option? e.g.
curl -X PUT -d "name=shareuser&type=Read" http://locahost:8080/project/resources/user/directory/sub-directory -v
You could try handling this all as a multipart upload (the server-side details aren't standardized and you didn't say what framework you're using so I can't give more clues) but I question why you're having the user and permissions set (via any parameters) in the first place. Surely you'd be better off deriving the user to store as through inspecting the user's login credentials and using a default set of permissions that they can change later on? Nearly as cheap, and enormously simpler.