Skip to main content
Solved

Requests are getting throttled even after having manual timeouts


Zolo
Contributor I
Forum|alt.badge.img+2
  • Contributor I
  • 2 replies

Hi all, 

I’m using the Typescript SDK to access the /api/metric-aggregates endpoint with the following retry options: 

const retryOptions = new RetryOptions({numOfAttempts: 3, timeMultiple: 10, startingDelay: 3000});

and getting this 429 response: 

[
  {
    id: 'd63b76c7-2457-40dd-9129-b8777253c5bd',
    status: 429,
    code: 'throttled',
    title: 'Request was throttled.',
    detail: 'Request was throttled. Expected available in 1 second.',
    source: { pointer: '/data' },
    links: {
      type: 'https://developers.klaviyo.com/en/docs/rate_limits_and_error_handling#rate-limits'
    },
    meta: {}
  }
]

The doc says: 

When you hit the error, those headers are replaced with a Retry-After header that returns an int indicating the number of seconds before you can start making requests.

But when I actually retry well after the given seconds, it’s still happening. Here’s the sample code: 

try {
  const response = await metricsApi.queryMetricAggregates(queryData);
} catch (error) {
  if (error.response.status === 429) {
    const retryAfterMs = error.response.headers['retry-after'] * 5000 || 5000
    const wait = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));
    await wait(retryAfterMs);
    const response = await metricsApi.queryMetricAggregates(queryData);
  }
  throw new Error ('Could not query metric aggreages from Klaviyo ' + error.message)
}

Is there something I’m doing wrong?

Best answer by Zolo

Brian Turcotte wrote:

Hi @Zolo!

My apologies for the delay here! Is this still happening for you?

 

Best,

Brian

Hi @Brian Turcotte

Thanks for the (much awaited 😅) reply. I’ve resolved the issue. There was a bug on our side 🙃

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

2 replies

Brian Turcotte
Forum|alt.badge.img+37

Hi @Zolo!

My apologies for the delay here! Is this still happening for you?

 

Best,

Brian


Zolo
Contributor I
Forum|alt.badge.img+2
  • Author
  • Contributor I
  • 2 replies
  • Answer
  • May 31, 2024
Brian Turcotte wrote:

Hi @Zolo!

My apologies for the delay here! Is this still happening for you?

 

Best,

Brian

Hi @Brian Turcotte

Thanks for the (much awaited 😅) reply. I’ve resolved the issue. There was a bug on our side 🙃