This guide shows a basic example of how to fetch an access token from MYP API using Power Automate and then get a list of Staff, which can then be sent to Power BI or used for other Power Automate flows.
Security
We highly recommend to handle secrets and tokens securely, as sharing Power Automate flows can also share those secrets if not handles securely.
The best practice for working with client secrets and access tokens is to
- Fetch client id and secret from Key Vault
- Set the ‘Secure Outputs’ setting to ‘On’ to hide the client id, secret and access token
For more details about how to create secure Power Automate flows, see the following link:
https://learn.microsoft.com/en-us/power-automate/how-tos-use-sensitive-input
Example flow
This article goes through the steps of how to create the following flow as an example of how to call MYP API and update a data source in Power BI.
Get client credentials from Azure Key Vault
To walk through how to create a secret in Key Vault, please see the following example:
https://learn.microsoft.com/en-us/connectors/keyvault/
Create actions to fetch client id and client secret from Azure Key Vault
For each action to get client id and secret, click on the 3 dots, then click Settings
In the settings for each of the actions, set ‘Secure Outputs’ to ‘On’. This will hide the client id and secret in the response.
Get access token
When creating a flow in Power Automate, first add a HTTP action and set it up the same as in this image:
Method |
POST |
URI |
https://identity.mypcorp.com/connect/token |
Headers |
Content-Type: application/x-www-form-urlencoded |
Body |
grant_type=client_credentials |
Authentication |
Basic |
Username |
{ClientId variable from KeyVault} |
Password |
{ClientSecret variable from KeyVault} |
Next, click on the 3 dots for ‘Get Access Token’ action, then click Settings
In the settings, set ‘Secure Outputs’ to ‘On’. This will hide the access token in the response.
Parse access token
Once the token has been fetched, it needs to be parsed for Power Automate.
To get the Schema, click on ‘Generate from sample’ button and parse the body response from previous step and Power Automate will automatically generate a JSON schema.
Call GET Staff endpoint
To call an endpoint such as Staff, create a new HTTP action and use the access token from previous steps as authentication, as illustrated in the following image.