2 回答
TA贡献1789条经验 获得超10个赞
您没有像示例请求所示那样对完整的请求正文进行编码
$args = [
"api_key" => 'some_api_key_string',
"profiles" => [
[
"email" => "john_doe@somewhere.com",
"value" => "some value",
],
[
"email" => "jane_doe@somewhere.com",
"value" => "some other value",
]
],
];
$listId = 123;
$url = "https://a.klaviyo.com/api/v2/list/{$listId}/members";
$response = wp_remote_post($url, json_encode($args));
这将为您提供如示例中所示的输出
TA贡献1815条经验 获得超6个赞
最后,我找到了解决方案:
#1: 将 'content type' => application/json 添加到标头
#2: 强制将配置文件数组转换为对象 - 由于行会表示:配置文件参数是 JSON 对象列表
工作代码:
$args = ["api_key" => "your_API_key",
"profiles" => array(
(object)['email' => 'email@something.success']
)
];
$res = wp_remote_retrieve_body( wp_remote_post( 'https://a.klaviyo.com/api/v2/list/you_list_ID/members', [
'headers' => ['Content-Type' => 'application/json'],
'body' => json_encode($args)
]));
- 2 回答
- 0 关注
- 105 浏览
添加回答
举报