2 回答

TA貢獻(xiàn)1789條經(jīng)驗(yàn) 獲得超10個贊
您沒有像示例請求所示那樣對完整的請求正文進(jìn)行編碼
$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貢獻(xiàn)1815條經(jīng)驗(yàn) 獲得超6個贊
最后,我找到了解決方案:
#1: 將 'content type' => application/json 添加到標(biāo)頭
#2: 強(qiáng)制將配置文件數(shù)組轉(zhuǎn)換為對象 - 由于行會表示:配置文件參數(shù)是 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 關(guān)注
- 170 瀏覽
添加回答
舉報(bào)