Use FetchXML in WEB API using Power Automate with HTTP action for Dataverse and Dynamics 365
In Business scenarios we sometimes require to use Fetch XML to read data from Dataverse or Dynamics 365 CE. In this post you will come to know how to use Fetch XML in HTTP action of Power Automate and call Dataverse or Dynamics 365 Web API end point.
Follow below steps.
Step 1: Prepare Fetch XML
First build the fetch XML and download and keep it ready. The below sample fetch XML shows reading accounts from dynamics 365 CE.
<fetch mapping="logical">
<entity name="account">
<attribute name="accountid" />
<attribute name="name" />
<attribute name="industrycode" />
<order attribute="name" />
</entity>
</fetch>
Step 2: Encode the Fetch XML for URL
Go to https://meyerweb.com/eric/tools/dencoder/ and paste the fetch XML inside the textbox and click encode. This will generate the encoded URL version of the fetch XML.
After encode it will generate the below code.
%3Cfetch%20mapping%3D%22logical%22%3E%20%20%0A%20%3Centity%20name%3D%22account%22%3E%20%20%0A%20%20%3Cattribute%20name%3D%22accountid%22%20%2F%3E%20%20%0A%20%20%3Cattribute%20name%3D%22name%22%20%2F%3E%20%20%0A%20%20%3Cattribute%20name%3D%22industrycode%22%20%2F%3E%20%20%0A%20%3Corder%20attribute%3D%22name%22%20%2F%3E%20%20%0A%20%3C%2Fentity%3E%20%20%0A%3C%2Ffetch%3E
Copy the encoded string and keep it.
Step 3: In Power Automate use the string in fetchXml query.
Open power automate add an instant trigger. You can add any trigger of your choice. Add new action called HTTP and use Get method and in URI, give the environment URL with entity set. Add headers as given below.
- Content-Type : application/json
- OData-MaxVersion : 4.0
- OData-Version : 4.0
- Prefer: odata.include-annotations=”*”
In the Query section add the encoded fetch Xml.
Now if you run the Power Automate it will show result.
When you click to download link from Output section it will give the result.
You can parse the JSON result and use it in next steps.
hope this helps
Follow my blog for more trending topics on Dynamics 365, Azure, C#, Power Portals and Power Platform. For training, Courses and consulting, call to us at +91 832 886 5778 I am working more for community to share skills in Dynamics 365 and Power Platform. Please support me by subscribing my YouTube Channel. My YouTube Channel link is this : https://www.youtube.com/user/sppmaestro