2 回答

TA貢獻1789條經驗 獲得超10個贊
您沒有像示例請求所示那樣對完整的請求正文進行編碼
$args = [
"api_key" => 'some_api_key_string',
"profiles" => [
[
"email" => "[email protected]",
"value" => "some value",
],
[
"email" => "[email protected]",
"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 protected]']
? ? ? ? ? ? ?)
? ? ? ? ];
? ? $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 關注
- 152 瀏覽
添加回答
舉報