Create a custom connector from an OpenAPI definition
Note
This topic is part of a tutorial series on creating and using custom connectors in Azure Logic Apps, Microsoft Power Automate, and Microsoft Power Apps. Make sure you read the custom connector overview to understand the process.
To create a custom connector, you must describe the API you want to connect to so that the connector understands the API's operations and data structures. In this topic, you create a custom connector using an OpenAPI definition that describes the Cognitive Services Text Analytics Sentiment API (our example for this series).
For other ways to describe an API, see the following topics:
Prerequisites
- An OpenAPI definition that describes the example API. When creating a custom connector, the OpenAPI definition must be less than 1 MB.
- An API key for the Cognitive Services Text Analytics API.
- One of the following subscriptions:
- Azure, if you're using Logic Apps
- Power Automate
- Power Apps
- If you're using Logic Apps, first create an Azure Logic Apps custom connector.
Import the OpenAPI definition
You're now ready to work with the OpenAPI definition you downloaded. All the required information is contained in the definition, and you can review and update this information as you go through the custom connector wizard.
Start by importing the OpenAPI definition for Logic Apps, or for Power Automate and Power Apps.
Import the OpenAPI definition for Logic Apps
Go to the Azure portal, and open the Logic Apps connector you created earlier in Create an Azure Logic Apps custom connector.
In your connector's menu, choose Logic Apps Connector, then choose Edit.
Under General, choose Upload an OpenAPI file, then navigate to the OpenAPI definition that you created.
Note
This tutorial focuses on a REST API, but you can also use a SOAP API with Logic Apps.
Import the OpenAPI definition for Power Automate and Power Apps
Go to make.powerapps.com or flow.microsoft.com.
In the navigation pane, select Data > Custom connectors.
Select New custom connector, then choose Import an OpenAPI file.
Enter a name for the custom connector, then navigate to the OpenAPI definition that you downloaded or created, and choose Continue.
Parameter Value Custom connector title "SentimentDemo"
Review general details
From this point, we'll show the Power Automate UI, but the steps are largely the same across all three technologies. We'll point out any differences. In this part of the topic, we'll mostly review the UI and show you how the values correspond to sections of the OpenAPI file.
At the top of the wizard, make sure the name is set to "SentimentDemo", then choose Create connector.
On the General page, review the information that was imported from the OpenAPI definition, including the API host and the base URL for the API. The connector uses the API host and the base URL to determine how to call the API.
Note
For more information about connecting to on-premises APIs, see Connect to on-premises APIs using the data gateway.
The following section of the OpenAPI definition contains information for this page of the UI:
"info": { "version": "1.0.0", "title": "SentimentDemo", "description": "Uses the Cognitive Services Text Analytics Sentiment API to determine whether text is positive or negative" }, "host": "westus.api.cognitive.microsoft.com", "basePath": "/", "schemes": [ "https" ]
Review authentication type
There are several options available for authentication in custom connectors. The Cognitive Services APIs use API key authentication, so that's what's specified in the OpenAPI definition.
On the Security page, review the authentication information for the API key.
The label is displayed when someone first makes a connection with the custom connector; you can choose Edit and change this value. The parameter name and location must match what the API expects, in this case "Ocp-Apim-Subscription-Key" and "Header".
The following section of the OpenAPI definition contains information for this page of the UI:
"securityDefinitions": {
"api_key": {
"type": "apiKey",
"in": "header",
"name": "Ocp-Apim-Subscription-Key"
}
}
Review the connector definition
The Definition page of the custom connector wizard gives you a lot of options for defining how your connector functions, and how it is exposed in logic apps, flows, and apps. We'll explain the UI and cover a few options in this section, but we also encourage you to explore on your own. For information on defining objects from scratch in this UI, see Create the connector definition.
The following area displays any actions, triggers (for Logic Apps and Power Automate), and references that are defined for the connector. In this case, the
DetectSentiment
action from the OpenAPI definition is displayed. There are no triggers in this connector, but you can learn about triggers for custom connectors in Use webhooks with Azure Logic Apps and Power Automate.The General area displays information about the action or trigger currently selected. You can edit the information here, including the Visibility property for operations and parameters in a logic app or flow:
none: displayed normally in the logic app or flow
advanced: hidden under an additional menu
internal: hidden from the user
important: always shown to the user first
The Request area displays information based on the HTTP request that's included in the OpenAPI definition. In this case, you see that the HTTP verb is POST, and the URL is "/text/analytics/v2.0/sentiment" (the full URL to the API is "https://westus.api.cognitive.microsoft.com//text/analytics/v2.0/sentiment"). We'll look closer at the body parameter shortly.
The following section of the OpenAPI definition contains information for the General and Request areas of the UI:
"paths": { "/text/analytics/v2.0/sentiment": { "post": { "summary": "Returns a numeric score representing the sentiment detected", "description": "The API returns a numeric score between 0 and 1. Scores close to 1 indicate positive sentiment, while scores close to 0 indicate negative sentiment.", "operationId": "DetectSentiment"
The Response area displays information based on the HTTP response that's included in the OpenAPI definition. In this case, the only response defined is for "200" (a successful response), but you can define additional responses.
The following section of the OpenAPI definition contains some of the information related to the response:
"score": { "type": "number", "format": "float", "description": "score", "x-ms-summary": "score" }, "id": { "type": "string", "description": "id", "x-ms-summary": "id" }
This section shows the two values that are returned by the connector:
id
andscore
. It includes their data types, and the fieldx-ms-summary
, which is an OpenAPI extension. For more information on this and other extensions, see Extend an OpenAPI definition for a custom connector.The Validation area displays any issues that are detected in the API definition. Make sure to check this area before you save a connector.
Update the definition
The OpenAPI definition you downloaded is a good basic example, but you might work with definitions that require a lot of updating so that the connector is more friendly when someone uses it in a logic app, flow, or app. We'll show you how to make a simple change to the definition.
In the Request area, choose body then Edit.
In the Parameter area, you now see the three parameters that the API expects:
ID
,Language
, andText
. Choose ID then Edit.In the Schema Property area, update the description for the parameter, then choose Back.
Parameter Value Description "A numeric identifier for each document that you submit" In the Parameter area, choose Back to take you back to the main definition page.
At the top right of the wizard, choose Update connector.
Download the updated OpenAPI file
You can create a custom connector from an OpenAPI file, a Postman collection, or from scratch (in Power Automate and Power Apps). Regardless of how you create the connector, you can download the OpenAPI definition that the service uses internally.
In Logic Apps, download from the custom connector.
In Power Automate or Power Apps, download from the list of custom connectors.
Test the connector
Now that you've created the connector, test it to make sure it's working properly. Testing is currently available only in Power Automate and Power Apps.
Important
When using an API key, we recommend not testing the connector immediately after you create it. It can take a few minutes until the connector is ready to connect to the API.
On the Test page, choose New connection.
Enter the API key from the Text Analytics API, then choose Create connection.
Return to the Test page:
In Microsoft Flow, you're taken back to the Test page. Choose the refresh icon to make sure the connection information is updated.
In Power Apps, you're taken to the list of connections available in the current environment. In the upper right corner, choose the gear icon, then choose Custom connectors. Choose the connector you created, then go back to the Test page.
On the Test page, enter a value for the text field (the other fields use the defaults that you set earlier), then choose Test operation.
The connector calls the API, and you can review the response, which includes the sentiment score.
Next steps
Now that you've created a custom connector and defined its behaviors, you can use the connector.
- Use a custom connector from a flow
- Use a custom connector from an app
- Use a custom connector from a logic app
You can also share a connector within your organization and/or get the connector certified so that people outside your organization can use it.