2017-11-30

Recently I was looking for a way to determine the list of Flow instances attached to a SharePoint List. After the recent CSOM API update, I noticed that there are now methods available to get the list of Flow instances for a given List.

The List CSOM object has the following methods:

public FlowSynchronizationResult SyncFlowInstances ();
public FlowSynchronizationResult SyncFlowTemplates ();
public FlowSynchronizationResult SyncFlowInstance (Guid flowID);

SyncFlowInstances:

This returns the list of flow instances attached to a list by the current user. “FlowSynchronizationResult” contains the status and the Json details of the flow instances attached to a list.

SyncFlowTemplates:

This returns the list of Flow templates available to a list. Similar to the above, “FlowSynchronizationResult” contains the status and the JSON details of the flow templates attached to a list.

SyncFlowInstances:

This takes the flow instances id which can be retrieved from the “SyncFlowInstances” output. The JSON contains full details of the Flow instances including the actions parameters.

Here we will see how to get a Flow instance attached to a list called “ColorList” list which sends a message to the mobile, when an item is created within the list.

Attached a sample code to get the flow instance details using the CSOM.

List document = context.Web.GetList("Lists/ColorList");
context.Load(document);context.ExecuteQuery();
var flows = document.SyncFlowInstances();
context.Load(flows);context.ExecuteQuery();
var flowTemplates = document.SyncFlowTemplates();
context.Load(flowTemplates);context.ExecuteQuery();

The above code gets the flow instances as a Json data as below. The below data contains the flow summary details like Id, Created/ Modified, Actions etc required to trigger the flow.

