Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Return the header response to check for X-RateLimit-Remaining #173

Open
jettonj opened this issue Oct 17, 2024 · 0 comments
Open

Comments

@jettonj
Copy link

jettonj commented Oct 17, 2024

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_checkIfClear(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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant