Skip to main content
Solved

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

  • May 16, 2022
  • 1 reply
  • 134 views

Forum|alt.badge.img+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.

Best answer by dartacus

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.

View original
Did this topic or the replies in the thread help you find an answer to your question?

1 reply

Forum|alt.badge.img+5
  • Author
  • Problem Solver III
  • 62 replies
  • Answer
  • May 16, 2022

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.