Skip to main content
Solved

API - 504 Gateway Timeout

  • December 15, 2022
  • 6 replies
  • 525 views

Forum|alt.badge.img+2

Hi,

 

We are using the profile API as documented here: https://developers.klaviyo.com/en/reference/get_profiles

On an extremely frequent basis (~50% of the time) we receive the following error:

Server error: `GET https://a.klaviyo.com/api/profiles/` resulted in a `504 Gateway Timeout` response

 

 

 - It isn’t a code error because, if re-ran a few minutes later, it works

 - It isn’t a rate limit error, as that is documented to be a 429 error (https://developers.klaviyo.com/en/reference/api_overview)

 

I see one other mention of a 504 on these forums (the Magento thread), but that seemed to be a misconfiguration issue with that user.

 

It appears your Klaviyo API is managed via Cloudflare. Are there any further limits imposed by Cloudflare config at your end?

Any input or investigation would be fantastic. As it stands, the inconsistent response makes it hard to rely on the API

Best answer by Brian Turcotte

Hi @chris_workinggears,

 

Just wanted to give another update - there’s a lot of attention on this subject, and I see that you have a support ticket open as well. I will update the thread as soon as we know more about what the source of the issue is, so that the other Community members can also learn from this.

 

Thanks so much for being a Community member!

- Brian

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

6 replies

Brian Turcotte
Forum|alt.badge.img+37

Hi @chris_workinggears and welcome to the Community!

 

Just so myself and other Community members can get some further perspective on this, what integration you are using? I see that you referenced the Magento thread, are you also integrated with that?

 

Also, have you tried setting a pagination parameter to reduce the complexity/volume of the request? 

 

These questions might help myself and other Community members obtain some further perspective on the issue. In the meantime, I’d also recommend trying these basic troubleshooting tasks that can sometimes alleviate gateway issues from the requester’s side:

  • Check your internet connection to ensure that it is stable and fast enough to support the API request.
  • Check your device or network settings to ensure that you are not being blocked by a firewall or other security measure. You may need to consult with your IT team or network administrator for help with this.

 

As far as any limits imposed by Cloudflare that might induce this error, I’m not aware of anything beyond the rate limiting that’s documented in the link you referenced. However, I will certainly reach out internally to figure out if there are any undocumented specs. 

 

If you are looking for account-specific troubleshooting, it may also be helpful to reach out to support.

 

Thanks,

Brian

 


Forum|alt.badge.img+2

Hi Brian,

 

Thanks for swift response. To answer your questions:

 

This is using the API directly, its not using an existing integration project. 

 

I have tried reducing the payload size by:

 - Using pagination and the `page[cursor]` parameter

 - Using a reduced set of fields with the `fields[profile]=email` parameter

 

Other notes:

 - We have tried both via Postman and also application scripts (using Guzzle).

 - This doesn’t appear to be an account specific issue. I setup a separate test account, and the same thing happens, both on the server and locally, and both in code and via Postman

 - I’m confident it isn’t related to the internet connection as the same occurs both locally and from the server in a different region. Ditto with Firewall

 

 

 

An example of the code being used in Guzzle / PHP

<?php

use GuzzleHttp\Pool;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;

$client = new Client();

$request = new Request(
        "GET",
        "https://a.klaviyo.com/api/profiles/?page%5Bcursor%5D=bmV4dDo6aWQ6OjAxR0tHUktENlNFWEtEUllDQUIyWldZRUNO&fields%5Bprofile%5D=email",
        [
            "Authorization" => "Klaviyo-API-Key REDACTED",
            "Revision" => "2022-10-17"
        ],
        "");

$response = $client->send($request);

// Throws error ~50% of the time
";

 

An example Postman collection that also randomly fails:

 

{
  "info": {
    "name": "utrr.paw",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "item": [
    {
      "name": "klaviyo - profiles",
      "request": {
        "method": "GET",
        "url": {
          "raw": "https://a.klaviyo.com/api/profiles/?page%5Bcursor%5D=bmV4dDo6aWQ6OjAxR0tHUktENlNFWEtEUllDQUIyWldZRUNO&fields%5Bprofile%5D=email",
          "query": [
            {
              "key": "page[cursor]",
              "value": "bmV4dDo6aWQ6OjAxR0tHUktENlNFWEtEUllDQUIyWldZRUNO",
              "disabled": false,
              "description": null
            },
            {
              "key": "fields[profile]",
              "value": "email",
              "disabled": false,
              "description": null
            }
          ],
          "protocol": "https",
          "host": [
            "a",
            "klaviyo",
            "com"
          ],
          "port": null,
          "path": [
            "api",
            "profiles"
          ]
        },
        "description": "",
        "header": [
          {
            "key": "Authorization",
            "value": "Klaviyo-API-Key REDACTED",
            "disabled": false,
            "description": null
          },
          {
            "key": "Revision",
            "value": "2022-10-17",
            "disabled": false,
            "description": null
          }
        ],
        "body": null,
        "auth": null
      },
      "protocolProfileBehavior": {
        "followRedirects": false,
        "followOriginalHttpMethod": false,
        "followAuthorizationHeader": false
      },
      "response": []
    }
  ]
}

 


Forum|alt.badge.img+2

I just want to add some timings in case you can cross check them against your logs:

  • 2022-12-16 21:38:43 AEST - 504 Gateway Timeout
  • 2022-12-16 21:41:17 AEST - 504 Gateway Timeout
  • 2022-12-16 21:45:08 AEST - 504 Gateway Timeout
  • 2022-12-16 21:47:25 AEST - 200 Success

I manually called the above 4, it wasn’t until after 3x that it worked


Forum|alt.badge.img+2

A few more tonight, let me know if these are/aren’t useful:

 

  • 2022-12-17 21:48:51 AEST - 504 Gateway Timeout
  • 2022-12-17 21:53:45 AEST - 504 Gateway Timeout
  • 2022-12-17 21:57:34 AEST - 504 Gateway Timeout
  • 2022-12-17 22:01:59 AEST - 200 Success

Again, these were all run manually via Postman. After the third, without any change to my config, paremeters, etc it started working. And continued to work for the same request a few minutes later.

 

The 504, which for Klaviyo, looks to be from Cloudflare. This typically means the server behind it isn’t responding correctly (eg: https://community.cloudflare.com/t/community-tip-fixing-error-502-504-bad-gateway/44008) .

 

The only pattern I’m seeing so far is the first “few” requests always seem to fail. I’m spit balling here, because I have no idea about your stack, but is there a chance you are having a cold start issue? Once warm, it seems to be fine.

 


Brian Turcotte
Forum|alt.badge.img+37

Hi @chris_workinggears,

 

Thank you for the valuable info! Several members of our Engineering team are looking into this issue for us now, and the thread will be updated as soon as possible.

 

Thanks again for using the Community!

 

- Brian


Brian Turcotte
Forum|alt.badge.img+37
  • Klaviyo Alum
  • 1393 replies
  • Answer
  • February 1, 2023

Hi @chris_workinggears,

 

Just wanted to give another update - there’s a lot of attention on this subject, and I see that you have a support ticket open as well. I will update the thread as soon as we know more about what the source of the issue is, so that the other Community members can also learn from this.

 

Thanks so much for being a Community member!

- Brian