top of page
Search
  • bouhmidiasmaa

Power Automate Custom Connector to update Exchange rate automatically

Exchange Rate table is one of the most important tables in the sales module, however, to update the values in this table the users have to perform this action manually, in most cases users would like to keep this table updated on a daily basis.

In this post I will try to explain in detail how to use Power Automate to create your Custom Connector and how to use this connector to update the exchange rates automatically.


Part 1 : Create a Custom Connector

In this post we will be using the https://currencyapi.com/ to get the exchange rates in our Custom Connector, so first create a free account the currencyapi website.

Once you connect to your account make sure to copy the apikey to use it next.

Now lets start creating the custom connector in Power Automate.

  1. Open Power Automate -> Data -> Custom connectors -> New custom connector

2. On the first step, set the host to api.currencyapi.com

3. On the second step, chose API Key as the authentication method and set the parameter name to apikey

4. On the definition step, add a new action and set the fields as follow

click import from sample to define the structure of the request and fill it as follow

Verb = GET

URL = "https://api.currencyapi.com/v3/latest?apikey=YourApiKey&base_currency=USD&currencies=EUR"

click on import and delete the apikey from the generated request

5. Click on Create connector, then Test

Now your connector is ready to be used in a Flow.


Part 2 : Update Exchange Rates Automatically

In this part will be using the custom connector created previously to update exchange rates automatically on a daily basis

  1. Create a Scheduled Flow in Power Automate and set the recurrence to every day

2. Initialize an array to store the results that will be returned by our custom connector

3. Add the custom connector and set the required parameters


4. Parse the Body returned by the custom connector

Use Postman to generate the schema (click on Generate from sample and paste the body from Postman to generate your schema)

5. Add the returned currencies rate to the array created in step 2

The action used is Append to array variable

6. Get currencies to update in dynamics 365, and remove the base currency from the list as it's value is always 1 and can't be updated, in my case MAD is the base currency

and make sure to have those currencies already created on dynamics 365

7. Initialize a counter to loop on the array create and filled in step 2& step 5

8. Add an apply to each to loop on the list of currencies returned by the Get List action, and set the counter to 0 each time

9. Add a Do Until action inside the Apply to each, and set the end condition to counter is equal to the number of returned rates ( in my case three since i have chosen three currencies in my custom connector in step 3)

10. Add a condition to update each currency by the matching returned rate value

condition used is :

Expression { variables('data')[variables('counter')].code } is equal isocureencycode

the value saved in the exchange rate is :

Expression { variables('data')[variables('counter')].value }

11. Finally, increment the counter inside the Do Until action


Your final Flow should look like this

Your Flow should work perfectly


Hope you find this post useful :)

0 comments
bottom of page