Skip to main content
Solved

Why is my API call returning a 503 error when adding profiles to a List?

  • May 31, 2022
  • 1 reply
  • 391 views

Hi

 

I am getting error 503 when trying to add people to my profile section.

 

The following code is what I use to add people to my list (Single opt in):

 


<?php

$Email = "second@ecovib2d.com.au";
$phone ="0413242417";
$name = "Adrian Tudini";
$age = "51";

include '/home/ecovibdc/vendor/autoload.php';
include '/home/ecovibdc/vendor/guzzlehttp/guzzle/src/Client.php';

$client = new Client();

$response = $client->request('POST', 'https://a.klaviyo.com/api/v2/list/SXxfVK/subscribe?api_key=********************************', [ 
  'body' => '{"profiles":[{"email": "'.$Email.'"},{"phone_number": "'.$phone.'","sms_consent":true}]}',
  'headers' => [
    'Accept' => 'application/json',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();

?>

The basis of this code is the klaviyo API on how to subscribe a customer to a list in my klaviyo account.

 

Thanks. 

Best answer by Taylor Tarpley

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:

  1. Verify that the JSON is valid. You can check http://jslint.com/ to verify that the payload you’re sending is formatted correctly. 
  2. Ensure that your base64-encoded string is also url-encoded.
  3. 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 

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

1 reply

Taylor Tarpley
Community Manager
Forum|alt.badge.img+60
  • Community Manager
  • 2148 replies
  • Answer
  • May 31, 2022

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:

  1. Verify that the JSON is valid. You can check http://jslint.com/ to verify that the payload you’re sending is formatted correctly. 
  2. Ensure that your base64-encoded string is also url-encoded.
  3. 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