Checking for X-RateLimit-Remaining with js-webflow-api

I’ll start off with a disclaimer that I come from an embedded background and that I’m not very familiar with JS or HTTP.

I’m working on updating our Webflow API to version 2, and while I was able to get it working I can’t seem to understand how to check for rate limiting before receiving a 429 error. We used to check the _meta field in what was returned from the api call to get the rate limit info from data that looked like this.

{
  _cid: 'abcd7f0fb270752970f76ece',
  _id: 'abcd65974412c6af99a9dfeb',
  _draft: false,
  _archived: false,
  name: 'building #507',
  slug: 'building-507',
  'updated-on': '2024-10-10T21:16:38.869Z',
  'updated-by': 'Person_62bb',
  'created-on': '2024-09-25T19:33:43.123Z',
  'created-by': 'Person_62bb',
  'published-on': '2024-09-25T19:48:35.993Z',
  'published-by': 'Collaborator_66d7',
  _meta: { rateLimit: { limit: 120, remaining: 111 } }
}

However, now the v2 API mentions that X-RateLimit-Remaining should be checked in the header, but I think I’m only receiving the body from the API call. Is there a different way I should be calling the js API functions?
Right now they look like this, in general.

const WF_getEntry = async (webflow, listingId, itemId) => {
	const it = await webflow.collections.items.getItem(listingId, itemId);
	await WF_checkIfClearv2(it);
	return it;
}

Looking at .collections.items.getItem() it looks like only the body gets passed,

if (_response.ok) {
    return serializers.Sites.parseOrThrow(_response.body, {
        unrecognizedObjectKeys: "passthrough",
        allowUnrecognizedUnionMembers: true,
        allowUnrecognizedEnumValues: true,
        skipValidation: true,
        breadcrumbsPrefix: ["response"],
    });
}

Is there a way I can use the js API and still receive the headers, or otherwise respect the rate limit?

Hey @jettonj - thanks for raising this! This is most likely a limitation on the SDK. Two things I’d recommend:

  • Call the API directly with your HTTP client of preference so you can see the headers for endpoints where you want to check this
  • If you get a chance, would love if you could log this issue on the Github repo as well! When we do have an answer for getting these relevant headers, we’ll make sure to raise the new version that has a solution so you can get notified

Got it, I’ll probably just try to call them directly with fetch. And yeah I can add an issue. Thanks!

1 Like