Consume Any API from Power Automate

What is an API

“Application Programming Interface” is the meaning of API. API is the middle of two applications and allows them to communicate. In other words, API is the messenger that delivers the request from the requestor to the provider that you’re requesting it from and then delivers the response back.

Why do we need APIs with Power Automate?

There are plenty of connectors available in Power Automate for different Microsoft and third-party services.

But sometimes, the connector you need doesn’t exist, or it doesn’t have the correct actions available. APIs expand the possibilities of Power Automate, so knowing how to use one is a valuable skill for any citizen developer.

HTTP request structure

A lot of APIs have documentations online. And this makes it easy to use them in PowerApps. But in case API documentation is not found, the basic structure for API call is:

  • Host, base URL, and base path
  • Endpoints
  • Requests and responses
  • Methods
  • JSON

To make an API call in power automate, we are using an “HTTP” request.

Power Automate API consumption workflow automation

REST API requests are made up of raw HTTP Method, Endpoint, including Headers, and the Body.

  • HTTP Method: HTTP defines a set of request methods to indicate the desired action to be performed for a given resource. These are the most common methods: POST, GET, PUT, PATCH, and DELETE.
  • URI– REST APIs use URIs to address resources. For APIs, an endpoint can include a URL of a server or service. Each endpoint is the location from which APIs can access the resources they need to carry out their function.
  • Headers – Headers are an important part of the API request and response as they represent the meta-data associated with the API request and response.
  • Request and Response Body – APIs work using “requests” and “responses”. In our example, we will provide a request body in JSON to the REST API call.

Use case

API call can connect this party tool in Power Automate. Also, it allows you to do some tasks in Microsoft products as well.

** Microsoft provides an amazing tool to try out Microsoft Graph APIs, it’s the Graph Explorer.

Here we will use: Post Tab in Teams channel graph API to create a tab that contains a URL in teams channel.

To prepare to work on this, a pre-requisite is to create an Azure AD App by giving the Application permissions required for Add Tabs to Channel API following these steps:

1.  Go to portal.azure.com and log in

2. Click app registrations

3. Click New App registration

4. Give your app a nice name

5. Save tenant ID and Client(app) ID somewhere (notepad or similar)

6. Click API PERMISSIONS and select Microsoft Graph

7. Now look up the permissions needed for this action

8. Now look up the permissions needed for this action: [Add tabs to a channel(https://docs.microsoft.com/en-us/graph/api/channel-post-tabs?view=graph-rest-1.0):

Permission type: Application

Permissions: TeamsTab.Create.Group*, TeamsTab.Create, TeamsTab.ReadWriteForTeam.All, TeamsTab.ReadWrite.All, Group.ReadWrite.All, Directory.ReadWrite.All

9. Select all these permissions

10. Grant Admin consent

11. Click Certificates & secrets

12. Click New client secret

13. Type in a description

14. Click Add

15. Copy the value and save it in your notepad (you will need that later)

Actual Flow:

Make the flow manually starting with these variables:

1. Team Name

2. Channel Name

3. URL of the tab

4. And App data from Azure:  Client ID, Client Secrete, Tenant ID

5. Get the team

6. Then get all channels

Power Automate API consumption workflow automation

The last step in the HTTP request is to post the Tab. As below:

Power Automate API consumption workflow automation

The Power Automate flow is now ready to test. Click on Test and select Manually as we have added a Manual trigger for the flow to run. Once the Flow runs, you will see a new tab added to your Teams General Channel.

HTTP requests are a superb method to achieve a lot of things that are not ready for user actions in Power Automate but can still be executed using Microsoft Graph or other Open APIs

Visit our blog To learn more about Power Platform.

Contact us to help you automate your business!