1
votes

I am using Parse Cloud Code to make a 'DELETE' HTTP Request to Delete Multiple Messages from Iron.io.

It is using exactly the same headers and url as 'GET' request to Get Message from the Queue:

    headers: {
        'Content-Type': 'application/json;charset=utf-8',
            'Authorization': 'OAuth ' + ironToken
      },

The 'GET' request does work, whether I put method: 'GET' or not inside Parse.Cloud.httpRequest(). It does work even if I send some data as body: (which are ignored).

However, for a 'DELETE' request, I need to send body:

 body: {
    'ids': ['someMessageId']
 }

And this requests fails with very unhelpful message:

{
"status":400,"headers":
 {"Access-Control-Allow-Origin":"*",
 "Connection":"keep-alive",
 "Content-Length":"32",
 "Content-Type":"application/json",
 "Date":"Tue, 06 May 2014 10:15:27 GMT"
},
"text":"{\"msg\":\"Failed to decode JSON.\"}",
"data":{"msg":"Failed to decode JSON."},
"buffer":[ ...],
"cookies":{}
}

Any idea why this happens and what else can I test?

1
I'd say the error is very helpful. It returned a status 400, which two seconds of googling explains as "your request is malformed". It is even more helpful by telling you that it couldn't decode the JSON in your request. So check that JSON, which is probably not valid. For starters, strings start with double quotes and not single quotes. - gnasher729

1 Answers

6
votes
 body: {
    'ids': ['someMessageId']
 }

Is not valid json object. You need double quotes everywhere:

 "body": {
    "ids": ["someMessageId"]
 }