Passing headers in webhook JSON

I’m trying to call a cloud code endpoint that I created in Parse using a Spark webhook. I’m working off the LIBRATO example in the Spark docs and I’m able to get that working fine.

Parse gives an exmaple of how to call the endpoint with a curl command like this:

curl -X POST \
  -H "X-Parse-Application-Id: MYAPPLICATIONID" \
  -H "X-Parse-REST-API-Key: MYRESTAPPLICATIONID" \
  -H "Content-Type: application/json" \
  -d '{}' \
  https://api.parse.com/1/functions/hello

Which calling this through curl does product the desired result.

I’ve tried to adapt that to the JSON from the LIBRATO example so I end up with this.

{
    "eventName": "buttonSelected_",
    "url": "https://api.parse.com/1/functions/hello",
    "requestType": "POST",
    "Content-Type": "application/json",
    "Headers": {
        "X-Parse-Application-Id": "MYAPPLICATIONID",
    	"X-Parse-REST-API-Key": "MYAPPLICATIONRESTID"
    },
    "json": {},
    "mydevices": true
}

…which doesn’t work. :frowning: Nothing happens on the Parse side.


I’ve also tried moving the Parse key fields outside of the “Headers”.

{
    "eventName": "buttonSelected_",
    "url": "https://api.parse.com/1/functions/hello",
    "requestType": "POST",
    "Content-Type": "application/json",
    "X-Parse-Application-Id": "MYAPPLICATIONID",
    "X-Parse-REST-API-Key": "MYAPPLICATIONRESTID",
    "json": {},
    "mydevices": true
}

When I do this and try to upload the JSON through

spark webhook create JSONTest.json

I get the error:

tryParse error  [SyntaxError: Unexpected string]
Using settings from the file JSONTest.json
Please specify an event name

So I assume the format of the JSON is wrong.

I’m am going crazy trying trying to figure this out because it seems like it should be extremely easy to implement! I’m assuming that my problem is how to pass along the credentials in the JSON post up to Parse but not sure what I’m doing wrong.

headers should have a lowercase ‘h’, not “Headers”, but “headers” :slight_smile:

and "Content-Type": "application/json", should be in headers, so try…

{
    "eventName": "buttonSelected_",
    "url": "https://api.parse.com/1/functions/hello",
    "requestType": "POST",
    "headers": {
        "X-Parse-Application-Id": "MYAPPLICATIONID",
    	"X-Parse-REST-API-Key": "MYAPPLICATIONRESTID",
        "Content-Type": "application/json"
    },
    "mydevices": true
}
2 Likes

Doh :grin: That did it! Thank you so much for your help.

I havn’t been able to find a complete tutorial on how to get the Spark to work with Parse but not that I have this working I’m going to make one!

1 Like