{"value": [{"name": "<guid>","id": "<id>","type": "Microsoft.ProcessSimple/environments/flows","properties": {"apiId": "/providers/Microsoft.PowerApps/apis/shared_logicflows",
"displayName": "Recurrence -> Collab365Azfn",
"userType": "Owner","state": "Started",
"createdTime": "2017-09-28T08:47:34.599874Z",
"lastModifiedTime": "2017-11-28T13:45:53.9885391Z",
"environment": {...},"definitionSummary": {...}....}]}

The api / method returns only the Flow(s) which are accessible by the current user. i.e. If the flow is created by the other user, SynfFlowInstances will not return the flow details unless it is set to Team Flows and shared to the current user. If the flow is shared, then the method will retrieve the flows associated as a Shared type with the “sharingType”: “Coauthor” as below.

{"value": [{
"name": "<guid>","id": "/providers/Microsoft.ProcessSimple/environments/Default-<guid>/flows/<guid>",
"type": "Microsoft.ProcessSimple/environments/flows",
"properties": {"apiId": "/providers/Microsoft.PowerApps/apis/shared_logicflows",
"displayName": "When a new item is added in SharePoint, complete a custom action",
"userType": "Owner",
"state": "Started",
"sharingType": "Coauthor",
"createdTime": "2017-11-28T17:50:30.9240286Z",
"lastModifiedTime": "2017-11-30T09:32:44.3055076Z",
"templateName": "<guid>",
"environment": {"name": "Default-7647fbf6-3cff-468d-b20f-3fdb7ae6b1ef",
"type": "Microsoft.ProcessSimple/environments",
"id": "/providers/Microsoft.ProcessSimple/environments/Default-7647fbf6-3cff-468d-b20f-3fdb7ae6b1ef"},...}}]}

Flow instance Details:

“SyncFlowInstances” gets the very high level details of the Flow instance attached. “SyncFlowInstance(<flowguid>)” returns the detailed data with all the actions and operations specified as an Open api as below.

{"name": "<guid>",
"id": "<id>",
"type": "Microsoft.ProcessSimple/environments/flows",
"properties": {..."displayName": "Recurrence -> Collab365Azfn","userType": "Owner","definition": {..."contentVersion": "1.0.0.0","parameters": {...},"triggers": {"When_a_new_item_is_created": {...}},"actions": {"Send_Azure_Notification": {"runAfter": {},"metadata": {"flowSystemMetadata": {"swaggerOperationId": "Collab365Azfn"}},"type": "ApiConnection","inputs": {"host": {"api": {"runtimeUrl": "https://europe-001.azure-apim.net/apim/sktechazurefunctionazurewebsitesnet.20.2d.201.5-84d98ba0c181b804"},"connection": {"name": "@parameters('$connections')['shared_sktechazurefunctionazurewebsitesnet.20.2d.201.5-84d98ba0c181b804']['connectionId']"}},"method": "get","path": "/api/Collab365Notification","queries": {"code": "..."},"authentication": "@parameters('$authentication')"}}},"outputs": {}},"state": "Started","connectionReferences": {"shared_sktechazurefunctionazurewebsitesnet.20.2d.201.5-...": {"connectionName": "<guid>","apiDefinition": {"name": "shared_sktechazurefunctionazurewebsitesnet.20.2d.201.5-...","id": "/providers/Microsoft.PowerApps/apis/shared_sktechazurefunctionazurewebsitesnet.20.2d.201.5-...","type": "/providers/Microsoft.PowerApps/apis","properties": {"displayName": "sktechazurefunctionazurewebsitesnet - 1","iconUri": "https://prodapiicons.cdn.powerappscdn.net/201707/customconnectoricon.jpeg","purpose": "NotSpecified","connectionParameters": {"api_key": {"type": "securestring","uiDefinition": {"displayName": "code","description": "The code for this api","tooltip": "Provide your code","constraints": {"required": "true"}}}},"runtimeUrls": ["https://europe-001.azure-apim.net/apim/sktechazurefunctionazurewebsitesnet.20.2d.201.5-84d98ba0c181b804","http://europe-001.azure-apim.net/apim/sktechazurefunctionazurewebsitesnet.20.2d.201.5-84d98ba0c181b804"],"primaryRuntimeUrl": "https://europe-001.azure-apim.net/apim/sktechazurefunctionazurewebsitesnet.20.2d.201.5-84d98ba0c181b804","metadata": {"source": "powerapps-user-defined","brandColor": "#00ff00","environmentName": "Default-87dd3c54-0668-46db-96f0-e4b67cc3638f","createdBy": "{\\"id\\":\\"065868eb-f08f-4a82-9786-690bc5c38fce\\",\\"displayName\\":\\"Balamurugan Kailasam\\",\\"email\\":\\"kshsbala@sktechnologies.onmicrosoft.com\\",\\"type\\":\\"User\\",\\"tenantId\\":\\"87dd3c54-0668-46db-96f0-e4b67cc3638f\\",\\"userPrincipalName\\":\\"kshsbala@sktechnologies.onmicrosoft.com\\"}","modifiedBy": "{\\"id\\":\\"065868eb-f08f-4a82-9786-690bc5c38fce\\",\\"displayName\\":\\"Balamurugan Kailasam\\",\\"email\\":\\"kshsbala@sktechnologies.onmicrosoft.com\\",\\"type\\":\\"User\\",\\"tenantId\\":\\"87dd3c54-0668-46db-96f0-e4b67cc3638f\\",\\"userPrincipalName\\":\\"kshsbala@sktechnologies.onmicrosoft.com\\"}"},"capabilities": ["actions"],"tier": "NotSpecified","createdTime": "2017-07-09T18:22:20.4581862Z","changedTime": "2017-11-03T21:25:40.5696915Z"}},"source": "Embedded","id": "/providers/Microsoft.PowerApps/apis/shared_sktechazurefunctionazurewebsitesnet.20.2d.201.5-84d98ba0c181b804","displayName": "sktechazurefunctionazurewebsitesnet - 1","iconUri": "https://prodapiicons.cdn.powerappscdn.net/20170709t000000zfbee329ca56942a787977c3d86318061/customconnectoricon.jpeg","brandColor": "#00ff00","swagger": {"swagger": "2.0","info": {"title": "sktechazurefunction.azurewebsites.net","version": "1.0.0"},"host": "europe-001.azure-apim.net","basePath": "/apim/sktechazurefunctionazurewebsitesnet.20.2d.201.5-84d98ba0c181b804","schemes": ["https"],"consumes": [],"produces": [],"paths": {"/{connectionId}/api/Collab365Notification": {"get": {"operationId": "Collab365Azfn","parameters": [{"name": "connectionId","in": "path","required": true,"type": "string","x-ms-visibility": "internal"},{"name": "code","in": "query","required": true,"type": "string","description": "code","x-ms-summary": "code","default": "<authcode>"}],"description": "Azure Notification Hub","responses": {"200": {"description": "Success operation"}},"security": [{"apikeyQuery": []}],"summary": "Send Azure Notification"}}},"definitions": {},"parameters": {},"responses": {},"securityDefinitions": {"apikeyQuery": {"type": "apiKey","name": "code","in": "query"}},"security": [],"tags": []},"tier": "NotSpecified"}...}}}

The above section displays the custom flow details created to send a mobile message, when an item is created on a list. More details about creating a custom connection for an Azure function can be found here.

There is an equivalent version of rest api is also available to query about the flow attached to a list.

  • https://<tenant>.sharepoint.com/_api/web/GetList(@a1)/SyncFlowTemplates?@a1=%27%2FLists%2FFlowTest%27
    • Method: Post
  • https://<tenant>.sharepoint.com/_api/web/GetList(@a1)/SyncFlowInstances?@a1=%27%2FLists%2FFlowTest%27
    • Method: Post

About the author 

Balamurugan Kailasam