Skip to main content
Contributor I
December 21, 2022
Solved

PHP SDK 400 bad request

  • December 21, 2022
  • 13 replies
  • 2019 views

Hi all,

Just started using the Klaviyo SDK and after several hours and reading api guides and postman quiries i cannot figure this out.

This is my error below

[400] Client error: `POST https://a.klaviyo.com/api/profiles/` resulted in a `400 Bad Request` response: {"errors":[{"id":"edd7f096-d88a-4b8c-80cd-175250722bfe","status":400,"code":"invalid","title":"Invalid input.","detail": (truncated...)

 

So FYI i can make get request like this and everything works great:

$klaviyo->Lists->getList('******');

 

As soon as i want to make a post request i try to send an associative array over the the keys of data , type and attributtes and no matter what way i send this data i even tried json etc i get the above error could anyone help?

$array[] = ['data' => ['type' => 'profile', 'attributes' => ['email' => 'test@outlook.com', 'first_name' => 'elliot',     'title' => 'fddfasdsfaf', 'organization' => 'fsdfdsfsd',    'external_id' => '1234', 'anonymous_id' => '12345', 'image' => 'dfds']]];
$response = $klaviyo->Profiles->createProfile($array);

 

 

This topic has been closed for replies.
Best answer by Brian Turcotte

Hi @ellputt and welcome to the Community!

 

Typically, 400 responses occur when the request is missing or the API key is invalid. Would you be willing to share the entire non-truncated error statement? I’m going to reach out to Engineering to gather some further context on this issue, so it will help to understand the issue better.

 

 

Thanks,

Brian,

13 replies

Contributor III
September 11, 2023

Thank you @Plutarch87 I think I will switch to call it manually, is a shame the SDK does not work as suppose to!

Contributor III
September 12, 2023

Hi @Plutarch87 after being working a lot with the PHP SDK I found out why I was getting the error.
I don’t know if you did the same in your code but just in case here is what i found out.

I was doing this `$this->klaviyoClient->Profiles->createProfile(json_encode($body));` I removed the `json_encode` and I passed just the `$body` (an associative array) and now it works!!

I tested with :
1. Profiles->subscribeProfiles($body);
2. Profiles->createProfile($body);

Contributor I
February 28, 2024

I had the same issue as couldn’t figure out the format of the PHP associative array to pass (no examples seem to be given anywhere!).  

This is what I used to get it to work - hope it helps somebody!

 

 $body =['data' => ['type' => 'profile', 'attributes' => ['email' => 'test@outlook.com', 'first_name' => 'elliot',     'title' => 'fddfasdsfaf', 'organization' => 'fsdfdsfsd',    'external_id' => '1234', 'anonymous_id' => '12345', 'image' => 'dfds']]];

$klaviyo->Profiles->createProfile($body);