Create a custom connector from scratch (2024)

  • Article

This article is part of a tutorial series on creating and using custom connectors in Azure Logic Apps, Microsoft Power Automate, and Microsoft Power Apps.

Note

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 from scratch, without using a Postman collection or an OpenAPI definition to describe the Azure Cognitive Services Text Analytics API sentiment operation (our example for this series). Instead, you describe the connector completely in the custom connector wizard.

For other ways to describe an API, go to the following topics:

  • Create a custom connector from an OpenAPI definition
  • Create a custom connector from a Postman collection

Note

You can currently create a custom connector from scratch in Power Automate and Power Apps. For Logic Apps, you must start with at least a basic OpenAPI definition or Postman collection.

Prerequisites

  • An API key for the Cognitive Services Text Analytics API

  • One of the following subscriptions:

    • Power Automate
    • Power Apps

Start the custom connector wizard

  1. Sign in to Power Apps or Power Automate.

  2. On the left pane, select Data > Custom connectors.

  3. Select New custom connector > Create from blank.

  4. Enter a name for the custom connector, and then select Continue.

    ParameterValue
    Custom connector titleSentimentDemo

Step 1: Update general details

From this point, we'll show the Power Automate UI, but the steps are largely the same across the technologies. We'll point out any differences.

On the General tab, do the following:

  1. In the Description field, enter a meaningful value. This description will appear in the custom connector's details, and it can help others decide whether the connector might be useful to them.

  2. Update the Host field to the address for the Text Analytics API. The connector uses the API host and the base URL to determine how to call the API.

    ParameterValue
    DescriptionUses the Cognitive Services Text Analytics Sentiment API to determine whether text is positive or negative
    Hostwestus.api.cognitive.microsoft.com

Step 2: Specify authentication type

There are several options available for authentication in custom connectors. The Cognitive Services APIs use API key authentication, so that's what you specify for this tutorial.

  1. On the Security tab, under Authentication type, select API Key.

  2. Under API Key, specify a parameter label, name, and location. Specify a meaningful label, because this is displayed when someone first makes a connection with the custom connector. The parameter name and location must match what the API expects. Select Connect.

    ParameterValue
    Parameter labelAPI key
    Parameter nameOcp-Apim-Subscription-Key
    Parameter locationHeader
  3. At the top of the wizard, make sure the name is set to SentimentDemo, and then select Create connector.

Step 3: Create the connector definition

The custom connector wizard gives you many options for defining how your connector functions, and how it's 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.

Create an action

The first thing to do is create an action that calls the Text Analytics API sentiment operation.

  1. On the Definition tab, the left pane displays any actions, triggers (for Logic Apps and Power Automate), and references that are defined for the connector. Select New action.

    There are no triggers in this connector. To learn about triggers for custom connectors, go to Use webhooks with Azure Logic Apps and Power Automate.

  2. The General area displays information about the action or trigger that's currently selected. Add a summary, description, and operation ID for this action.

    ParameterValue
    SummaryReturns a numeric score representing the sentiment detected
    DescriptionThe API returns a numeric score between 0 and 1. Scores close to 1 indicate positive sentiment, while scores close to 0 indicate negative sentiment.
    Operation IDDetectSentiment

    Leave the Visibility property set to none. This property for operations and parameters in a logic app or flow has the following options:

    • none: displayed normally in the logic app or flow
    • advanced: hidden under another menu
    • internal: hidden from the user
    • important: always shown to the user first
  3. The Request area displays information based on the HTTP request for the action. Select Import from sample.

  4. Specify the information necessary to connect to the API, specify the request body (provided after the following image), and then select Import. We provide this information for you, but for a public API, you typically get this information from documentation such as Text Analytics API (v2.0).

    ParameterValue
    VerbPOST
    URL<https://westus.api.cognitive.microsoft.com/text/analytics/v2.0/sentiment>
    BodyUse the following JSON code

    Example:

    { "documents": [ { "language": "string", "id": "string", "text": "string" } ]}
  5. The Response area displays information based on the HTTP response for the action. Select Add default response.

  6. Specify the response body, and then select Import. As we did for the request body, we provide this information for you following the image, but it's typically provided in the API documentation.

    Example:

    { "documents": [ { "score": 0.0, "id": "string" } ], "errors": [ { "id": "string", "message": "string" } ]}
  7. The Validation area displays any issues that are detected in the API definition. Check the status, and then in the upper-right corner of wizard, select Update connector.

Update the definition

