Hi there @tudsy,
Thanks for sharing your question with us! Happy to help!
I’m assuming that the documentation of the code you’re referencing if from our API article on how to add members to a list. Do you mind confirming whether or not you’re using a private or public API key in the call, this call will only work if you use a private API key vs. a public key and could be the reason for the error you’re receiving. If so, we have a helpful article that can walk your through how to create a private API key
Whenever an API call gets rejected, I’d recommend taking these troubleshooting steps that my coworker @Dov outlines in a similar post:
- Verify that the JSON is valid. You can check http://jslint.com/ to verify that the payload you’re sending is formatted correctly.
- Ensure that your base64-encoded string is also url-encoded.
- Cross-reference your request with the examples we have in our Track API documentation. One common mistake is the private api key is used in the request when the public api key is required or vice versa. In this case, the request will return a body of 0.
While neither support nor the Community can troubleshoot custom code since we do not have access to your codebase, the is the example snippet from our API docs. I’d suggest going over the code with a fine-tooth comb to ensure there are no additional or missing spaces/ letters that don’t need to be there.
<?php
require_once('vendor/autoload.php');
$client = new \GuzzleHttp\Client();
$response = $client->request('POST', 'https://a.klaviyo.com/api/v2/list/LIST_ID/subscribe?api_key=API_KEY', [
'body' => '{"profiles":[{"phone_number":"+13239169023","sms_consent":true,"email":"jeffklaviyo@gmail.com"}]}',
'headers' => [
'Accept' => 'application/json',
'Content-Type' => 'application/json',
],
]);
echo $response->getBody();
Finally, another Community member asked had a similar issue to this problem that I’d recommend checking out to gain more insight on what might be happening here as well.
Thanks for your participation in the Community!
-Taylor