Performance Tuning Webservices in Dynamics 365 Business Central: Apply Filters to Your Webservice Request
Webservices taking a long time to run? Reduce the size of your response and get fewer records returned by using filters in your webservice request.
Using filters ($filter) in your webservice request will reduce the number of records returned and increase the overall performance of your system and integration.
Using the $select option is a great way to remove unnecessary fields from the webservice response and reduce the payload size.
Filters are important because they allow you to identify and use the specific data you need at a specific time. Whether you need to respond to an inquiry using data or need a specific data set for a presentation, filters allow you to focus solely on what you need and cut out the noise of data that isn't relevant to what you are doing.
Below is an example using Postman and CRONUS database. In the example we limit the number of fields to two and the number of customers to only ones that start with the letter A:
https://api.businesscentral.dynamics.com/v2.0/TENANT_ID/Sandbox/api/v2.0/companies(COMPANY_GUID_ID)/customers?$select=id, displayName&$filter=startswith(displayName, 'A')
You can visit this Microsoft blog to learn more about Webservice's filter documentation.
Using Application Insights?
Application Insights is a diagnostic tool you can use to determine why your Dynamics 365 Business Central system is behaving a certain way. This can include gathering information on extensions, diagnosing a slow-down in processing, or giving you a view of the traffic and data running through your system.
In this scenario, you can use the event ID RT0008 to view incoming webservice telemetry data. You can use the sample query below to apply filters to your webservice request.
Learn more about Application Insights here.
| where timestamp > ago(60d)
| where customDimensions.aadTenantId == 'YOUR AAD ID HERE' and isnotempty( 'YOUR AAD ID HERE')
| where customDimensions.environmentName == 'YOUR ENVIRONMENT NAME HERE' and isnotempty( 'YOUR ENVIRONMENT NAME HERE')
| where customDimensions.alObjectType <> ''
| where customDimensions.eventId == "RT0008"
//| where toupper(customDimensions.category) contains "API" //Change category to filter on the web service category "API", "ODATA", "SOAP"
| extend _processingTimeMS = toreal(totimespan(customDimensions.serverExecutionTime))/10000
["Timestamp"] = timestamp,
["Category"] = toupper(customDimensions.category),
["Endpoint"] = tostring(customDimensions.endpoint),
["Object Type"] = tostring(customDimensions.alObjectType),
["Object No."] = tostring(customDimensions.alObjectId),
["Object Name"] = tostring(customDimensions.alObjectName),
["Processing Time"] = _processingTimeMS,
["Publisher"] = tostring(customDimensions.extensionPublisher),
["Extension Name"] = tostring(customDimensions.extensionName)
| sort by ["Timestamp"] desc
We have a team of Business Central experts ready to assist you! Please get in touch with us if you have any questions.