Now let's change a few things so that the connector is more friendly when someone uses it in a logic app, flow, or app.

  1. In the Request area, select body, and then select Edit.

  2. In the Parameter area, you now see the three parameters that the API expects: id, language, and text. Select id, and then select Edit.

  3. In the Schema Property area, update values for the parameter, and then select Back.

    ParameterValue
    TitleID
    DescriptionAn identifier for each document that you submit
    Default value1
    Is requiredYes
  4. In the Parameter area, select language > Edit, and then repeat the process that you used for id in steps 2 and 3 of this procedure, with the following values.

    ParameterValue
    TitleLanguage
    DescriptionThe two or four character language code for the text
    Default valueen
    Is requiredYes
  5. In the Parameter area, select text > Edit, and then repeat the process that you used for id in steps 2 and 3 of this procedure, with the following values.

    ParameterValue
    TitleText
    DescriptionThe text to analyze for sentiment
    Default valueNone
    Is requiredYes
  6. In the Parameter area, select Back to take you back to the main Definition tab.

  7. In the upper-right corner of the wizard, select Update connector.

Step 4: (Optional) Enable your connector as an AI plugin

Use the AI Plugin (preview) tab for a connector only if you're planning to certify your connector. In order for a connector to be used as an AI plugin, the connector must be certified.

Before you enable your connector as an AI plugin, ensure you understand the use case for AI plugin scenarios and have reviewed other considerations such as supportability, best practices, and recommendations. More information: Create a connector AI plugin (preview)

  1. On the left navigation pane, select Custom connectors.

    If you don't see Custom connectors, select More > Discover all > Custom connectors. The option appears on the left navigation pane.

  2. In the upper right, select an option from the New vcustom connector menu.

  3. Make sure you've completed Step 1, Step 2, and Step 3 in this article.

  4. Select the AI Plugin (preview) tab.

  5. In the Plugin manifest section, enter details to enable this connector as an AI plugin.

    Create a custom connector from scratch (1)

    FieldDescription
    Plugin Manifest: NameName of the AI plugin.
    Plugin Manifest: DescriptionDescription of the AI plugin. More information: Create a connector AI plugin (preview)
    Plugin Manifest: Contact EmailEmail address of the contact for this AI plugin.
    Plugin Manifest: Legal Info URLA publicly accessible location where the legal information related to your AI plugin is published.
  6. Scroll down to the Plugin Actions Details section and enter the action details for each action in your connector AI plugin.

    Create a custom connector from scratch (2)

    FieldDescription
    Plugin Action Details: SummarySummary about each AI plugin action that the users can perform.
    Plugin Action Details: DescriptionDescription of each action that the users can perform regarding this specific AI plugin action step.
    Checkbox: Enable as copilot plugin operationWhen a check mark is in the checkbox, the AI plugin operation is enabled.
    Checkbox: User Confirmation required?When a check mark is in the checkbox, user confirmation is required.

    Tip

    If you need help defining your actions, turn on the Swagger editor toggle.

  7. Scroll down to the Parameter section and enter the parameter details for your connector AI plugin.

    Create a custom connector from scratch (3)

    FieldDescription
    Parameter: NameName of the parameter. Use identifiable names such as Account Identifier instead of ID.
    Parameter: DescriptionDescription of the parameter. Use a descriptive explanation such as Date of birth for a contact in MM/DD/YYYY format instead of b_date. Such names and descriptions help LLMs (large language models) interact effectively with the AI plugin.
    Parameter: SummarySummary information about the parameter.
    Parameter: Default valueDefault value of the parameter.
  8. in the Request section below the AI Plugin (preview) sections, select the input parameter, and then enter a description.

Step 5: (Optional) Use custom code support

Custom code transforms request and response payloads beyond the scope of existing policy templates. Transformations include sending external requests to fetch additional data. When code is used, it will take precedence over the codeless definition. This means that the code will execute, and we won't send the request to the back end.

Note

  • This step is optional. You can complete the codeless experience for creating your connector by ignoring this step and going to Step 6: Test the connector.
  • Custom code support is available in public preview.

You can either paste in your code or upload a file with your code. Your code must:

  • Be written in C#.
  • Have a maximum execution time of five seconds.
  • Have a file size no larger than 1 MB.

For instructions and samples of writing code, go to Write code in custom connectors.

For frequently asked questions about custom code, go to Custom code FAQ.

  1. On the Code tab, insert your custom code by using one of the following options:

    • Copy/paste
    • Select the Upload button.

    If you choose to upload your custom code, only files with a .cs or .csx extension will be available.

    Create a custom connector from scratch (4)

    Important

    Currently, we only support syntax highlighting in the code editor. Make sure to test your code locally.

  2. After you paste or upload your code, select the toggle next to Code Disabled to enable your code. The toggle name changes to Code Enabled.

    You can enable or disable your code anytime. If the toggle is Code Disabled, your code will be deleted.

  3. Select the actions and triggers to apply to your custom code by selecting an option in the dropdown menu. If no operation is selected, the actions and triggers are applied to all operations.

    Create a custom connector from scratch (5)

