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".
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
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".
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.
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.