MG

Custom Connectors- Get Flow Runs History

Advertisements

This is my first attempt to work on custom connectors and on this first attempt , I will be using OpenAPI definition to create the custom connector.

Step 1: App registration

  1. Login to Portal.azure.com
  2. Click on Azure Active Directory on the Home Page

3. Click on App Registration-> New App Registration

Create New App Registration

4. Enter App Name and Click Register

5. Click on API Permissions

Add Flow Service

6. Select Below Permissions and Click Add Permissions

7. Grant Consent and Move to step 2

Step 2: Creating the Connector via Swagger File

  1. Login to make.powerapps.com
  2. On the left side Expand Data -> Custom Connectors -> New Custom Connector

3. And I will choose Import an OpenAPI File as I will be using the Swagger file used in this link https://2die4it.com/swagger-file-for-custom-connector-get-flow-runs/ to get the flow runs history.

4. Add the Connector Name and Choose the Swagger JSON file and Click Continue.

JSON Code:

{
  "swagger": "2.0",
  "info": {
    "title": "Flow Runs",
    "description": "",
    "version": "1.0"
  },
  "host": "emea.api.flow.microsoft.com",
  "basePath": "/",
  "schemes": [
    "https"
  ],
  "consumes": [],
  "produces": [],
  "paths": {
    "/providers/Microsoft.ProcessSimple/environments/{environment_name}/flows/{flow_name}/runs": {
      "get": {
        "responses": {
          "default": {
            "description": "default",
            "schema": {}
          }
        },
        "summary": "Get Flow Runs",
        "description": "Get run history of specified flow in specified environment",
        "operationId": "GetFlowRuns",
        "x-ms-visibility": "important",
        "parameters": [
          {
            "name": "environment_name",
            "in": "path",
            "required": true,
            "type": "string",
            "default": "Default-82e5f1fb-9ffd-49c1-b0e1-1aae52374ff1",
            "x-ms-visibility": "important",
            "description": "Environment ID"
          },
          {
            "name": "flow_name",
            "in": "path",
            "required": true,
            "type": "string",
            "default": "39190573-dbe9-40a2-a99f-183bb2a3fd31",
            "x-ms-visibility": "important",
            "description": "Flow ID"
          },
          {
            "name": "api-version",
            "in": "query",
            "required": true,
            "type": "string",
            "default": "2016-11-01"
          }
        ]
      }
    }
  },
  "definitions": {},
  "parameters": {},
  "responses": {},
  "securityDefinitions": {
    "undefined": {
      "type": "oauth2",
      "flow": "accessCode",
      "authorizationUrl": "https://login.windows.net/common/oauth2/authorize",
      "tokenUrl": "https://login.windows.net/common/oauth2/authorize",
      "scopes": {}
    }
  },
  "security": [
    {
      "undefined": []
    }
  ],
  "tags": []
}

5. On the General Tab; you can change connector Icon, Background Color and Description

6. On the Security Tab , enter the client Id, Client Secret from the app you have registered and Resource URL:https://service.flow.microsoft.com/

Note: Copy the redirect URL after Creating the connector

7. On the Definition Tab you can see the URL and the Parameters which is environment name and flow_name and api-version

8. Then Click Create Connector, and you will get a validation success message as below

9. Then Test the connector , and I tried to create a connection but got the below error:

AADSTS500113: No reply address is registered for the application.

After a little bit of search , I went back to Azure Portal-> open my app registration -> Authentication and clicked Add Platform.

Note: The RedirectURI / Reply URL is required by AAD, so that AAD knows where to post the token back so that the app can pick that token up and use it. Hence you need to specify the correct Redirect URI for your application as from where the app can pick the Access_token and use it further.

10. Add Platform->Choose web-> And paste the Redirect URL I have copied in step 6 above, checked Access Tokens and ID Tokens and Access Tokens would be fair enough.

