10
votes

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.

enter image description here

3
Any codes for your try ? check this out too: stackoverflow.com/a/29945301/4409113 - ʍѳђઽ૯ท
Have you succeed in any other request? - Oleksandr
@Alexandr no. not yet get the answer. - Gunaseelan
@Empty2k12 Yes, I have read it and I have created the App also. - Gunaseelan

3 Answers

4
votes

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/

1
votes

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
0
votes

Your Json Data Should be send like this,it is not allowing next line

{"key":"mykey","access_token":"mytoken","site":"stackoverflow.com","preview":"false","filter":"default"}