Vesa
Vesa

Reputation: 217

Curl and JSON beginner - web request POST

I'm a curl and JSON beginner.

I am trying to use an online API and this works:

curl -X POST https://blah.com/trigger/{test_event}/with/key/mykeynumber123

The service specifies that I should also be able to send additional data like so:

You can also send an optional JSON body of:

{ "value1" : "", "value2" : "", "value3" : "" }

The data is completely optional, and you can also pass value1, value2, and value3 as query parameters or form variables. This content will be passed on to the Action in your Recipe.

So my issue is I don't know how to format this. The first curl example works but if I try this for example it won't work:

curl -X POST https://blah.com/trigger/{test-event}{"value1":"test","value2":"test2","value3":"test3"}/with/key/mykeynumber

Any advice?

Upvotes: 0

Views: 380

Answers (2)

Sabuj Hassan
Sabuj Hassan

Reputation: 39365

You can post json data with appropriate header:

curl -X POST
  https://blah.com/trigger/{test_event}/with/key/mykeynumber123
  -H "Content-Type: application/json"
  -d '{ "value1" : "", "value2" : "", "value3" : "" }'

If you are running this from windows, then use double quote (") instead of single at -d parameter.

Upvotes: 1

ronalchn
ronalchn

Reputation: 12335

Try

curl --data "value1=test&value2=test2&value3=test3" https://blah.com/trigger/{test_event}/with/key/mykeynumber123

I think the JSON is just a way of formatting it for display purposes.

Your next sentence mentions passing them as form parameters, which is what the above command does.

The query parameters mentioned would be something like:

curl -X POST https://blah.com/trigger/{test_event}/with/key/mykeynumber123?value1=test&value2=test2&value3=test3

Upvotes: 0

Related Questions