Reputation: 662
This is probably an easy question, but I haven't found a super clear answer.
I basically want to convert this curl POST request:
curl https://api.leaddyno.com/v1/affiliates \
-d key=[YOUR_PRIVATE_KEY] \
-d [email protected]
to an API call in Apps Scripts (I think this question goes across all languages though).
I found I could just add the -d parameters as query parameters to the end of the request, but I can't seem to pass them in the body. When passing JSON I just use JSON.stringify on a javascript object and it works great. So I guess my question is how do I format this so it has the same effect as when I make the data a query string?
This works great: https://api.leaddyno.com/v1/affiliates?key=xxxxx&[email protected]
Thanks in advance.
Upvotes: 0
Views: 133
Reputation: 5782
Data to be sent in the post body is added to the payload property of the options object you pass to UrlfetchApp.
var payload = {key:1233456,email:"[email protected]"};
var options = {method:"POST", contentType:"application/json", payload:JSON.stringify(payload)};
var URL =" https://api.leaddyno.com/v1/affiliates";
var results = UrlfetchApp.fetch(URL,options);
Upvotes: 1