Exercise - Implement a polling trigger

Completed

In this exercise, you'll add a polling 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.

Task 1: Import the solution with the custom connector

Note

You can continue using the connector that you created and modified in Unit 4: Implement a webhook trigger. If you completed that exercise, you can skip ahead to Task 2.

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.

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.

  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. 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 component highlighted.

  9. Go to Contoso Invoicing.

  10. Select the API Key link.

    Screenshot of the API key link highlighted.

  11. Copy the API Key and then paste it on a notepad for future use.

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

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

  14. 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 in Host.

  17. Select Update connector.

  18. Select Test > + New Connector.

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

  19. Paste the API Key and then 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 ListInvoice, 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 polling trigger

If you skipped the prior task, go to your Contoso invoicing triggers custom connector and select Edit.

  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 (Poll)

    • Description - When Invoice is Created (Poll)

    • Operation ID - InvoiceCreatedPoll

    • Trigger type - Polling

    Screenshot of the connector trigger properties.

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

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

  5. Enter the following values and then select Import.

    • Verb - GET

    • URL - https://contosoinvoicing.azurewebsites.net/ListInvoices?fromDate=

  6. Select the ellipsis the chevron button next to fromDate and then select Edit.

    Screenshot of an arrow pointing to the edit query button.

  7. Select internal for Visibility and then select the Back button.

    Screenshot of parameter visibility option set to internal.

  8. Scroll down to the Response section and select + Add default response.

  9. Paste the following JSON code in the Body field and then select Import.

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

    Screenshot of the import default response.

  10. Go to the Trigger configuration section and provide the following values:

    • Select query parameter to monitor state change - fromDate

    • Specify value to pass to selected query parameter. You may choose expressions - @{triggerBody().invoices[0].createDate}

    • Select collection that contains trigger data - @triggerBody().invoices

    Screenshot of the Trigger configuration section with values.

  11. Select the Update connector button located at the top of the screen, and then wait for the connector to be updated.

Task 3: Test the trigger

If you have already completed Unit 4: Implement a webhook trigger and have created the Create invoice cloud flow, skip ahead to step 14.

  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 > Cloud flow.

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

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

  5. 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, and then select Create.

    Screenshot of the creation connection button.

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

    Screenshot of the amount field output from the previous step.

  12. Select Save.

  13. Keep this browser tab or window open.

  14. Start a new browser window and navigate to https://make.powerapps.com/

  15. Make sure you have the correct environment selected.

  16. Select Solutions and open the Contoso Invoicing - Triggers solutions.

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

  18. Enter Invoice notification poll for the name and select Skip.

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

    Screenshot of an arrow pointing to the custom connector trigger.

  20. Select the When Invoice is Created (Poll) trigger.

    Screenshot of an arrow pointing to a custom connector trigger.

  21. Select the ... Menu button of the trigger and then make sure that Connection references is selected.

    Screenshot of the Connection references section.

  22. Select + New step.

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

  24. 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.

  25. Select Save and then wait for the flow to be saved.

  26. Select Test.

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

  28. Switch to the Create invoice flow browser tab or window.

  29. Select Test.

  30. Select Manually > Test.

  31. Enter 6500 for Amount and then select Run flow.

  32. Select Done.

  33. The flow should run successfully. Select Edit.

    Screenshot of successful flow with edit icon.

  34. Select Test again.

  35. Select Manually > Test.

  36. Enter 8800 for Amount and then select Run flow.

  37. Select Done. The flow should run successfully again.

  38. Switch to the Invoice notification poll flow. This flow should run successfully.

    Note

    Unlike a webhook trigger, it might take about a minute to find out if the flow ran successfully or not.

  39. Select to expand the Compose action step.

    Screenshot of an arrow pointing to the compose flow action.

  40. Review the Outputs and then select the button.

    Screenshot of the compose flow action outputs.

    You should see two run results for the two invoices that you created.

    Screenshot of the flow run history details.