Solved

remove email from list gives 400 bad request error with error message error nil

  • 19 December 2022
  • 5 replies
  • 531 views

Badge +1

Hi there,

We are using the endpoint https://a.klaviyo.com/api/v2/group/{list_or_segment_id}/members/all to get all the emails from a list and then using that on this endpoint https://a.klaviyo.com/api/v2/list/{list_id}/members to delete all the emails returned by the first endpoint from the same list. 

Sometimes we get 400 response code but the error message is empty.

 

It would be useful to get a message that specifies exactly what part of the request is not correct.

I checked for the email list sent to not be empty and for the emails sent to be correct, so that is not the problem, what else could cause this 400 bad request response?

 

Thanks!

 

 

 

icon

Best answer by Brian Turcotte 20 December 2022, 00:28

View original

5 replies

Userlevel 7
Badge +36

Hi @Antonia Biro and welcome to the Community!

 

Firstly, are you getting the 400 error every time you make the request, or is the request successful sometimes?

 

Typically, a 400 error occurs when the request is missing or you called an invalid ID or API key. Would you be willing to add a screenshot of the error message (with sensitive info redacted)? According to our documentation, the response of all API errors contain a message parameter which has developer-facing information about why the request failed, so I will have to reach out to our engineering team to check why this would be blank.

 

- Brian

Badge +1

Hi @Brian Turcotte thanks for the quick response,

 

Regarding the first question, the 400 error happens sometimes, not at every request to the https://a.klaviyo.com/api/v2/list/{list_id}/ delete endpoint, 

 

The api key is correct, I checked, the error returned by a wrong api key is different, and the list ID is also correct, and the error would be a 404 if it was incorrect, not 400.

 

Regarding the second part of your response, the problem is that there is no error message to make a screenshot of, the body returned is empty.

 

I tried simulating in postman a few bad requests to that endpoint and for example if I send the

"emails": []

array empty, the response is a 400 status code and the body is this:

{

     "detail": "at least one \"emails\", \"phone_numbers\", or \"push_tokens\" parameter is required."

}

 

no message parameter present.

 

If the error originates from the wrong api_key the error message is this:

{
    "message": "The API key specified is invalid."
}

 

so here we get the message parameter.

 

Not sure what else I could check. What else could cause the 400 error?

 

Thanks!

Userlevel 7
Badge +36

Hi @Antonia Biro!

 

Just to confirm, are you doing everything exactly the same when you call this endpoint and receive different results? In other words, can you think of anything you might be doing differently when you receive the error? 

 

I’m only asking because I spoke with Engineering, and this isn’t a widely known issue, so any further details will help in establishing a potential cause. If you don’t mind, would you be able to share more details about the exact steps you take to make the calls (with any sensitive information redacted)? 

 

Thanks for using the Community!

- Brian

Badge +1

Hello @Brian Turcotte 

 

The error stopped appearing for a while, we added some more logging and now it started happening again and discovered something new. Before the 400 error occurs there is a 429 too many requests error.

Is it possible that the 429 error causes the 400 error?

I looked in the api https://developers.klaviyo.com/en/v1-2/reference/remove-members

and there is nothing mentioned about rate limiting, or how the api reacts when such a limit is hit.

 

Do you have any idea as to what that behaviour of the api is? And if it might cause the 400 error, and how we could work around that?

 

Thanks!

Userlevel 7
Badge +36

Hi @Antonia Biro!

 

Have you considered using the new V3 endpoint to accomplish this?

Removes a profile from a list with the given list ID.The provided profile will no longer receive marketing from this particular list once removed. Removing a profile from a list will not impact the profile's consent status or subscription status in general.

 

The new v3 endpoints have more expansive information on rate limiting. If there is a request that fails with a 400 error, you could also implement retry logic to attempt the request again.

 

If you continue to get a 400 error at that point, it would likely indicate some sort of formatting error within the API call - the 429 error is likely agnostic of the 400.

 

I hope this helps!

- Brian

Reply