与Zendesk API通信时,我无法将cURL请求转换为httr发布请求.我已经成功地从API中提取了数据,但到目前为止,发布仍然存在问题.
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.
我已经与Zendesk的API支持人员进行了交谈,但是很遗憾,他们没有R方面的经验,因此无法告诉我我的脚本是否错误.
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.
我得到的cURL示例如下(替换了所有敏感信息):
The cURL example I've been given, is as follows (all sensitive information replaced):
curl {subdomain}.zendesk/api/v2/nps/surveys/{survey_id}/invitations.json -d '{"invitation": {"recipients": [{"name": "Ed C", "email": "example@subdomain", "language": "en-US"}]}}' -H "Content-Type: application/json" -v -u {your_email}/token:{your_api_token} -X POST我对cURL的了解非常有限,但是我相信我可以使用以下脚本正确地联系API(同样,所有敏感信息都已替换):
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('{subdomain}.zendesk/api/v2/nps/surveys/{survery_id}/invitations.json' ,add_headers(Authorization="Basic {api_key}") ,body ='{"invitation": {"recipients": [{"name": "Ed C", "email": "example@subdomain", "language": "en-US"}]}}' ,encode='json' )我已经反复检查了Stack Overflow以及其他来源,但是到目前为止,还没有发现适用于我的问题的情况.
I've scoured Stack Overflow repeatedly, as well as other sources, but haven't found a situation applicable to my issue so far.
谢谢.
推荐答案经过反复尝试,我设法通过添加'content_type_json()'解决了我的问题.我不确定100%为何能正常工作,所以如果有人想澄清一下,我将不胜感激.
After much trial and error, I managed to resolve my issue by adding in 'content_type_json()'. I'm not 100% sure why exactly this worked, so if someone would like to clarify, I'd appreciate the input.
请参见下面的完整代码:
Please see below for full code:
r2 <- POST('{subdomain}.zendesk/api/v2/nps/surveys/{survery_id}/invitations.json' ,add_headers(Authorization="Basic {api_key}") ,content_type_json() ,body ='{"invitation": {"recipients": [{"name": "Ed C", "email": "example@subdomain", "language": "en-US"}]}}' ,encode='json' )更多推荐
在R中将cURL转换为httr
发布评论