Exercise - Implement a webhook trigger
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.
Go to Power Apps maker portal and make sure that you are in the correct environment.
Select Solutions > Import solution.
Select Browse.
Select the ContosoInvoicingTriggers_1_0_0_0.zip solution and then select Open.
Select Next.
Select Import and then wait for the import to complete. You should get a success message after the import completes.
Select Publish all customizations and then wait for the publish to complete.
Select to open the Contoso invoicing triggers solution that you imported. You should see the Contoso invoicing triggers custom connector component.
In a new tab, go to Contoso Invoicing.
Select the API Key link.
Copy the API Key and keep it on a notepad. You'll use it a few times in this exercise.
Return to Power Apps maker portal and make sure that you are in the environment.
Select Solutions and select to open the Contoso invoicing triggers solution.
Select to open the Contoso invoicing triggers custom connector.
Select Edit.
Enter
contosoinvoicing.azurewebsites.net
for Host.Select Update connector.
Select Test > + New Connection.
Paste the API Key and select Create connection.
Select Refresh. The connection that you created should be selected automatically.
Scroll down to the Operations section, select ListInvoices, and then select Test operation.
You should see a list of invoices in the Body section.
Don't navigate away from this page.
Task 2: Add a webhook trigger
Follow these steps to add a webhook trigger:
Select Definition.
Scroll down to the Triggers section and select + New trigger.
Provide the following values:
Summary - When Invoice is Created
Description - When Invoice is Created
Operation ID - InvoiceCreated
Trigger type - Webhook
Go to the Request section and select + Import from sample.
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" }
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.
Scroll up to the Request section, select Body, and then select Edit.
Select targetUrl and then select Edit.
Select Yes for Is required and select internal for Visibility.
Select the Back button.
Select the Back button again.
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.
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" }
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.
Select Close.
Task 3: Test the trigger
Go to Power Apps maker portal and make sure that you are in the environment.
Select Solutions and then open the Contoso invoicing triggers solution.
Select + New > Automation > Cloud flow > Instant.
Enter Create invoice for the name, select Manually trigger a flow under Triggers, and then select Create.
Expand the trigger and select + Add an input.
Select Number for the input type.
Enter Amount for the input name and then select + New step.
Select the Custom tab and then select the Contoso invoicing custom connector.
Select the Add Invoice action.
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.
Select the amount field and select Amount from the Dynamic content pane.
Select Save.
Select the <- back button.
Make sure you're still in the Contoso Invoicing - Triggers solution.
Select + New > Automation > Cloud flow > Automated.
Enter Invoice Notification for Flow name and select Skip.
Select the Custom tab, and then select the Contoso invoicing custom connector.
Select the When Invoice is Created trigger.
Select + New step.
Search for compose and then select the Compose action.
Select the Inputs field and then select body from the Dynamic content pane.
Select Save.
Select Test.
Select Manually > Test. The flow will start, and you should wait for notifications.
Open a new browser window and navigate to https://make.powerapps.com/
Make sure you have the correct environment selected.
Select Solutions and open the Contoso Invoicing - Triggers
Open the Create invoice cloud flow.
Select Edit.
Select Test.
Select Manually > Test.
Select Continue.
Enter 5500 for Amount and then select Run flow.
Select Done.
Switch to the Invoice Notification flow. The flow should run successfully.
Select to expand the Compose action.
The Inputs and Outputs should show the amount that you provided in the Create invoice flow.