带有身份验证令牌的httr POST请求

肯特·奥尔

我希望通过一个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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

带有身份验证的GET请求

带有身份验证的HTTP HTTP获取请求

如何在我的HTTP请求中使用带有身份验证的代理?

使用restTemplate发送带有身份验证标头的GET请求

带有身份验证的python请求(access_token)

带有身份验证的python请求(access_token)

在Ruby中发送带有身份验证的https发布请求

带有身份验证标头的Java Jersey HTTPS GET请求

具有身份验证的httpget请求

ASP核心拦截所有身份验证请求

带有身份验证的requests.post为python中的jira rest api提供错误415

如何使用令牌身份验证对 Post 请求进行身份验证?

Python:使用请求或urllib3下载具有身份验证的文件

Python请求带有验证令牌的POST到网站

Python请求-身份验证令牌

带有基本 POST 请求的 OAuth 令牌

具有Kerberos身份验证的WCF:由于身份验证失败,无法满足对安全令牌的请求

使用HTTR的POST请求

使用 POST 请求的身份验证无法验证数据

带有httr的POST请求后的无效内容类型

使用Javascript发出HTTP POST身份验证基本请求

CAS身份验证后恢复原始POST请求?

通过POST使用请求库进行python身份验证

POST 400错误请求React身份验证

Firebase存储在Android中没有用于请求的身份验证令牌

Firebase存储在Android中没有用于请求的身份验证令牌

使用身份验证令牌的Axios请求有时在Safari中失败

验证POST请求Laravel?

带Twitch身份验证的带有请求承诺的NodeJS发布请求