In this tutorial, we will guide you through the process of creating a custom connector in Azure Logic Apps, Power Automate, and Power Apps. Custom connectors allow you to connect to external APIs and define their operations and data structures. We will focus on creating a custom connector from scratch, specifically for the Azure Cognitive Services Text Analytics API sentiment operation.
Step 1: Start the Custom Connector Wizard To begin, sign in to Power Apps or Power Automate and navigate to the Data > Custom connectors section. Select "New custom connector" and choose "Create from blank". Enter a name for the custom connector, such as "SentimentDemo", and click "Continue".
Step 2: Update General Details On the General tab, provide a meaningful description for the custom connector. This description will appear in the connector's details and help others understand its purpose. Next, update the "Host" field with the address for the Text Analytics API, which is "westus.api.cognitive.microsoft.com". This information is crucial for the connector to call the API correctly.
Step 3: Specify Authentication Type For this tutorial, we will use API key authentication, which is the authentication method required by the Cognitive Services APIs. On the Security tab, select "API Key" under Authentication type. Specify a parameter label, name, and location for the API key. The label should be meaningful and will be displayed when someone connects to the custom connector. The parameter name and location must match the API's expectations. Click "Connect" to proceed.
Step 4: Create the Connector Definition The custom connector wizard provides various options for defining how your connector functions and how it is exposed in logic apps, flows, and apps. In this section, we will focus on creating an action that calls the Text Analytics API sentiment operation.
- On the Definition tab, select "New action" in the left pane.
- Provide a summary, description, and operation ID for the action. For example:
- Summary: Returns a numeric score representing the sentiment detected.
- Description: The API returns a numeric score between 0 and 1, where scores close to 1 indicate positive sentiment and scores close to 0 indicate negative sentiment.
- Operation ID: DetectSentiment
Step 5: Import Request and Response Information In the Request area, select "Import from sample" to specify the necessary information to connect to the API. Use the provided URL, verb, and body information to import the request details. For example:
- URL:
https://westus.api.cognitive.microsoft.com/text/analytics/v2.0/sentiment
- Verb: POST
- Body: Use the provided JSON code example, which includes the "documents" array with language, id, and text properties.
Similarly, in the Response area, select "Add default response" and import the response body details using the provided JSON example.
Step 6: Update the Connector Definition To make the connector more user-friendly, we will update some settings in the connector definition.
- In the Request area, select "Edit" for the "body" parameter. Modify the parameter values, such as the title, description, and default value, to match the API's expectations.
- Repeat the same process for the "id" and "language" parameters, updating their values accordingly.
Step 7: (Optional) Enable Your Connector as an AI Plugin If you plan to certify your connector as an AI plugin, you can enable this feature in the AI Plugin (preview) tab. Enter the required details, such as the plugin name, description, contact email, and legal information URL. Additionally, provide action details for each AI plugin action, including the summary and description. Enable the plugin operation and user confirmation if desired.
Step 8: (Optional) Use Custom Code Support If you need to transform request and response payloads beyond the scope of existing policy templates, you can utilize custom code support. This step is optional, and you can complete the codeless experience without it.
Step 9: Test the Connector After creating the custom connector, it is essential to test it to ensure it functions correctly. On the Test tab, create a new connection by entering the API key from the Text Analytics API. Once the connection is established, enter a value for the text field and test the operation. The connector will call the API and provide the sentiment score in the response.
Conclusion Creating a custom connector in Azure Logic Apps, Power Automate, and Power Apps allows you to connect to external APIs and define their operations and data structures. By following the steps outlined in this tutorial, you can create a custom connector from scratch and integrate it into your workflows and applications.