Retrieve Salesforce Daily Api Requests limit
Asked Answered
M

3

5

Does anyone know how to retrieve the SFDC daily requests api limit through SOAP or REST ? I don't see any call for this. Currently I have to access this info at the Company Info page. I would like to retrieve this info at code level for batch processing.

Thanks!

Monaghan answered 10/2, 2012 at 0:40 Comment(0)
J
3

We are using custom code to workaround this:

WebService static string GetAPIUsage() {
    PageReference pr = new PageReference('/00D20000000HsCQ');//use id of setup page
    pr.setRedirect(false);
    String result = pr.getContent().toString();
    Integer start_index = result.indexOf('API Requests, Last 24 Hours', 1) + 52;
    Integer end_index = result.indexOf('<', start_index);
    result = result.substring(start_index, end_index);
    result = result.replaceAll('&nbsp;', ' ');
    return result;     
}

Hope that helps.

Regards, Łukasz

Jovia answered 21/2, 2012 at 9:33 Comment(1)
thanks for your suggestion Lukasz ! I'll play with this. Regards,Monaghan
L
4

This info was not exposed in the API.

As of Salesforce Spring '15 and REST API version 29.0, the /limits resource can be used to retrieve this info. https://developer.salesforce.com/releases/release/Spring15/restapi

Also, the Sforce-Limit-Info header is returned with every REST response.

https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/headers_api_usage.htm

Looney answered 10/2, 2012 at 4:2 Comment(2)
Is it entirely unfeasible to count the number of requests you've made in a given 24 hour period on the client side? Not particularly elegant but sounds like it may be your only choice.Schellens
yea currently we have to monitor this api limit using SFDC alert system (ex: api approaching 80% limit). I wish SFDC implement such call in the api or if anyone know of any workaround would be nice to retrieve this info from code. Thanks.Monaghan
J
3

We are using custom code to workaround this:

WebService static string GetAPIUsage() {
    PageReference pr = new PageReference('/00D20000000HsCQ');//use id of setup page
    pr.setRedirect(false);
    String result = pr.getContent().toString();
    Integer start_index = result.indexOf('API Requests, Last 24 Hours', 1) + 52;
    Integer end_index = result.indexOf('<', start_index);
    result = result.substring(start_index, end_index);
    result = result.replaceAll('&nbsp;', ' ');
    return result;     
}

Hope that helps.

Regards, Łukasz

Jovia answered 21/2, 2012 at 9:33 Comment(1)
thanks for your suggestion Lukasz ! I'll play with this. Regards,Monaghan
S
2

I used REST API. Choose an HTTP method GET to perform on the REST API service URI: "/services/data/v31.0/limits". It allows me to get DailyApiRequests data.

It returns:

{ "ConcurrentAsyncGetReportInstances" : { "Remaining" : 200, "Max" : 200 }, "ConcurrentSyncReportRuns" : { "Remaining" : 20, "Max" : 20 }, "DailyApiRequests" : { "Remaining" : 14995, "Max" : 15000 }, "DailyAsyncApexExecutions" : { "Remaining" : 250000, "Max" : 250000 }, "DailyBulkApiRequests" : { "Remaining" : 5000, "Max" : 5000 }, "DailyStreamingApiEvents" : { "Remaining" : 10000, "Max" : 10000 }, "DailyWorkflowEmails" : { "Remaining" : 390, "Max" : 390 }, "DataStorageMB" : { "Remaining" : 5, "Max" : 5 }, "FileStorageMB" : { "Remaining" : 20, "Max" : 20 }, "HourlyAsyncReportRuns" : { "Remaining" : 1200, "Max" : 1200 }, "HourlyDashboardRefreshes" : { "Remaining" : 200, "Max" : 200 }, "HourlyDashboardResults" : { "Remaining" : 5000, "Max" : 5000 }, "HourlyDashboardStatuses" : { "Remaining" : 999999999, "Max" : 999999999 }, "HourlySyncReportRuns" : { "Remaining" : 500, "Max" : 500 }, "HourlyTimeBasedWorkflow" : { "Remaining" : 50, "Max" : 50 }, "MassEmail" : { "Remaining" : 10, "Max" : 10 }, "SingleEmail" : { "Remaining" : 15, "Max" : 15 }, "StreamingApiConcurrentClients" : { "Remaining" : 20, "Max" : 20 } }

Spragens answered 24/11, 2014 at 10:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.