๐น Connecting to APIs using Custom Connectors in Power Apps โ A Complete Guide
๐ Introduction
Custom Connectors in Power Apps and Power Automate allow you to integrate external APIs and interact with third-party services that do not have prebuilt connectors. By using Custom Connectors, you can extend Power Apps’ functionality to fetch, post, update, and delete data from external sources.
๐น Step 1: Prerequisites
Before creating a Custom Connector, ensure the following:
โ
You have access to Power Apps and Power Automate.
โ
The API you want to connect to supports REST (HTTP) requests.
โ
You have the API endpoint URL and necessary authentication details (API Key, OAuth, etc.).
โ
The API provides a valid JSON response.
โ
(Optional) Postman for testing API endpoints.
๐น Step 2: Understanding API Basics
A. Types of API Requests
| Request Type | Description | Example |
|---|---|---|
| GET | Fetch data from an API | Retrieve user details |
| POST | Send data to an API | Create a new record |
| PUT | Update existing data | Modify a record |
| DELETE | Remove data from an API | Delete a record |
B. Example API Endpoint (JSON Placeholder API)
A sample GET request to fetch user data:
https://jsonplaceholder.typicode.com/users
Response:
[
{
"id": 1,
"name": "John Doe",
"email": "johndoe@example.com"
}
]
๐น Step 3: Creating a Custom Connector in Power Apps
A. Open the Custom Connector Setup
- Go to Power Apps โ Power Apps.
- Click “Dataverse” (left panel) โ “Custom Connectors”.
- Click “New custom connector” โ Choose “Create from blank”.
- Enter a Connector Name (e.g.,
MyAPIConnector).
B. Define API General Information
- Scheme: Select HTTPS.
- Host: Enter the API hostname (e.g.,
jsonplaceholder.typicode.com). - Base URL: Provide the API base path (e.g.,
/users).
C. Set Authentication Type
Select an authentication method:
๐น No Authentication โ Public APIs (e.g., JSONPlaceholder).
๐น API Key โ Enter API Key header value (e.g., Authorization: Bearer YOUR_API_KEY).
๐น OAuth 2.0 โ For APIs like Microsoft Graph, Google APIs.
๐น Basic Authentication โ Username and password-based login.
๐น Step 4: Defining API Actions
A. Adding a GET Request
- Click “Definition” โ “New Action”.
- Summary: Enter a description (e.g., “Get User List”).
- Operation ID: Enter a unique identifier (e.g.,
GetUsers). - Click “Request” โ “Import from Sample”.
- Select GET and enter the URL:
https://jsonplaceholder.typicode.com/users - Click Import โ The API will be added to the request section.
B. Defining Response Schema
- Click “Response” โ “Add Default Response”.
- Paste the JSON response sample (from Step 2).
- Power Apps will generate the response schema automatically.
๐น Step 5: Testing the Custom Connector
- Click “Test” โ Choose an action (
GetUsers). - Click “Test Operation”.
- If the request is successful, youโll see API data returned in JSON format.
๐น Step 6: Using the Custom Connector in Power Apps
- Open Power Apps Studio.
- Click “Data” โ “Add Data”.
- Search for the newly created Custom Connector and select it.
- Insert a Gallery (
Insert โ Gallery โ Vertical). - Set its Items property to:
MyAPIConnector.GetUsers() - Map API fields to controls (e.g.,
ThisItem.name).
๐น Step 7: Performing CRUD Operations
A. Adding a New Record (POST Request)
- Create a new action in the Custom Connector.
- Select POST and enter the URL:
https://jsonplaceholder.typicode.com/users - Define request parameters (e.g.,
name,email). - Use the following Power Apps formula to create a record:
MyAPIConnector.CreateUser({name: txtName.Text, email: txtEmail.Text}) - Click Submit to send data to the API.
B. Updating an Existing Record (PUT Request)
- Create a PUT action in the Custom Connector.
- Use this Power Apps formula:
MyAPIConnector.UpdateUser(Gallery1.Selected.id, {name: txtName.Text, email: txtEmail.Text})
C. Deleting a Record (DELETE Request)
- Create a DELETE action in the Custom Connector.
- Use the following Power Apps formula:
MyAPIConnector.DeleteUser(Gallery1.Selected.id)
๐ CRUD operations enable full API integration!
๐น Step 8: Automating API Calls with Power Automate
- Go to Power Automate โ Create a new flow.
- Select Trigger (e.g., “When a button is clicked”).
- Choose “Custom Connector” as an action.
- Select the desired API request (e.g.,
GetUsers). - Add additional steps like notifications, data storage, etc..
- Save & test the flow.
๐น Step 9: Best Practices for Using Custom Connectors
โ
Use API Authentication โ Prefer OAuth 2.0 for security.
โ
Optimize API Calls โ Fetch only necessary fields using query parameters.
โ
Handle Errors โ Use IfError() to catch API failures.
โ
Cache Data โ Store frequently used API results in Collections.
โ
Avoid Overloading APIs โ Use pagination for large datasets.
๐น Troubleshooting Common Issues
| Issue | Solution |
|---|---|
| Connector not returning data | Check API Key, Headers, and authentication settings. |
| Slow API response | Use pagination and avoid unnecessary API calls. |
| Unauthorized Error (401) | Verify API authentication method (OAuth, API Key). |
| Power Apps not displaying API data | Ensure API response format matches Power Apps expectations. |
๐น Conclusion
Using Custom Connectors in Power Apps allows you to integrate external APIs, fetch and update external data, and extend app functionality beyond built-in connectors. ๐
๐ก For better scalability, consider using APIs with Dataverse, SQL Server, or SharePoint.
