I'm having trouble in converting a cURL request, into a httr post request, when communicating with the Zendesk API. I've successfully pulled data from the API, but posting is so far proving problematic.
I've spoken to Zendesk's API support staff, but unfortunately, they don't have any experience in R, so can't tell me if my script is wrong or not.
The cURL example I've been given, is as follows (all sensitive information replaced):
curl https://{subdomain}.zendesk.com/api/v2/nps/surveys/{survey_id}/invitations.json -d '{"invitation": {"recipients": [{"name": "Ed C", "email": "example@subdomain.com", "language": "en-US"}]}}'
-H "Content-Type: application/json"
-v -u {your_email}/token:{your_api_token} -X POST
My cURL knowledge is very limited, but I believe I am contacting the API correctly with the below script (again, all sensitive information replaced):
r2 <- POST('https://{subdomain}.zendesk.com/api/v2/nps/surveys/{survery_id}/invitations.json'
,add_headers(Authorization="Basic {api_key}")
,body ='{"invitation": {"recipients": [{"name": "Ed C", "email": "example@subdomain.com", "language": "en-US"}]}}'
,encode='json'
)
I've scoured Stack Overflow repeatedly, as well as other sources, but haven't found a situation applicable to my issue so far.
Thanks in advance.