Bendrinti naudojant


Use a custom connector in a logic app workflow

This article is part of a tutorial series on creating and using custom connectors in Azure Logic Apps, Power Automate, and Power Apps. To understand the process, make sure you read Custom connector overview.

In this article, you build an example Consumption logic app workflow that shows how to use the custom connector that you created in a previous tutorial. This example workflow triggers when an item is added to a SharePoint Online list. The workflow then uses the custom connector to call the Cognitive Services Text Analytics API. The connector returns the sentiment score (0 to 1) for the text in the list item, and the workflow writes the score back to the list.

The following example shows the finished logic app workflow:

Screenshot of the complete sentiment analysis of the Consumption logic app workflow.

Prerequisites

Create the SharePoint Online list

First, create a three-column list in SharePoint Online. This list stores movie review data that the logic app workflow analyzes for sentiment. Learn more about SharePoint Online lists in Introduction to lists.

  1. In your SharePoint Online site, select New > List to create a new list.

  2. In the Name field, type Movie Reviews

  3. Select Create.

    By default, Sharepoint Online creates the list with a Title column.

  4. Select the plus sign New item icon > Single line of text.

  5. Enter the name Review, and select Save.

  6. To add another column using Number as the data type and Score as the name, repeat steps 3 and 4.

Create logic app resource

Now that you have a list, create a Consumption logic app resource and workflow in the Azure portal.

  1. Sign in to the Azure portal with your Azure account credentials.

  2. In the portal search box, enter logic app, and select Logic apps.

  3. Select the Consumption plan.

  4. Enter the following information for your logic app resource:

    Property Value Description
    Subscription <Azure-subscription-name> The name for your Azure subscription.
    Resource Group <resource-group-name> The name for the Azure resource group used to organize related resources. This example uses My-First-LA-RG.
    Logic App name <logic-app-name> The name for your logic app. This exmaple uses SentimentAnalysis.
    Region <Azure-region> The Azure region for hosting your logic app.

    Note: Your logic app resource and custom connector must exist in the same region. This example uses East US 2.
    Enable log analytics No Keep diagnostic logging disabled.
  5. Finish creating your logic app.

  6. After Azure deploys your app, select Go to resource.

    Alternatively, find and select your logic app by entering the name in the Azure search box.

Add a trigger

As the first step in your workflow, add a SharePoint trigger. This trigger fires when an item is added to the specified SharePoint Online list.

  1. On the logic app menu, under Development Tools, select Logic app designer, if not selected already.

  2. On the designer, select Add a trigger.

  3. In the connector gallery pane search box, enter SharePoint, and select the SharePoint trigger named When an item is created. If the trigger doesn't appear in the list, in the upper-right corner of the SharePoint triggers list, select See more.

    Screenshot shows Azure portal, Consumption workflow designer, selected Add a trigger, and open connector gallery for selecting a trigger.

  4. After the Create Connection pane opens, sign in with your SharePoint credentials.

  5. Provide the following information for the SharePoint trigger:

    Parameter Value
    Site Address <SharePoint-site-address>
    List Name Movie Reviews
  6. Expand the section named How often do you want to check for items to finish setting up the trigger:

    Parameter Value
    Interval 10
    Frequency Second

    When you finish, your trigger looks like the following example:

    Screenshot shows Consumption workflow designer, SharePoint trigger, and trigger parameters.

Add an action from custom connector

Following the trigger, you can add one or more actions to perform. To add an action from your custom connector, follow these steps:

  1. Under the trigger, select the plus sign (+), and select Add an action.

  2. In the connector gallery pane search box, enter the name for your custom connector, which is SentimentDemo in this example, and select the action that you want.

    Tip

    For easier searching, under Runtime, select Custom.

    Screenshot shows Consumption workflow and action available for SentimentDemo custom connector.

    The action name and description come from information provided when you created the connector.

  3. Enter a name for the connection and the API key.

    Parameter Value
    Connection Name A name for the connection, for example, SentimentDemoConnection.
    API key The API key for the Text Analytics API. To learn more, see Get an API key.
  4. Provide the information for the action, for example:

    Parameter Value
    documents ID 1

    This value is required because the connector can handle multiple documents. This example sends one document at a time. However, in production, the documents Language and documents ID values might come from a list or another data source.
    documents Language en
    documents Text The SharePoint Review field. To enter this value, follow these steps:

    1. Select inside the documents Text box, and select the lightning icon to open the dynamic content list.

    2. From the list, in the SharePoint trigger section, select Review.
  5. Add the SharePoint action named Update item to your workflow, and provide the following values:

    Parameter Value
    Site Address <SharePoint-site-address>
    List Name Movie Reviews
    Id The SharePoint ID field
    Title The SharePoint trigger output named Title.

    To enter this value, follow these steps:

    1. Select inside the Title box, and select the lightning icon to open the dynamic content list.

    2. From the list, in the SharePoint trigger section, select Title.
  6. In the Update item action pane, open the Advanced parameters list, select the desired parameters, which vary based on the SharePoint Online list, to add them to the action. For each added parameter, open the dynamic content list, and select the corresponding output from the SharePoint trigger named When an item is created and from the custom connector action.

    This example adds the following parameters and the corresponding trigger and action outputs:

    Advanced parameter Trigger or action output
    Review The SharePoint trigger output named Review
    Score The custom connector action output named score.

    When you select the trigger output to use in this field, the designer automatically adds a For each action because the custom connector action can accept multiple documents. Although the custom connection action sends only one document at a time, the designer matches the connector's capabilities.

    When you finish, the Update item action looks like the following example:

    Screenshot shows added custom connector action, parameter values, and surrounding action named For each.

  7. When you finish, save your workflow. On the designer toolbar, select Save.

Test the workflow

To test the workflow, add reviews to your SharePoint Online list, and check how the workflow responds.

  1. On the designer toolbar, select Run > Run.

  2. In your SharePoint Online list, choose Quick Edit.

  3. Add two reviews to the list, one negative and one positive, based on the following values, and select Done.

    Parameter Suggested value
    Title (positive) My Favorite Movie
    Review (positive) I enjoyed the new movie after a long day.
    Title (negative) Some Other Movie
    Review (negative) The worst movie I've seen in decades.
  4. In the Azure portal, on the logic app menu, choose Overview to review the workflow run history. On the Overview page, select Runs history.

    The Runs history tab shows two workflow runs, one for each review that you added to the list.

  5. To save on resource consumption after you're done with this workflow, on the Overview page toolbar, choose Disable.

  6. Back on the SharePoint Online list page, refresh the browser to see the scores that the workflow added.

    Screenshot shows scores added to SharePoint Online list from logic app workflow.

Congratulations! Although this example is a basic workflow, the custom connector adds powerful functionality with the capability to call Cognitive Services.

You can share your custom connector within your organization, or you can get the connector certified for people outside your organization to use:

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.