2

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?

Dmitri Zaitsev
  • 13,548
  • 11
  • 76
  • 110
  • 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 May 06 '14 at 10:27

1 Answers1

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

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

 "body": {
    "ids": ["someMessageId"]
 }
thousandsofthem
  • 1,355
  • 10
  • 9
  • I have tested and there is no difference. Also this object is inside JavaScript code on Parse Cloud, so I don't see why that is invalid. Also see this example: https://www.parse.com/docs/cloud_code_guide#networking – Dmitri Zaitsev May 06 '14 at 10:38
  • @DmitriZaitsev some JSON parsers are very strict, some are more forgiving. It is best to always use JSON that strictly complies with the standard to avoid problems. – Timothy Walters May 06 '14 at 20:54