I am trying to create a new paste using the PasteBin API with request
module like so:
var request = require("request");
request({
url : "http://pastebin.com/api/api_post.php",
method : "POST",
qs : {
"api_dev_key" : MY_DEV_KEY,
"api_option" : "paste",
"api_paste_code" : "random text"
}
},function(err,res,body){
...
});
My understanding is that since the method is POST
and querystring parameters are provided, the values in qs
object will be stored as key=value
pairs in the body. (Ref: How are parameters sent in an HTTP POST request?)
However, I get back a Bad API request, invalid api_option
from PasteBin. So I curl
ed the request from my terminal like so:
curl -X POST "http://pastebin.com/api/api_post.php" -d "api_dev_key=[MY_DEV_KEY]&api_option=paste&api_paste_code=some+random+text"
and this worked.
So this leads to two questions:
POST
request is made and qs
is provided? request
module?Rename the qs
key to form
in the object. The qs
key is for specifying the query string on the end of the URL (e.g. For GET requests). The form
key is for specifying the form URL encoded request body (e.g. For a POST request).
the same issue for me and my resolution which is perfectly working for me is.
request.post({
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
url : "http://pastebin.com/api/api_post.php",
body : "api_dev_key=MY_DEV_KEY&api_option=paste&api_paste_code=andom text"},function(err,res,body){ ...});
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