我希望通过一个httr
包,通过其API发布一个数组以在电子邮件服务提供商中创建一个新的配置文件。可以在此处找到API文档。
通过文档提供了curl命令的副本和粘贴,但是我的实现抛出403。为在此处发布而替换了该键。
我真的很难确定问题。我对API调用(尤其是POST)非常陌生,并且感到缺少一个核心概念。
我的尝试:
identify_body <- '{
"token" : "public_key_goes_here",
"properties" : {
"$email" : "[email protected]",
"$first_name" : "Thomas",
"$last_name" : "Jefferson",
"Plan" : "Premium",
"SignUpDate" : "2016-05-01 10:10:00"
}
}'
httr::POST("https://a.klaviyo.com/api/identify",
body = identify_body,
content_type_json(),
verbose())
结果:
-> POST /api/identify HTTP/1.1
-> Host: a.klaviyo.com
-> User-Agent: libcurl/7.59.0 r-curl/3.3 httr/1.4.0
-> Accept-Encoding: gzip, deflate
-> Accept: application/json, text/xml, application/xml, */*
-> Content-Type: application/json
-> Content-Length: 222
->
>> {
>> "token" : "public_key_goes_here",
>> "properties" : {
>> "$email" : "[email protected]",
>> "$first_name" : "Thomas",
>> "$last_name" : "Jefferson",
>> "Plan" : "Premium",
>> "SignUpDate" : "2016-05-01 10:10:00"
>> }
>> }
<- HTTP/1.1 403 Forbidden
<- Content-Encoding: gzip
<- Content-Type: text/html
<- Date: Mon, 04 Jan 2021 22:02:12 GMT
<- Server: nginx
<- Vary: Accept-Encoding
<- Vary: Cookie
<- Content-Length: 779
<- Connection: keep-alive
<-
Response [https://a.klaviyo.com/api/identify]
Date: 2021-01-04 22:02
Status: 403
Content-Type: text/html
Size: 1.46 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="robots" content="NONE,NOARCHIVE">
<title>403 Forbidden</title>
<style type="text/css">
html * { padding:0; margin:0; }
body * { padding:10px 20px; }
来自文档
The Server-Side APIs use the same request and response formats. Requests are made with a GET request to the specified endpoint with a single parameter, data, which is a JSON object that has been base64 and URL encoded
您需要将请求转换为GET请求,并将JSON转换为base64 / URL编码的字符串,并作为名为的查询参数传递data
。
或者,您可以使用他们提供的帮助程序库之一。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句