Last active
June 6, 2018 15:53
-
-
Save zplume/bfa0a48d942f16dea92a2c475198e9ec to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#", | |
"contentVersion": "1.0.0.0", | |
"parameters": { | |
"$connections": { | |
"defaultValue": {}, | |
"type": "Object" | |
}, | |
"$authentication": { | |
"defaultValue": {}, | |
"type": "SecureObject" | |
} | |
}, | |
"triggers": { | |
"manual": { | |
"type": "Request", | |
"kind": "Button", | |
"inputs": { | |
"schema": { | |
"type": "object", | |
"required": [], | |
"properties": {} | |
} | |
} | |
} | |
}, | |
"actions": { | |
"Get_list_changes": { | |
"runAfter": { | |
"Set_Change_token_start": ["Succeeded"] | |
}, | |
"metadata": { | |
"flowSystemMetadata": { | |
"swaggerOperationId": "HttpRequest" | |
} | |
}, | |
"type": "ApiConnection", | |
"inputs": { | |
"host": { | |
"api": { | |
"runtimeUrl": "https://europe-001.azure-apim.net/apim/sharepointonline" | |
}, | |
"connection": { | |
"name": "@json(decodeBase64(triggerOutputs().headers['X-MS-APIM-Tokens']))['$connections']['shared_sharepointonline']['connectionId']" | |
} | |
}, | |
"method": "post", | |
"body": { | |
"method": "POST", | |
"uri": "_api/web/lists(guid'62f3e702-edd9-4a87-a469-60bb76c0784c')/getchanges?$select=ItemId,ChangeType,Time,ChangeToken&$top=500", | |
"headers": { | |
"Accept": "application/json; odata=nometadata", | |
"Content-Type": "application/json" | |
}, | |
"body": "{\n \"query\": {\n \"Add\": \"True\",\n \"Update\": \"True\",\n \"SystemUpdate\": \"False\",\n \"DeleteObject\": \"False\",\n \"Move\": \"False\",\n \"Rename\": \"False\",\n \"Restore\": \"False\",\n \"Item\": \"True\",\n \"ChangeTokenStart\": @{if(empty(body('Get_Change_token_start_from_property_bag')), 'null', variables('ChangeTokenStart'))}\n }\n}" | |
}, | |
"path": "/datasets/@{encodeURIComponent(encodeURIComponent('https://tenant.sharepoint.com/sites/Flow'))}/httprequest", | |
"authentication": { | |
"type": "Raw", | |
"value": "@json(decodeBase64(triggerOutputs().headers['X-MS-APIM-Tokens']))['$ConnectionKey']" | |
} | |
} | |
}, | |
"Select_ID_ChangeToken_and_ChangeType": { | |
"runAfter": { | |
"Parse_Get_list_changes_response": ["Succeeded"] | |
}, | |
"type": "Select", | |
"inputs": { | |
"from": "@body('Parse_Get_list_changes_response')?['value']", | |
"select": { | |
"ID": "@item()['ItemId']", | |
"ChangeToken": "@item()['ChangeToken']['StringValue']", | |
"ChangeType": "@outputs('Set_ChangeType')[item()['ChangeType']]" | |
} | |
}, | |
"description": "Retrieve ChangeType label from ChangeType enum string array using outputs('Set_ChangeType')[item()['ChangeType']]" | |
}, | |
"Parse_Get_list_changes_response": { | |
"runAfter": { | |
"Get_list_changes": ["Succeeded"] | |
}, | |
"type": "ParseJson", | |
"inputs": { | |
"content": "@body('Get_list_changes')", | |
"schema": { | |
"type": "object", | |
"properties": { | |
"value": { | |
"type": "array", | |
"items": { | |
"type": "object", | |
"properties": { | |
"ChangeToken": { | |
"type": "object", | |
"properties": { | |
"StringValue": { | |
"type": "string" | |
} | |
} | |
}, | |
"ChangeType": { | |
"type": "number" | |
}, | |
"Time": { | |
"type": "string" | |
}, | |
"ItemId": { | |
"type": "number" | |
} | |
}, | |
"required": ["ChangeToken", "ChangeType", "Time", "ItemId"] | |
} | |
} | |
} | |
} | |
} | |
}, | |
"Load_items": { | |
"foreach": "@variables('IDs')", | |
"actions": { | |
"Get_item": { | |
"runAfter": {}, | |
"metadata": { | |
"flowSystemMetadata": { | |
"swaggerOperationId": "HttpRequest" | |
} | |
}, | |
"type": "ApiConnection", | |
"inputs": { | |
"host": { | |
"api": { | |
"runtimeUrl": "https://europe-001.azure-apim.net/apim/sharepointonline" | |
}, | |
"connection": { | |
"name": "@json(decodeBase64(triggerOutputs().headers['X-MS-APIM-Tokens']))['$connections']['shared_sharepointonline']['connectionId']" | |
} | |
}, | |
"method": "post", | |
"body": { | |
"method": "GET", | |
"uri": "_api/web/lists(guid'62f3e702-edd9-4a87-a469-60bb76c0784c')/items?$filter=ID eq @{items('Load_items')}", | |
"headers": { | |
"Accept": "application/json; odata=nometadata" | |
} | |
}, | |
"path": "/datasets/@{encodeURIComponent(encodeURIComponent('https://tenant.sharepoint.com/sites/Flow'))}/httprequest", | |
"authentication": { | |
"type": "Raw", | |
"value": "@json(decodeBase64(triggerOutputs().headers['X-MS-APIM-Tokens']))['$ConnectionKey']" | |
} | |
} | |
}, | |
"If_item_exists": { | |
"actions": { | |
"Append_to_array_variable": { | |
"runAfter": {}, | |
"type": "AppendToArrayVariable", | |
"inputs": { | |
"name": "Items", | |
"value": "@body('Get_item')?.value[0]" | |
}, | |
"description": "body('Get_item')?.value[0]" | |
} | |
}, | |
"runAfter": { | |
"Get_item": ["Succeeded"] | |
}, | |
"expression": "@greater(length(body('Get_item').value), 0)", | |
"type": "If", | |
"description": "length(body('Get_item').value)" | |
} | |
}, | |
"runAfter": { | |
"Set_IDs": ["Succeeded"] | |
}, | |
"type": "Foreach" | |
}, | |
"Set_Items": { | |
"runAfter": { | |
"Exit_if_there_are_no_changes_to_process": ["Succeeded"] | |
}, | |
"type": "InitializeVariable", | |
"inputs": { | |
"variables": [{ | |
"name": "Items", | |
"type": "Array" | |
}] | |
} | |
}, | |
"Set_Last_change_token": { | |
"runAfter": { | |
"Log_items": ["Succeeded"] | |
}, | |
"type": "InitializeVariable", | |
"inputs": { | |
"variables": [{ | |
"name": "LastChangeToken", | |
"type": "String", | |
"value": "@{last(body('Select_ID_ChangeToken_and_ChangeType')).ChangeToken}" | |
}] | |
}, | |
"description": "last(body('Select_ID_ChangeToken_and_ChangeType')).ChangeToken" | |
}, | |
"Set_ChangeType": { | |
"runAfter": {}, | |
"type": "Compose", | |
"inputs": ["NoChange", "Add", "Update", "DeleteObject", "Rename", "MoveAway", "MoveInto", "Restore", "RoleAdd", "RoleDelete", "RoleUpdate", "AssignmentAdd", "AssignmentDelete", "MemberAdd", "MemberDelete", "SystemUpdate", "Navigation", "ScopeAdd", "ScopeDelete", "ListContentTypeAdd", "ListContentTypeDelete", "Dirty", "Activity"] | |
}, | |
"Log_items": { | |
"runAfter": { | |
"Load_items": ["Succeeded"] | |
}, | |
"type": "Compose", | |
"inputs": "@variables('Items')" | |
}, | |
"Set_Change_token_start": { | |
"runAfter": { | |
"Get_Change_token_start_from_property_bag": ["Succeeded"] | |
}, | |
"type": "InitializeVariable", | |
"inputs": { | |
"variables": [{ | |
"name": "ChangeTokenStart", | |
"type": "Object", | |
"value": { | |
"StringValue": "@body('Get_Change_token_start_from_property_bag')?['ChangeQueryFlow_x005f_LastChangeToken']" | |
} | |
}] | |
} | |
}, | |
"Get_Change_token_start_from_property_bag": { | |
"runAfter": { | |
"Set_ChangeType": ["Succeeded"] | |
}, | |
"metadata": { | |
"flowSystemMetadata": { | |
"swaggerOperationId": "HttpRequest" | |
} | |
}, | |
"type": "ApiConnection", | |
"inputs": { | |
"host": { | |
"api": { | |
"runtimeUrl": "https://europe-001.azure-apim.net/apim/sharepointonline" | |
}, | |
"connection": { | |
"name": "@json(decodeBase64(triggerOutputs().headers['X-MS-APIM-Tokens']))['$connections']['shared_sharepointonline']['connectionId']" | |
} | |
}, | |
"method": "post", | |
"body": { | |
"method": "GET", | |
"uri": "_api/web/lists/getById('62f3e702-edd9-4a87-a469-60bb76c0784c')/RootFolder/Properties?$select=ChangeQueryFlow_LastChangeToken", | |
"headers": { | |
"Accept": "application/json; odata=nometadata" | |
} | |
}, | |
"path": "/datasets/@{encodeURIComponent(encodeURIComponent('https://tenant.sharepoint.com/sites/Flow'))}/httprequest", | |
"authentication": { | |
"type": "Raw", | |
"value": "@json(decodeBase64(triggerOutputs().headers['X-MS-APIM-Tokens']))['$ConnectionKey']" | |
} | |
} | |
}, | |
"Get_site_ID": { | |
"runAfter": { | |
"Set_Last_change_token": ["Succeeded"] | |
}, | |
"metadata": { | |
"flowSystemMetadata": { | |
"swaggerOperationId": "HttpRequest" | |
} | |
}, | |
"type": "ApiConnection", | |
"inputs": { | |
"host": { | |
"api": { | |
"runtimeUrl": "https://europe-001.azure-apim.net/apim/sharepointonline" | |
}, | |
"connection": { | |
"name": "@json(decodeBase64(triggerOutputs().headers['X-MS-APIM-Tokens']))['$connections']['shared_sharepointonline']['connectionId']" | |
} | |
}, | |
"method": "post", | |
"body": { | |
"method": "GET", | |
"uri": "_api/site?$select=id", | |
"headers": { | |
"Accept": "application/json; odata=nometadata" | |
} | |
}, | |
"path": "/datasets/@{encodeURIComponent(encodeURIComponent('https://tenant.sharepoint.com/sites/Flow'))}/httprequest", | |
"authentication": { | |
"type": "Raw", | |
"value": "@json(decodeBase64(triggerOutputs().headers['X-MS-APIM-Tokens']))['$ConnectionKey']" | |
} | |
} | |
}, | |
"Get_web_ID": { | |
"runAfter": { | |
"Set_Last_change_token": ["Succeeded"] | |
}, | |
"metadata": { | |
"flowSystemMetadata": { | |
"swaggerOperationId": "HttpRequest" | |
} | |
}, | |
"type": "ApiConnection", | |
"inputs": { | |
"host": { | |
"api": { | |
"runtimeUrl": "https://europe-001.azure-apim.net/apim/sharepointonline" | |
}, | |
"connection": { | |
"name": "@json(decodeBase64(triggerOutputs().headers['X-MS-APIM-Tokens']))['$connections']['shared_sharepointonline']['connectionId']" | |
} | |
}, | |
"method": "post", | |
"body": { | |
"method": "GET", | |
"uri": "_api/web?$select=id", | |
"headers": { | |
"Accept": "application/json; odata=nometadata" | |
} | |
}, | |
"path": "/datasets/@{encodeURIComponent(encodeURIComponent('https://tenant.sharepoint.com/sites/Flow'))}/httprequest", | |
"authentication": { | |
"type": "Raw", | |
"value": "@json(decodeBase64(triggerOutputs().headers['X-MS-APIM-Tokens']))['$ConnectionKey']" | |
} | |
} | |
}, | |
"Get_folder_ID": { | |
"runAfter": { | |
"Set_Last_change_token": ["Succeeded"] | |
}, | |
"metadata": { | |
"flowSystemMetadata": { | |
"swaggerOperationId": "HttpRequest" | |
} | |
}, | |
"type": "ApiConnection", | |
"inputs": { | |
"host": { | |
"api": { | |
"runtimeUrl": "https://europe-001.azure-apim.net/apim/sharepointonline" | |
}, | |
"connection": { | |
"name": "@json(decodeBase64(triggerOutputs().headers['X-MS-APIM-Tokens']))['$connections']['shared_sharepointonline']['connectionId']" | |
} | |
}, | |
"method": "post", | |
"body": { | |
"method": "GET", | |
"uri": "_api/web/lists/getById('62f3e702-edd9-4a87-a469-60bb76c0784c')/RootFolder?$select=uniqueId", | |
"headers": { | |
"Accept": "application/json; odata=nometadata" | |
} | |
}, | |
"path": "/datasets/@{encodeURIComponent(encodeURIComponent('https://tenant.sharepoint.com/sites/Flow'))}/httprequest", | |
"authentication": { | |
"type": "Raw", | |
"value": "@json(decodeBase64(triggerOutputs().headers['X-MS-APIM-Tokens']))['$ConnectionKey']" | |
} | |
} | |
}, | |
"Set_Change_token_start_property_bag_value": { | |
"runAfter": { | |
"Parse_Get_site_ID": ["Succeeded"], | |
"Parse_Get_web_ID": ["Succeeded"], | |
"Parse_Get_folder_ID": ["Succeeded"] | |
}, | |
"metadata": { | |
"flowSystemMetadata": { | |
"swaggerOperationId": "HttpRequest" | |
} | |
}, | |
"type": "ApiConnection", | |
"inputs": { | |
"host": { | |
"api": { | |
"runtimeUrl": "https://europe-001.azure-apim.net/apim/sharepointonline" | |
}, | |
"connection": { | |
"name": "@json(decodeBase64(triggerOutputs().headers['X-MS-APIM-Tokens']))['$connections']['shared_sharepointonline']['connectionId']" | |
} | |
}, | |
"method": "post", | |
"body": { | |
"method": "POST", | |
"uri": "_vti_bin/client.svc/ProcessQuery", | |
"headers": { | |
"Content-Type": "text/xml" | |
}, | |
"body": "<Request AddExpandoFieldTypeSuffix=\"true\" SchemaVersion=\"15.0.0.0\" LibraryVersion=\"16.0.0.0\" ApplicationName=\"SharePoint PnP PowerShell Library\" \n xmlns=\"http://schemas.microsoft.com/sharepoint/clientquery/2009\">\n <Actions>\n <Method Name=\"SetFieldValue\" Id=\"42\" ObjectPathId=\"37\">\n <Parameters>\n <Parameter Type=\"String\">ChangeQueryFlow_LastChangeToken</Parameter>\n <Parameter Type=\"String\">@{variables('LastChangeToken')}</Parameter>\n </Parameters>\n </Method>\n <Method Name=\"Update\" Id=\"43\" ObjectPathId=\"27\" />\n</Actions>\n <ObjectPaths>\n <Property Id=\"37\" ParentId=\"27\" Name=\"Properties\" />\n <Identity Id=\"27\" Name=\"ab8c6d9e-3059-5000-c7a7-1c96cb3c9e84|740c6a0b-85e2-48a0-a494-e0f1759d4aa7:site:@{body('Parse_Get_site_ID')?['Id']}:web:@{body('Parse_Get_web_ID')?['Id']}:folder:@{body('Parse_Get_folder_ID')?['UniqueId']}\" />\n</ObjectPaths>\n</Request>" | |
}, | |
"path": "/datasets/@{encodeURIComponent(encodeURIComponent('https://tenant.sharepoint.com/sites/Flow'))}/httprequest", | |
"authentication": { | |
"type": "Raw", | |
"value": "@json(decodeBase64(triggerOutputs().headers['X-MS-APIM-Tokens']))['$ConnectionKey']" | |
} | |
} | |
}, | |
"Parse_Get_site_ID": { | |
"runAfter": { | |
"Get_site_ID": ["Succeeded"] | |
}, | |
"type": "ParseJson", | |
"inputs": { | |
"content": "@body('Get_site_ID')", | |
"schema": { | |
"type": "object", | |
"properties": { | |
"Id": { | |
"type": "string" | |
} | |
} | |
} | |
} | |
}, | |
"Parse_Get_web_ID": { | |
"runAfter": { | |
"Get_web_ID": ["Succeeded"] | |
}, | |
"type": "ParseJson", | |
"inputs": { | |
"content": "@body('Get_web_ID')", | |
"schema": { | |
"type": "object", | |
"properties": { | |
"Id": { | |
"type": "string" | |
} | |
} | |
} | |
} | |
}, | |
"Parse_Get_folder_ID": { | |
"runAfter": { | |
"Get_folder_ID": ["Succeeded"] | |
}, | |
"type": "ParseJson", | |
"inputs": { | |
"content": "@body('Get_folder_ID')", | |
"schema": { | |
"type": "object", | |
"properties": { | |
"UniqueId": { | |
"type": "string" | |
} | |
} | |
} | |
} | |
}, | |
"Parse_Set_property_bag_value_response": { | |
"runAfter": { | |
"Set_Change_token_start_property_bag_value": ["Succeeded"] | |
}, | |
"type": "ParseJson", | |
"inputs": { | |
"content": "@body('Set_Change_token_start_property_bag_value')", | |
"schema": { | |
"type": "array", | |
"items": { | |
"type": "object", | |
"properties": { | |
"SchemaVersion": { | |
"type": "string" | |
}, | |
"LibraryVersion": { | |
"type": "string" | |
}, | |
"ErrorInfo": { | |
"type": ["object", "null"], | |
"properties": { | |
"ErrorMessage": { | |
"type": "string" | |
}, | |
"ErrorValue": {}, | |
"TraceCorrelationId": { | |
"type": "string" | |
}, | |
"ErrorCode": { | |
"type": "number" | |
}, | |
"ErrorTypeName": { | |
"type": "string" | |
} | |
} | |
}, | |
"TraceCorrelationId": { | |
"type": "string" | |
} | |
}, | |
"required": ["SchemaVersion", "LibraryVersion", "ErrorInfo", "TraceCorrelationId"] | |
} | |
} | |
} | |
}, | |
"Handle_error": { | |
"actions": {}, | |
"runAfter": { | |
"Get_error_message": ["Succeeded"] | |
}, | |
"else": { | |
"actions": { | |
"Terminate": { | |
"runAfter": {}, | |
"type": "Terminate", | |
"inputs": { | |
"runStatus": "Failed", | |
"runError": { | |
"code": "500", | |
"message": "@{variables('Set property bag error')}" | |
} | |
} | |
} | |
} | |
}, | |
"expression": "@equals(variables('Set property bag error'), '')", | |
"type": "If" | |
}, | |
"Get_error_message": { | |
"runAfter": { | |
"Parse_Set_property_bag_value_response": ["Succeeded"] | |
}, | |
"type": "InitializeVariable", | |
"inputs": { | |
"variables": [{ | |
"name": "Set property bag error", | |
"type": "String", | |
"value": "@{body('Parse_Set_property_bag_value_response')[0].ErrorInfo?.ErrorMessage}" | |
}] | |
} | |
}, | |
"Set_IDs": { | |
"runAfter": { | |
"Select_IDs": ["Succeeded"] | |
}, | |
"type": "InitializeVariable", | |
"inputs": { | |
"variables": [{ | |
"name": "IDs", | |
"type": "Array", | |
"value": "@union(body('Select_IDs'), body('Select_IDs'))" | |
}] | |
}, | |
"description": "union(body('Select_IDs'), body('Select_IDs')) removes duplicates" | |
}, | |
"Exit_if_there_are_no_changes_to_process": { | |
"actions": { | |
"No_changes_to_process": { | |
"runAfter": {}, | |
"type": "Terminate", | |
"inputs": { | |
"runStatus": "Succeeded" | |
} | |
} | |
}, | |
"runAfter": { | |
"Select_ID_ChangeToken_and_ChangeType": ["Succeeded"] | |
}, | |
"expression": "@equals(length(body('Select_ID_ChangeToken_and_ChangeType')), 0)", | |
"type": "If", | |
"description": "length(body('Select_ID_ChangeToken_and_ChangeType'))" | |
}, | |
"Select_IDs": { | |
"runAfter": { | |
"Set_Items": ["Succeeded"] | |
}, | |
"type": "Select", | |
"inputs": { | |
"from": "@body('Select_ID_ChangeToken_and_ChangeType')", | |
"select": "@item().ID" | |
}, | |
"description": "item().ID" | |
} | |
}, | |
"outputs": {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment