planningcenter / developers

Planning Center API docs and support
https://developer.planning.center/docs/
85 stars 8 forks source link

Rate Limit - How to Add Headers using Qlik REST Connector to PCO #940

Closed DrBTheAshbeauty closed 2 years ago

DrBTheAshbeauty commented 2 years ago

Related Product Which product is this question related to? People or Services

Describe the question How do I add REST Connector headers to avoid getting 429 error for https://api.planningcenteronline.com/people/v2/people endpoint? I am using Next URL pagination and have tried adding Headers with the 3 Header names and values given in the response headers.

What have you tried that worked? I have only had this to be successful when trying it late at night or early morning, but as soon as I go in to reload - I hit the 429 error no matter what I values I put in the headers.

What have you tried that didn't work? X-PCO-API-Request-Rate-Count = 7 X-PCO-API-Request-Rate-Limit = 100 X-PCO-API-Request-Rate-Period = 20

Additional context

image

The following error occurred: (Connector error: HTTP protocol error 429 (Too Many Requests):

{"errors":[{"code":"429","title":"Too May Requests","detail":"Rate limit exceeded: 101 of 100 requests per 20 seconds"}]})

I have..

kylemellander commented 2 years ago

Hi @DrBTheAshbeauty, thanks for your issue. From what it looks like, it looks like you are hitting a rate limit for the usage of the API. Is your issue that you believe that the rate limit is being hit in error?

One thing to note is that the rate limit does not relate solely to the usage of this endpoint. If you have other applications/implementations that are making other requests to the API, then you can also hit the rate limit from your requests.

If you are trying to add headers to avoid hitting the rate limit, then that is not possible, as the rate limit is internally tracked and cannot be manipulated by the user (other than to use the API less frequently).

DrBTheAshbeauty commented 2 years ago

Hi @kylemellander - thank you for this response. Maybe I misunderstood the PCO documentation which I was attempting to comply with " If you think your app may be affected by rate limits, it should be developed to adjust dynamically inspecting the values of X-PCO-API-Request-Rate-Limit and X-PCO-API-Request-Rate-Period in the HTTP headers." I have been requesting and downloading daily exports of our data from People and Services for years and was hoping to replace that practice by setting up an API to our PCO data that would refresh/reload itself daily. I have yet to be successful at making this happen. I am new at using API's so perhaps I'm not envisioning correctly what the API can do for us? or am I on the right path to live connectivity to real-time data?

kylemellander commented 2 years ago

You should be able to grab the data that you are looking for, but I would suggest that you evaluate how frequently you make the request. It is possible that the client you are using is firing off the request more frequently than you want it to. With your rate limit, you are limited to 100 requests every 20 seconds, so if you are grabbing lots of information, you might need to add some timeouts to wait so that you don't go over your data limit.

If you do want "live connectivity", it is important to limit how often the data refreshes. For most data that lives on your system, you might not need to update it very frequently, and limiting those refreshes will help to prevent data limit overages.

I'm going to close this ticket for now, but feel free to ask any more questions that you might have.

DrBTheAshbeauty commented 2 years ago

If I have 5000 records in People when I try to Get that data - what counts as a "request" ? each record?

kylemellander commented 2 years ago

If you make a request to grab 25 people per page (which is the default), then that would be 5000 / 25 = 200 requests.

DrBTheAshbeauty commented 2 years ago

Ok. Got it. Thanks.