12

According to the documentation, the Salesforce REST API returns a Limit Info Header with each request. So each REST API call gets a Sforce-Limit-Info: api-usage=18/5000 line returned in the response header.

When I make a call to a custom Apex REST API endpoint, this header is not automatically included in the response. The only other way I can find to programmatically determine the limit for an organization is to ping the /limits REST endpoint. But, according to a SF employee:

This feature is still in pilot mode, and just "might" become generally available with the winter 15 release (november).

So if Sforce-Limit-Info isn't being returned in the header, and /limits endpoint isn't in production yet, how can my custom APEX REST endpoint programmatically determine the limits for the authorized organization today, and, how many requests have been made towards those limits?

It doesn't solve the issue, but what would be great/helpful is if Salesforce added a daily_limit return parameter to the OAuth connection so you at least know the organizations max daily usage at the time you authorize them.

4
  • Unfortunately I do not see any way for you to get the limit via apex so setting a header to return the value could not be done. Until they expose a way to get the value I do not believe it is possible without consuming another api call to do so.
    – Eric
    Aug 23, 2014 at 18:44
  • @Eric Even if I wanted to consume another API call, what call would I make? Aug 24, 2014 at 0:55
  • I may have mistyped my thought. I do not think there is currently a way to get it. I am sure if there is a way someone will post it..
    – Eric
    Aug 24, 2014 at 2:28
  • Amazing that in 2020 we're still in the same situation
    – zaitsman
    May 22, 2020 at 12:33

2 Answers 2

2

Well, you could make a Force.com REST call after your custom call. Something like a trivial select. This is not an efficient solution. It will increase the speed at which you use up calls and will slow down whatever is consuming this info as it now needs to call your custom endpoint, then this trivial one as well. I will continue to research since this is a bucket of nope but it does get you the information you are looking for.

2
  • While not efficient, it at least gives me an idea of what the organization max limit is. Ping it each day, or something like that, and then I can at least try and keep a rough estimate of the API calls used on my server side. Aug 26, 2014 at 23:22
  • @John Yep, I am just a bit surprised that the usualy comprehensive Limits class doesn't mention a word of the api limits. I would have thought that Limits class + RestResponse.headers would have knocked it out of the park. C'est la vie I suppose Aug 26, 2014 at 23:27
1

I would create a static method which puts all needed information to header.

RestContext.response.addHeader(REST_Manager.ERROR_MESSAGE_HEADER_NAME, errorMessage);

In this way you can put all needed limits.

RestContext.response.addHeader(CIO_REST_Toolbox.DML_STATEMENTS_HEADER_NAME, Limits.getDMLStatements());

And then extract values on your application by getting data from response header.

This method can be included in needed REST services in the end of the REST method.

Edit.

Please, check this API Usage Limits. Particularly, I'm referring to

You can configure your organization so that email is sent to a designated user when the number of API requests has exceeded a specified percentage of the limit. You can perform this configuration in from Setup by clicking Monitoring | API Usage Notifications.

I totally understand, that this is not what you wanted; but this is the only way right to be notified about API Limits.

2

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .