I have tried to upvote a stackoverflow question with the stack exchange api and failed. I have tried a lot but I didn't get it to work.
URL :
http://api.stackexchange.com/2.2/questions/35007869/upvote
Docs
https://api.stackexchange.com/docs/upvote-question
Json Data :
{
"key" : "my key",
"access_token" : "my token",
"site" : "stackoverflow.com",
"preview" : "false",
"filter": "default"
}
I tried through fiddler with following parameters.
User-Agent: Fiddler
Host: api.stackexchange.com
Content-Length: 159
Content-Type: application/json; charset=utf-8
And POST
method. But I am failed with following error message.
error_id=400
error_message=site is required
error_name=bad_parameter
But I have provided the site in my JSON object. So Any help will be highly appreciable.
Update
While try this in fiddler I got following message.
You need to send them as form data, with Javascript it would be like this:
var request = new XMLHttpRequest();
request.open('POST', 'http://api.stackexchange.com/2.2/questions/35007869/upvote', true);
var formData = new FormData();
formData.append('key', 'my key');
formData.append('access_token', 'my token');
formData.append('site', 'stackoverflow.com');
formData.append('preview', 'false');
formData.append('filter', 'default');
request.send(formData);
Here's a guide to do it with Android: http://www.onlymobilepro.com/2013/03/16/submitting-android-form-data-via-post-method/
You have to send the parameters as URL arguments, not as a raw JSON on the request body. In order to perform an upvote, send the following POST request:
http://api.stackexchange.com/2.2/questions/35007869/upvote?site=stackoverflow.com&key=YOUR_KEY&access_token=YOUR_TOKEN&preview=false&filter=default
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