One key skill you must grasp is performing actions in cloud flows by calling external APIs (Application Programming Interfaces). Why so? These APIs provide a mechanism for two applications or services to interact with each other, which is crucial in the automation process.
Microsoft Power Automate enables you to integrate and automate processes with external APIs. You create a custom connector to any publicly available API, then use this within the cloud flows as any other Microsoft Power Automate connector. This provides you with flexibility and scalability; you can integrate with virtually any service that exposes an API.
Creating a Custom Connector
The first step to call external APIs is creating a custom connector. Here’s how it’s done:
- From Power Automate, select Data from the left-hand side, then Custom connectors
- Click on the “+ New custom connector” and select “Create from blank”
- You’ll be prompted to enter a name for your connector; input the data as required.
- In the General tab, you’ll find the base URL of your API. Click on Security to set up the authentication type.
- Click on Definition, set up the operations you’ll call, their URL, verb (GET, POST), parameters, headers, and response.
- Save and Test your custom connector.
To illustrate, let’s say you’re creating a connector to GitHub API, which uses OAuth2.0 for authentication, you’d input your client ID, secret, auth and redirect URLs in the security tab.
The definition tab allows you to define actions (like ‘List Repositories’), assign verbs (like ‘Get’) and specify the API endpoint that will run this operation.
Calling the Custom Connector in a Cloud Flow
After creating the custom connector, you can now set up a cloud flow that calls it:
- From Power Automate, select “Create” and pick the type of cloud flow (instant, automated, or scheduled).
- In the cloud flow, search for your custom connector and add an action from it.
- Fill in any required fields in the action.
- Save and test your cloud flow.
In the case of our fictitious GitHub connector, you might create a scheduled cloud flow that lists all repositories you’ve starred every day.
Response Handling
The response from an API call varies; it might reflect success, failure, or request data. The “Parse JSON” action in Power Automate simplifies response handling. This ensures that response data is interpretable and usable for subsequent actions in your cloud flow.
Given the pervasive nature of APIs in contemporary app design, mastery of calling external APIs allows the creation of robust, versatile automated flows. This is a critical component of the PL-500 Microsoft Power Automate RPA Developer exam and extensive practice and application will be instrumental in acing the test.
Practice Test
True or False: In Power Automate, you can use HTTP actions to call REST APIs.
- True
- False
Answer: True.
Explanation: Power Automate provides HTTP actions feature which allows users to make HTTP calls to REST APIs.
Which of the following are valid methods of calling an external API within a cloud flow in Power Automate?
- a) HTTP actions.
- b) Using connectors.
- c) Writing a custom script.
- d) Using the Power BI connector.
Answer: a) HTTP actions, b) Using connectors.
Explanation: In Power Automate, HTTP actions and using connectors are two valid methods to call an external API within a cloud flow. The other options are not valid methods within Power Automate.
True or False: You cannot pass parameters to an API in a cloud flow.
- True
- False
Answer: False.
Explanation: You can pass parameters to an API in a cloud flow using either a GET or POST request.
Multiple Select: What are the primary components of an HTTP request action in cloud flows?
- a) URL
- b) HTTP Method
- c) Headers
- d) Subnet Mask
Answer: a) URL, b) HTTP Method, c) Headers.
Explanation: The URL, HTTP method and headers are the primary components of an HTTP request action in a cloud flow. Subnet Mask is not related to HTTP request action.
True or False: All external APIs can be used with Power Automate.
- True
- False
Answer: False.
Explanation: Only those external APIs can be used with Power Automate that support RESTful operations and are HTTP or HTTPS based.
Which of these actions can be performed using Power Automate?
- a) Create and delete records in a CRM system through an API.
- b) Get data from a machine learning model through an API.
- c) Control IoT devices through an API.
- d) All of the above.
Answer: d) All of the above.
Explanation: All these actions can be performed by calling appropriate APIs within Power Automate.
True or False: The API key is typically required in the header for authenticating an API request.
- True
- False
Answer: True.
Explanation: The API key is often used for authentication and is typically included in the header of the API request.
What HTTP method should be used while performing a create operation via API in Power Automate?
- a) GET
- b) POST
- c) DELETE
- d) PATCH
Answer: b) POST
Explanation: The POST method is typically used in HTTP for sending data to create new resources.
True or False: The API response is always in JSON format in Power Automate.
- True
- False
Answer: False.
Explanation: The API may response in any format, not just JSON. However, JSON is a common response format from RESTful APIs.
Which of the following property in Power Automate is used to parse the content of the HTTP response?
- a) Body
- b) Headers
- c) Parse JSON
- d) Post a reply
Answer: c) Parse JSON
Explanation: The Parse JSON action is used in Power Automate to parse the content of HTTP responses.
Interview Questions
What is the purpose of calling external APIs in cloud flows?
Calling external APIs allows the automation of cloud flows to interact with external systems and services. It helps in retrieving, inserting, or updating data on these platforms.
How do you add an action to call an API in a cloud flow in Power Automate?
You can add an action to call an API by selecting “New step” > “Custom” > “HTTP” from the flow designer, then specifying the method, URI, headers, and body based on the API you’re integrating.
What is the HTTP action in Power Automate used for?
The HTTP action in Power Automate is used to make outbound HTTP calls to RESTful services and interact with endpoints that expose APIs, enabling you to call external APIs within your flows.
What does a POST method in an HTTP request indicate in Power Automate?
A POST method in an HTTP request is used to send data to a server to create/update a resource in external APIs while using Power Automate.
In Power Automate, what input does the HTTP action need to call an external API?
The HTTP action needs certain inputs like method type (GET, POST, PATCH, etc.), Uri (Endpoint of the API server), Headers (Content-Type, Authorization, etc.), and Body (Data to send if required).
How do you handle API response in Power Automate?
API response in Power Automate can be handled using the “Parse JSON” action, which reads and extracts data from the JSON response.
What is the role of authentication while calling an external API in Power Automate?
Authentication is significant in validating the identity and access permissions of the API caller. API calls often require credentials, API keys, or tokens provided in the headers for security reasons.
How can you specify query parameters while calling an API in Power Automate?
Query parameters can be specified directly in the URL or in the “Queries” section of the “HTTP” action while calling an API in Power Automate.
What does the ‘Parse JSON’ action do in Power Automate?
The ‘Parse JSON’ action is used to parse the JSON response from the API queries. It extracts the required data from the result to be used later in the flow.
What does the status code tell you about an API request in Power Automate?
The status code provides information about the result of an API request. For example, 200 indicates a successful request, while 404 indicates the requested resource couldn’t be found.
What is the use of Expression tab in Power Automate?
The Expression tab in Power Automate is used to write complex expressions in a flow. This can include calculations, data manipulations, and accessing system parameters like timestamps and flow details.
How do you handle errors during API calls in Power Automate?
Errors during API calls can be identified using the “configure run after” setting in Power Automate. It allows execution of certain steps only if others have failed or have been skipped.
How do you pass a header while calling an API in Power Automate?
Headers can be passed in the HTTP action in Power Automate. In the “Headers” field, you can specify the header name and its corresponding value.
Where do you get an access token for authentication while calling an API?
An access token is usually obtained after the user has authenticated themselves with the API server. This token is then used in the headers for subsequent API requests.
Can Power Automate call an external API that requires Bearer Token Authentication?
Yes, Power Automate can call an external API that requires Bearer Token Authentication. The token can be included in the Authorization header within the HTTP action.