Error 429 too many requests

I have seen several responses to this problem but not exactly sure how to fix it. Where do I set the Limited Request Rate to 1? When I step through my code the error does not occur since I suppose I don’t exceed the 7 per minute rate?

Hey @Mtnbiker88,

When using the Notehub API you should only get 429 errors if you try to invoke the API more than 7 times in one minute.

If you need to do invoke the API more frequently you either have to rate limit your calls, or reach out to us about custom pricing.

Can I ask which APIs you’re working with? There might be a different approach you could take to avoid running into rate-limit problems.

TJ

Hi TJ,

Thanks for your support. As I mentioned in another response, I am accessing hundreds of sensors across the US. I read them all at program startup and every hour to update my GIS map. I am trying to read approx 30 sensors with Blues comms via a web-based API, see below. My code immediately runs into the 7 per minute limit (no one else has those kinds of limits).

public static async Task GetBluesDataAsync()
{
//Convert start and enddates to epoch time (unix time in milliseconds)
DateTime startDate, endDate;
DateTime.TryParse(SensorComms.start_date, out startDate);
int dtStartEpochTimeSecs = EpochExtensions.ToUnix(startDate.ToUniversalTime());
string dtStartEpochTimeStr = dtStartEpochTimeSecs.ToString();
DateTime.TryParse(SensorComms.end_date, out endDate);
int dtEndEpochTimeSecs = EpochExtensions.ToUnix(endDate.ToUniversalTime());
string dtEndEpochTimeStr = dtEndEpochTimeSecs.ToString();

string urlString = "https://api.notefile.net/v1/projects/" + BluesAuthorization.ProjectUID + "/events?deviceUID=" + SensorComms.device_id +
    "&startDate=" + dtStartEpochTimeStr + "&endDate=" + dtEndEpochTimeStr + "&dataType=captured"; 
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, urlString);
request = new HttpRequestMessage(HttpMethod.Get, urlString);
request.Headers.Add("Authorization", "Bearer " + BluesAuthorization.AccessToken);
HttpResponseMessage response = await BluesAuthorization.Client.SendAsync(request);
response.EnsureSuccessStatusCode();
string responseBody = await response.Content.ReadAsStringAsync(); 

return responseBody;

}

Hi @Mtnbiker88,

It looks like you are pulling in event data on a device-by-device basis, which is fine, but if you have a lot of distinct devices you will quickly run into a rate limit. Another option would be to pull in all events from your project or put your devices into one or more fleets and then get all events from your fleet.

Either way, this will reduce your API calls dramatically, though it does then require you to parse out the data from the individual devices in your web API.

Thanks,
Rob

Thanks, Rob, for the response. That does require some restructuring of the way I handle the Blues sensors but is doable I suppose. I query each sensor based on the last date of a successful reading stored in my database (since some sensors go offline, fail to send a package, or don’t send data at the same time), and so each query has its own start and end date. Our sensors with Blues comms are all above 9,000 ft elevation in the high mountains…

Just curious, why the limit? Is there another way around that?

I just put in a Thread.Sleep(8600) after each reading to not exceed 7 per minute, that’s fine. Again thanks…