Connecting to APIs using Custom Connectors

Loading

🔹 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 TypeDescriptionExample
GETFetch data from an APIRetrieve user details
POSTSend data to an APICreate a new record
PUTUpdate existing dataModify a record
DELETERemove data from an APIDelete 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

  1. Go to Power Apps → Power Apps.
  2. Click “Dataverse” (left panel) → “Custom Connectors”.
  3. Click “New custom connector” → Choose “Create from blank”.
  4. Enter a Connector Name (e.g., MyAPIConnector).

B. Define API General Information

  1. Scheme: Select HTTPS.
  2. Host: Enter the API hostname (e.g., jsonplaceholder.typicode.com).
  3. 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

  1. Click “Definition” → “New Action”.
  2. Summary: Enter a description (e.g., “Get User List”).
  3. Operation ID: Enter a unique identifier (e.g., GetUsers).
  4. Click “Request” → “Import from Sample”.
  5. Select GET and enter the URL: https://jsonplaceholder.typicode.com/users
  6. Click Import → The API will be added to the request section.

B. Defining Response Schema

  1. Click “Response” → “Add Default Response”.
  2. Paste the JSON response sample (from Step 2).
  3. Power Apps will generate the response schema automatically.

🔹 Step 5: Testing the Custom Connector

  1. Click “Test” → Choose an action (GetUsers).
  2. Click “Test Operation”.
  3. If the request is successful, you’ll see API data returned in JSON format.

🔹 Step 6: Using the Custom Connector in Power Apps

  1. Open Power Apps Studio.
  2. Click “Data” → “Add Data”.
  3. Search for the newly created Custom Connector and select it.
  4. Insert a Gallery (Insert → Gallery → Vertical).
  5. Set its Items property to: MyAPIConnector.GetUsers()
  6. Map API fields to controls (e.g., ThisItem.name).

🔹 Step 7: Performing CRUD Operations

A. Adding a New Record (POST Request)

  1. Create a new action in the Custom Connector.
  2. Select POST and enter the URL: https://jsonplaceholder.typicode.com/users
  3. Define request parameters (e.g., name, email).
  4. Use the following Power Apps formula to create a record: MyAPIConnector.CreateUser({name: txtName.Text, email: txtEmail.Text})
  5. Click Submit to send data to the API.

B. Updating an Existing Record (PUT Request)

  1. Create a PUT action in the Custom Connector.
  2. Use this Power Apps formula: MyAPIConnector.UpdateUser(Gallery1.Selected.id, {name: txtName.Text, email: txtEmail.Text})

C. Deleting a Record (DELETE Request)

  1. Create a DELETE action in the Custom Connector.
  2. 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

  1. Go to Power Automate → Create a new flow.
  2. Select Trigger (e.g., “When a button is clicked”).
  3. Choose “Custom Connector” as an action.
  4. Select the desired API request (e.g., GetUsers).
  5. Add additional steps like notifications, data storage, etc..
  6. 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

IssueSolution
Connector not returning dataCheck API Key, Headers, and authentication settings.
Slow API responseUse pagination and avoid unnecessary API calls.
Unauthorized Error (401)Verify API authentication method (OAuth, API Key).
Power Apps not displaying API dataEnsure 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.


Leave a Reply

Your email address will not be published. Required fields are marked *