在R中将cURL转换为httr

编程入门 行业动态 更新时间:2024-10-09 03:18:48
本文介绍了在R中将cURL转换为httr的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

与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

本文发布于:2023-10-12 05:17:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1483822.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:转换为   中将   cURL   httr

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!