Exercise - Implement a webhook trigger

Completed

In this exercise, you'll add a webhook trigger to the custom connector for an existing Contoso Invoicing API.

Important

Use a test environment with Microsoft Dataverse provisioned. If you don't have one, you can sign up for the community plan.

Note

Download the following file to your local computer to complete this exercise Contoso Invoicing Triggers. Select the download button on the middle-right of the screen.

Task 1: Import a solution with the custom connector

In this task, you'll import an unmanaged solution that contains a prebuilt custom connector for Contoso Invoicing API.

  1. Go to Power Apps maker portal and make sure that you are in the correct environment.

  2. Select Solutions > Import solution.

  3. Select Browse.

  4. Select the ContosoInvoicingTriggers_1_0_0_0.zip solution and then select Open.

  5. Select Next.

  6. Select Import and then wait for the import to complete. You should get a success message after the import completes.

  7. Select Publish all customizations and then wait for the publish to complete.

  8. Select to open the Contoso invoicing triggers solution that you imported. You should see the Contoso invoicing triggers custom connector component.

    Screenshot of the Contoso invoicing triggers highlighted.

  9. In a new tab, go to Contoso Invoicing.

  10. Select the API Key link.

    Screenshot of the API Key link highlighted.

  11. Copy the API Key and keep it on a notepad. You'll use it a few times in this exercise.

  12. Return to Power Apps maker portal and make sure that you are in the environment.

  13. Select Solutions and select to open the Contoso invoicing triggers solution.

  14. Select to open the Contoso invoicing triggers custom connector.

  15. Select Edit.

    Screenshot of an arrow pointing to the edit connector button.

  16. Enter contosoinvoicing.azurewebsites.net for Host.

  17. Select Update connector.

  18. Select Test > + New Connection.

    Screenshot of an arrow pointing to the add new connection button.

  19. Paste the API Key and select Create connection.

    Screenshot of the Create connection button.

  20. Select Refresh. The connection that you created should be selected automatically.

  21. Scroll down to the Operations section, select ListInvoices, and then select Test operation.

    Screenshot of an arrow pointing to the test operation button.

    You should see a list of invoices in the Body section.

    Screenshot of a list of invoices in the Body section.

  22. Don't navigate away from this page.

Task 2: Add a webhook trigger

Follow these steps to add a webhook trigger:

  1. Select Definition.

    Screenshot of the Definition tab selected.

  2. Scroll down to the Triggers section and select + New trigger.

  3. Provide the following values:

    • Summary - When Invoice is Created

    • Description - When Invoice is Created

    • Operation ID - InvoiceCreated

    • Trigger type - Webhook

    Screenshot of the new trigger values for Summary, Description, Operation ID, and Trigger type.

  4. Go to the Request section and select + Import from sample.

    Screenshot of an arrow pointing to the Import from sample button.

  5. Provide the following values and then select Import. With other APIs, you would get the sample from the API documentation.

    • Verb - POST

    • URL - https://contosoinvoicing.azurewebsites.net/NewInvoiceNotification/

      Note

      Include the trailing foward slash on the URL.

    • Body

        {
        "targetUrl":"https://webhook.site"
        }
      

    Screenshot of the request sample properties.

  6. Scroll to Trigger configuration and then select targetUrl for Callback URL parameter. This selection allows targetUrl to be populated at runtime by the custom connector.

    Screenshot of the trigger confirmation window.

  7. Scroll up to the Request section, select Body, and then select Edit.

    Screenshot of an arrow pointing to the edit body button.

  8. Select targetUrl and then select Edit.

    Screenshot of an arrow pointing to the edit target URL button.

  9. Select Yes for Is required and select internal for Visibility.

    Screenshot of the target URL properties fields.

  10. Select the Back button.

    Screenshot of an arrow pointing to the back button.

  11. Select the Back button again.

  12. Scroll down to the Webhook Response section, enter Invoice for the Description, and then select + Import from sample. The Webhook Response defines what will be sent to your flow when the triggering event occurs.

    Screenshot of an arrow punting to the import sample response button.

  13. Paste the following JSON sample in the Body and then select Import.

     {
     "invoiceId": "1933",
     "date": "2021-01-26T04:02:52.1490835+00:00",
     "amount": 5000,
     "accountId": "1001",
     "accountName": "Wing Tips",
     "status": "Invoiced",
     "typeId": 1,
     "purchaseOrderId": "3002",
     "tags": "New Account;Special Pricing"
     }
    

    Screenshot of the response import properties details.

  14. Select Update connector.

    Note

    If you receive an error message about "all paths must begin with '/'," open Swagger, find the line containing '':{} and then delete it.

  15. Select Close.

Task 3: Test the trigger

  1. Go to Power Apps maker portal and make sure that you are in the environment.

  2. Select Solutions and then open the Contoso invoicing triggers solution.

  3. Select + New > Automation > Cloud flow > Instant.

  4. Enter Create invoice for the name, select Manually trigger a flow under Triggers, and then select Create.

    Screenshot of an arrow pointing to the Manually trigger a flow trigger.

  5. Expand the trigger and select + Add an input.

  6. Select Number for the input type.

    Screenshot of an arrow pointing to the Number input type.

  7. Enter Amount for the input name and then select + New step.

    Screenshot of an arrow pointing to the add new flow step button.

  8. Select the Custom tab and then select the Contoso invoicing custom connector.

    Screenshot of an arrow pointing to the custom connector.

  9. Select the Add Invoice action.

  10. Enter Contoso Connection in the Connection Name field, paste the API Key that you copied in Task 1: Import a solution with the custom connector, and then select Create. You must use the same API key in both flows or your trigger flow won't run.

    Screenshot of the creation connection button.

  11. Select the amount field and select Amount from the Dynamic content pane.

    Screenshot of the amount field output from the previous step.

  12. Select Save.

  13. Select the <- back button.

  14. Make sure you're still in the Contoso Invoicing - Triggers solution.

  15. Select + New > Automation > Cloud flow > Automated.

  16. Enter Invoice Notification for Flow name and select Skip.

  17. Select the Custom tab, and then select the Contoso invoicing custom connector.

    Screenshot of an arrow pointing to the custom connector trigger.

  18. Select the When Invoice is Created trigger.

  19. Select + New step.

  20. Search for compose and then select the Compose action.

  21. Select the Inputs field and then select body from the Dynamic content pane.

    Screenshot of the Inputs field and body from the Dynamic content pane.

  22. Select Save.

  23. Select Test.

  24. Select Manually > Test. The flow will start, and you should wait for notifications.

  25. Open a new browser window and navigate to https://make.powerapps.com/

  26. Make sure you have the correct environment selected.

  27. Select Solutions and open the Contoso Invoicing - Triggers

  28. Open the Create invoice cloud flow.

  29. Select Edit.

  30. Select Test.

  31. Select Manually > Test.

  32. Select Continue.

  33. Enter 5500 for Amount and then select Run flow.

  34. Select Done.

  35. Switch to the Invoice Notification flow. The flow should run successfully.

  36. Select to expand the Compose action.

    Screenshot of an arrow pointing to the Compose action.

    The Inputs and Outputs should show the amount that you provided in the Create invoice flow.

    Screenshot of the Compose action inputs and outputs.