Jump to content

API calls

From Resco's Wiki

An application programming interface (API) is a communication protocol or interface between client and server computers. When a client device requests data from the server, this is called an API call.

In our environment, Resco uses API calls to request data from the CRM server. Growing number of CRM server providers restrict the number of API calls per time period, or have pricing related to this number. Therefore, it becomes increasingly important to understand how and when Resco Mobile CRM talks to the CRM server. Fortunately, careful setup of your app project can help you optimize the number of API calls.

Dynamics limits (as of October 2019)

User license # API requests / 24 hr
D365 Enterprise apps 20,000
D365 Professional 10,000
D365 Team Member 5,000
etc. (more plans exist)

From the perspective of Resco Mobile CRM app, practically all server calls count:

  • All CRUD operations, share, assign.
  • From any client/app, using SOAP/REST endpoints.

Important: Implied API calls issued by server plugins, (async) workflows etc. are counted, too.

Only a handful calls are ignored (do not count for the limit)

  • login/logout
  • getClientMetadata

Exceeding request capacity

What happens if any user exceeds the licensed request capacity? The current policy is that end users are not be blocked from using the app for occasional and reasonable over-consumption at this point of time. Dynamics admins are notified and they can assign PowerApps and Microsoft Flow request capacity to that user.

All existing customers have a transition period until October 1, 2020 or the expiration of their current subscription term, whichever is longer. During this period, customers gain access to Reporting (part of Power Platform Admin Center) that shows the API consumption.

Estimating API calls

The following formulas can give you an estimate of API calls made during the synchronization and online mode. Only the communication with Dynamics server is counted. Calls to SharePoint/Exchange, etc., are not subject of any limit.

Full synchronization

Add the following numbers together to receive a rough estimate of API calls needed to perform a full synchronization in your project. Round up.

  • ~15 for preparation phase (without new customization)
  • number of entities / 2
  • number of records / fetch_page_size
  • number of NN records / 2000
  • number of ActivityParty records / 2000
  • number of attachments
  • number of images
  • 1 (if audit is used)

Incremental synchronization

Add the following numbers together to receive a rough estimate of API calls needed to perform an incremental synchronization in your project. Round up.

  • ~11 for preparation phase (Same as for FullSync except permissions are loaded only at 1st sync after AppStart)
  • +1 (DeletePlugin)
  • number of changed entities (for uploader; see also comment below)
  • number of entities * 1.2 (SyncAnalyzer + downloader)
  • number of NN entities

Note for uploader: This maybe sound like a low number, but it is usually correct. However, there are some cases when uploader is quite costly:

  • If you have many local changes (default batchsize=100) - this is typically the case for Inspections
  • Every upload problem costs extra API calls (upload retries, conflict resolution...)
  • Status changes cost extra calls

Online mode

All API calls go through online request queue. (They are serialized!)

Any serious work in online mode will sooner or later consume more API calls than sync. This is valid even for full synchronization of huge app projects. Why? Lot of actions generate several API calls. Extreme example: opening of a single complex form with several related / unrelated lists in online mode can take more than 40 API calls.

Views

  • Open: 2 calls
  • Browse: 2 calls / page (~50 items)

Forms

  • Load: 2-50+ calls/form
  • Save: 1 or more calls

Recommendations

Install newest release of Resco Mobile CRM app. Its sync log contains API call statistics in the following format:

<ApiCalls Prepare='...' Uploader='...' SyncAnalyzer='...' Downloader='...' Images='...' Total='1234' />

The value listed in Total attribute represents the total number of API calls made during the synchronization.

Notes:

  • These numbers are not reliable in case of Salesforce/RescoXRM servers. ((This will be corrected in v12.3 release.)
  • API calls issued by MCRM may induce additional API calls made by Server plugins. (This mainly concerns sync Uploader or Save operation in Online mode.)
  • MCRM has no chance to know about these extra calls, but you should take them into consideration when making API calls estimates.

Below are some maxims how to minimize API calls number.

Online mode
  • Do not use New UI (Then the tabs are loaded on demand.)
Synchronization
  • Use large fetch page size (Advanced sync setup):
    • By default 500 records = 1 API call.
    • Using page size 5000 (maximum) decreases the number of API calls to one tenth. However, larger page size may result in lower app responsiveness and requires more memory.
  • Decrease number of downloaded attachments (1 attachment = 1 API call)
  • Minimize data downloaded by the client
  • Avoid useless downloads:
    • All records that are deleted in the FullSync cleanup need not be downloaded at all.
  • SyncAnalyzer:
    • Dynamics/RescoXRM: If you are sure you don't need this module, switch it off. You might save ~O(numEntities/10) API calls during IncSync.
    • Salesforce: SyncAnalyzer saves a lot of API calls during IncSync. (Due to batching several requests into one API call.)
Automatic synchronization
  • Do not overuse. Normal IncSync takes ~50-100 API calls.