How to read X-RateLimit-NearLimit header in the response from Jira Cloud REST API?

Hi,
I need to send many requests to fetch some issues from Jira. I occasionally get responses with 429 status-code from Jira Cloud REST API. I have read in https://developer.atlassian.com/cloud/jira/platform/rate-limiting/ that x-ratelimit-nearlimit header is added to the responses when less than 20% budget for calls remain. However, when I send requests with @forge/bridge’s requestJira method and try to read this header from the response, it is null. How can I read this header? Below, you can find how I try to read it.
Best regards,
Odin

const response = await requestJira("...");
const isNearLimit = response.headers["x-ratelimit-nearlimit"]; // isNearLimit is undefined for me.
1 Like

@OdinSon,

According to the Fetch API spec, headers is not a normal object that you can index into. You have to get(name). Fortunately, the spec also says “The name is case-insensitive.”

I’ll admit I haven’t tried this as I don’t have any expensive requests handy. But I’m counting on the Atlassian Forge polyfill for Fetch being compliant with the spec.

1 Like

Hi,
Thank you @ibuchanan . I tried this as well, however it returns always null for x-ratelimit-nearlimit header. This is the code snippet I am using:

const response = await requestJira(
                `/rest/api/3/search?startAt=${startAt}&maxResults=${maxResults}&fields=${fields}&jql=${dataJQL}&`,
                {
                    headers: {
                        Accept: "application/json",
                    }
                }
            );
            if (!response.ok && response.status === 429) {
                throw new Error("Request has been rate limited")
            }
            console.error("X rate limited header: " + response.headers.get("x-ratelimit-nearlimit"));
1 Like