11. Then I went back to my Custom Connector and Retested the connection and it worked like charm.

12.To Continue with the Testing operation , I have added my environment URL and flow_id and Clicked Test Operation and WAW I can get it working and returning data as below:

Below is a sample of how the response looks and what information we got get from the Flow run history.

Name: This is the Flow Run ID

Id: Provide full URL so if we need to keep a direct link to the Flow run to troubleshoot or see what what the issue.

Status: Failed /Succeeded

StartTime/EndTime

Also we have Trigger information

{
      "name": "08585812450273045760418259003CU08",
      "id": "/providers/Microsoft.ProcessSimple/environments/Default-d5c6aa48-44f7-4364-b5df-421c3c29eba6/flows/0aa0fd02-4e8e-4ddd-9622-f0b318e07beb/runs/08585812450273045760418259003CU08",
      "type": "Microsoft.ProcessSimple/environments/flows/runs",
      "properties": {
        "startTime": "2021-05-07T04:30:58.173606Z",
        "endTime": "2021-05-07T04:30:58.7915001Z",
        "status": "Failed",
        "code": "ActionFailed",
        "error": {
          "code": "ActionFailed",
          "message": "An action failed. No dependent actions succeeded."
        },
        "correlation": {
          "clientTrackingId": "08585812454156150713973380691CU13",
          "clientKeywords": [
            "testFlow"
          ]
        },
        "trigger": {
          "name": "manual",
          "inputsLink": {
            "uri": "https://prod-21.australiasoutheast.logic.azure.com:443/workflows/f4671e72b1b3408abfa2093a7411b8d3/runs/08585812450273045760418259003CU08/contents/TriggerInputs?api-version=2016-06-01&se=2021-05-08T14%3A00%3A00.0000000Z&sp=%2Fruns%2F08585812450273045760418259003CU08%2Fcontents%2FTriggerInputs%2Fread&sv=1.0&sig=e4HMxhjrjCJ_xaRGuF9bb3f4csg67Bk4eeeqMC6dKHM",
            "contentVersion": "/T5WXAj3fj0rTPrCL3IKcg==",
            "contentSize": 58,
            "contentHash": {
              "algorithm": "md5",
              "value": "/T5WXAj3fj0rTPrCL3IKcg=="
            }
          },
          "outputsLink": {
            "uri": "https://prod-21.australiasoutheast.logic.azure.com:443/workflows/f4671e72b1b3408abfa2093a7411b8d3/runs/08585812450273045760418259003CU08/contents/TriggerOutputs?api-version=2016-06-01&se=2021-05-08T14%3A00%3A00.0000000Z&sp=%2Fruns%2F08585812450273045760418259003CU08%2Fcontents%2FTriggerOutputs%2Fread&sv=1.0&sig=wJj7FmHeLzvI97c6D2GqLa6hYbJQ6p6q2-D6goXszt0",
            "contentVersion": "2I19zwGytSu9/VJ0Gv6xAA==",
            "contentSize": 5036,
            "contentHash": {
              "algorithm": "md5",
              "value": "2I19zwGytSu9/VJ0Gv6xAA=="
            }
          },
          "startTime": "2021-05-07T04:30:58.1383618Z",
          "endTime": "2021-05-07T04:30:58.1383618Z",
          "originHistoryName": "08585812450273045760418259003CU08",
          "sourceHistoryName": "08585812451333528861412126527CU28",
          "correlation": {
            "clientTrackingId": "08585812454156150713973380691CU13",
            "clientKeywords": [
              "testFlow"
            ]
          },
          "status": "Succeeded"
        }
      }
    }

References :

https://docs.microsoft.com/en-us/connectors/custom-connectors/define-blank

Thanks to stefan for his blog article which I have followed to create the custom connector/

https://community.dynamics.com/365/b/theressomethingaboutdynamics365/posts/custom-connector-to-get-flow-run-history

Advertisements

Advertisements