Solved

API: passing profiles to the https://a.klaviyo.com/api/v2/list/{list_id}/members endpoint

  • 16 May 2022
  • 1 reply
  • 114 views

Userlevel 2
Badge +5

Currently integrating our own mailing list subscription flows, ie, when someone places an order and subscribes then opt-in-verifies as part of it, with Klaviyo.

I’m using https://a.klaviyo.com/api/v2/list/{list_id}/members for this, platform is a LAMP server, I’m sending requests using PHP’s curl library. It’s a custom ecommerce solution.

The request auths OK, but I keep getting a {"detail":"profiles is a required parameter."} response.

Similar requests have not been a problem.

Here’s the payload:

$data = (object) array(    'profiles' => array(        0 => (object) array('email' => $email_to_sub)    ));$jsonObj = json_encode($data);

...and then $jsonObj is set as the ‘data’ field for CURLOPT_POSTFIELDS, after being url encoded, the exact same method that works just fine for several other Klaviyo API requests such as tracking orders.

I have tried variations on this, such as passing the array to CURLOP_POSTFIELDS with ‘profiles’ as the key. Still no luck.

Has anyone had a similar problem?

Many thanks.

icon

Best answer by dartacus 16 May 2022, 12:34

View original

1 reply

Userlevel 2
Badge +5

FIXED! Make sure you set CURLOPT_HTTPHEADER to array('Content-Type:application/json’), and submit the body as url encoded json as the only contents of CURLOPT_POSTFIELDS.

Reply