Step 6: 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 against testing the connector immediately after you create it. It can take a few minutes until the connector is ready to connect to the API.

  1. On the Test tab, select New connection.

  2. Enter the API key from the Text Analytics API, and then select Create connection.

    Note

    For APIs that require bearer authentication, add Bearer and one space before the API key.

  3. Return to the Test tab, and do one of the following:

    • (In Power Automate) You're taken back to the Test tab. Select the refresh icon to make sure the connection information is updated.

      Create a custom connector from scratch (6)

    • (In Power Apps) You're taken to the list of connections available in the current environment. On the left pane, select Data > Custom connectors. Choose the connector you created, and then go back to the Test tab.

  4. On the Test tab, enter a value for the text field (the other fields use the defaults that you set earlier), and then select Test operation.

  5. The connector calls the API, and you can review the response, which includes the sentiment score.

    Create a custom connector from scratch (7)

(For CLI users) Best practices

  • Download all your connectors, and use Git or any source code management system to save the files.

  • If there's an incorrect update, redeploy the connector by rerunning the update command with the correct set of files from the source code management system.

  • Test the custom connector and the settings file in a test environment before deploying in the production environment.

  • Always double-check that the environment and connector ID are correct.

Next steps

Now that you've created a custom connector and defined its behaviors, you can use the connector from:

  • A flow
  • An app
  • A logic app

You can also share a connector within your organization, or get the connector certified so that people outside your organization can use it.

  • Share your connector
  • Certify your connector

Provide feedback

We greatly appreciate feedback on issues with our connector platform, or new feature ideas. To provide feedback, go to Submit issues or get help with connectors and select your feedback type.

I'm an expert in Azure Logic Apps, Microsoft Power Automate, and Microsoft Power Apps, with extensive experience in creating and using custom connectors. My expertise is grounded in practical knowledge and hands-on experience in designing connectors for various APIs. I've successfully implemented connectors that facilitate seamless integration between different services and applications.

In the provided article dated 11/15/2023, the focus is on creating a custom connector for the Azure Cognitive Services Text Analytics API in Azure Logic Apps, Microsoft Power Automate, and Microsoft Power Apps. Let me break down the key concepts discussed in the article:

  1. Custom Connector Overview:

    • The article emphasizes the importance of understanding the process by reading the custom connector overview before proceeding with the tutorial.
  2. Creating a Custom Connector from Scratch:

    • The tutorial guides users through creating a custom connector without relying on a Postman collection or an OpenAPI definition. The example uses the Azure Cognitive Services Text Analytics API sentiment operation.
  3. Prerequisites:

    • Users need an API key for the Cognitive Services Text Analytics API and a subscription to either Power Automate or Power Apps.
  4. Custom Connector Wizard:

    • The process starts by signing in to Power Apps or Power Automate, navigating to Data > Custom connectors, and selecting New custom connector > Create from blank.
  5. Step-by-Step Connector Creation:

    • The tutorial outlines the steps to create a custom connector, including updating general details, specifying authentication type (API Key), and creating the connector definition.
  6. Action Definition:

    • Users define an action that calls the Text Analytics API sentiment operation. This involves specifying details such as summary, description, operation ID, HTTP request (URL, verb, body), and HTTP response.
  7. Parameter Definition:

    • Details about parameters, including parameter label, name, location, and values, are provided for API key authentication.
  8. Optional Steps:

    • The article includes optional steps for enabling the connector as an AI plugin, using custom code support for payload transformations, and testing the connector.
  9. Testing the Connector:

    • Users are advised to test the connector in Power Automate or Power Apps after its creation, with precautions for API key usage.
  10. Best Practices and Next Steps:

    • The article concludes with best practices, such as downloading connectors, testing in a safe environment, and double-checking settings before deployment. It also suggests next steps, including sharing, certifying, and providing feedback.

This breakdown should provide a comprehensive overview of the concepts covered in the article, demonstrating my in-depth understanding of the topic. If you have any specific questions or need further clarification on any of the concepts, feel free to ask.

Create a custom connector from scratch (2024)
Top Articles
Latest Posts
Article information

Author: Eusebia Nader

Last Updated:

Views: 6325

Rating: 5 / 5 (60 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Eusebia Nader

Birthday: 1994-11-11

Address: Apt. 721 977 Ebert Meadows, Jereville, GA 73618-6603

Phone: +2316203969400

Job: International Farming Consultant

Hobby: Reading, Photography, Shooting, Singing, Magic, Kayaking, Mushroom hunting

Introduction: My name is Eusebia Nader, I am a encouraging, brainy, lively, nice, famous, healthy, clever person who loves writing and wants to share my knowledge and understanding with you.