Optimizing and Transforming API Responses Effectively
Image Source: Shutterstock.com NetForce 365
Developer Tools
Oct 20, 2022 8:59 AM

Optimizing and Transforming API Responses Effectively

by HubSite 365 about Michael Megel

Enterprise Architect, Azure DevOps, Power Platform Addict, Cloud Solutions & Intelligent ERP ... Never stop learning!

Citizen DeveloperDeveloper ToolsM365 Hot News

Learn how to modify external API responses with powerful custom connectors and policies for optimal Microsoft Canvas App integration.

The blog post by Michael Megel describes the issue of when an "external API response doesn't fit your requirements." It talks about his personal experience with transforming API responses with the help of Custom connectors within a Canvas App.

Custom connectors facilitate the consumption of external APIs in Canvas Apps or Power Automate Flows. Michael discovered that the response from his API, though set up perfectly and functioning as expected, wasn't suitable for his Canvas App.

The particular issue was with a nested record provided by his connector. Since Michael wanted to display a list of his 'userFields' in a Canvas App, an unsatisfactory response led him to the idea of modifying it using a policy. For more on Developer Tools and policies, refer here.

Custom connector policies can modify connectors' behaviour during runtime. Michael decided to solve his issue by adjusting the API response with Microsoft's predefined policy template: "Convert an object to an array".

Setting Up a Custom Connector Policy

Create a new policy under the custom connectors' operations, then specify the policy's name and the template "Convert an object to an array". Select the operation to which the new policy will be applied, followed by defining the "Target object or collection path." In this instance, the path was "@body().value".

Then, the 'userFields' property needs to be treated - transformed from an object into an array. As this property should replace the original one, the new property path becomes "@item().userFields". The resultant array should consist of key-value pairs. Finally, define that the policy should run on the API response of the operation.

With the policy set up, the API response can now be manipulated as desired. Michael's 'userFields' are now in a format he can work with. A demonstrated test run resulted in a correctly transformed response.

Beginning with an API unable to meet his Canvas App's demands, Michael constructed a custom connector policy to solve his problem. Adding a policy based on a template to his custom connector, configuring the operation, defining transformation details, and specifying the policy’s execution all led to successful results. It's emphasised that custom connector policies are an extremely powerful tool, and setting one up can take as little as five minutes.

Read the full article Transforming API Responses

Developer Tools - Optimizing and Transforming API Responses Effectively

Learn about Transforming API Responses

Manipulating API responses with custom connectors provides flexible solutions to interact with external APIs in Canvas Apps or Power Automate Flows. At times, however, the external API response might not meet your requirements. There are various reasons for dissatisfaction, including incompatibility with particular calculations or presentations in a Canvas App.

In Microsoft, custom connections aid in solving this issue. In setting up a custom connector, the connector operates as expected, providing a correctly formatted response based on the schema you've defined. However, when focusing on specific details like displaying a list of custom fields, the provided nested records may not satisfy your needs.

Microsoft provides the perfect solution to these challenges – policies in custom connectors. Policies are capable of modifying the behavior of connectors at runtime. With the help of available policy templates, developers can opt to restructure their API responses.

This becomes evident through an example with an API providing an array "value", with each record in the array possessing a property "userFields." However, the "userFields" is an object, necessitating modification in the API response to fit the required format. To facilitate this, you can use the predefined policy template "Convert an object to an array".

  • Navigate to custom connectors operations - create a new policy
  • Name the policy and specify the template: "Convert an object to an array"
  • Select the operation for policy application
  • Specify the "Target object or collection path" - marks where objects can be found in the response JSON
  • Select object property to transform into array - this might include items within arrays presented as objects
  • The policies should replace the original property, generating key-value pairs arrays from the selected objects
  • Finally, implement the new policy to run on the API response

This will help you attain a correctly structured API response, transforming an unsatisfactory API response to a structured form compatible with your needs. Through this process, you create a policy based on a template, then configure the operation and transformation details. Finally, you specify when the policy should run, then save and test the custom connector.

All these steps can be executed in under 5 minutes. In summary, policies in custom connectors are powerful solutions for modifying API responses, thus satisfying your requirements when external APIs do not meet your needs.

More links on about Transforming API Responses

Transforming API requests and responses
Learn how to set up parameter mapping to modify API requests and responses for Amazon API Gateway HTTP APIs.
Setting up data transformations for REST APIs
Learn how to set up request data mappings in integration request and how to set response data mappings in integration response.


API Transformations, API Response management, Optimizing API responses, API transformation tools, Advancement API responses, API output Transformations, Transforming REST API responses, Improve API responses, API Data Transformation, Transformation in API integration.