Skip to content

Instantly share code, notes, and snippets.

@bumbu
Created July 23, 2018 21:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bumbu/1cda244cdc386e9248d95ffa2ca3a890 to your computer and use it in GitHub Desktop.
Save bumbu/1cda244cdc386e9248d95ffa2ca3a890 to your computer and use it in GitHub Desktop.
Microsoft flow for Todoist (changing the priority of next item in a project when a task is completed)
{
"$schema":"https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion":"1.0.0.0",
"parameters":{
"logicAppName":{
"type":"String",
"metadata":{
"description":"Name of the logic app."
}
},
"logicAppLocation":{
"defaultValue":"[resourceGroup().location]",
"allowedValues":[
"eastasia",
"southeastasia",
"centralus",
"eastus",
"eastus2",
"westus",
"northcentralus",
"southcentralus",
"northeurope",
"westeurope",
"japanwest",
"japaneast",
"brazilsouth",
"australiaeast",
"australiasoutheast",
"southindia",
"centralindia",
"westindia",
"canadacentral",
"canadaeast",
"westcentralus",
"westus2",
"[resourceGroup().location]"
],
"type":"String",
"metadata":{
"description":"Location of the logic app."
}
},
"todoist_Connection_Name":{
"defaultValue":"todoist",
"type":"String",
"metadata":{
"description":"Name of the connection."
}
}
},
"resources":[
{
"type":"Microsoft.Logic/workflows",
"name":"[parameters('logicAppName')]",
"apiVersion":"2016-06-01",
"location":"[parameters('logicAppLocation')]",
"properties":{
"state":"Disabled",
"definition":{
"$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":{
"When_a_task_is_completed":{
"recurrence":{
"interval":15,
"frequency":"Second"
},
"splitOn":"@triggerBody()?.items",
"metadata":{
"flowSystemMetadata":{
"swaggerOperationId":"OnItemCompleted"
}
},
"type":"ApiConnection",
"inputs":{
"host":{
"connection":{
"name":"@parameters('$connections')['todoist']['connectionId']"
}
},
"method":"get",
"path":"/trigger/completed/get_all",
"queries":{
"project_id":"1"
},
"authentication":"@parameters('$authentication')"
}
}
},
"actions":{
"Initialize_variable":{
"runAfter":{
"Parse_JSON":[
"Succeeded"
]
},
"type":"InitializeVariable",
"inputs":{
"variables":[
{
"name":"projectId",
"type":"String",
"value":"@body('Parse_JSON')?['project_id']"
}
]
}
},
"Parse_JSON":{
"runAfter":{
},
"type":"ParseJson",
"inputs":{
"content":"@triggerBody()",
"schema":{
"type":"object",
"properties":{
"content":{
"type":"string"
},
"meta_data":{
},
"user_id":{
"type":"number"
},
"task_id":{
"type":"number"
},
"project_id":{
"type":"string"
},
"completed_date":{
"type":"string"
},
"id":{
"type":"string"
}
}
}
}
},
"List_projects":{
"runAfter":{
"Initialize_variable_2":[
"Succeeded"
]
},
"metadata":{
"flowSystemMetadata":{
"swaggerOperationId":"ListProjects"
}
},
"type":"ApiConnection",
"inputs":{
"host":{
"connection":{
"name":"@parameters('$connections')['todoist']['connectionId']"
}
},
"method":"get",
"path":"/sync/listProjects",
"authentication":"@parameters('$authentication')"
}
},
"Apply_to_each":{
"foreach":"@body('List_projects')?['projects']",
"actions":{
"Condition":{
"actions":{
"Condition_2":{
"actions":{
"Tasks":{
"runAfter":{
},
"metadata":{
"flowSystemMetadata":{
"swaggerOperationId":"ListItemsByProject"
}
},
"type":"ApiConnection",
"inputs":{
"host":{
"connection":{
"name":"@parameters('$connections')['todoist']['connectionId']"
}
},
"method":"get",
"path":"/projects/get_data",
"queries":{
"id":"@variables('projectId')"
},
"authentication":"@parameters('$authentication')"
}
},
"Set_variable":{
"runAfter":{
"Filter_array":[
"Succeeded"
]
},
"type":"SetVariable",
"inputs":{
"name":"nextTask",
"value":"@first(body('Filter_array'))"
}
},
"Filter_array":{
"runAfter":{
"Tasks":[
"Succeeded"
]
},
"type":"Query",
"inputs":{
"from":"@body('Tasks')?['items']",
"where":"@equals(item()?['checked'], 0)"
}
},
"Parse_JSON_2":{
"runAfter":{
"Set_variable":[
"Succeeded"
]
},
"type":"ParseJson",
"inputs":{
"content":"@string(first(body('Filter_array')))",
"schema":{
"type":"object",
"properties":{
"is_deleted":{
"type":"number"
},
"assigned_by_uid":{
},
"is_archived":{
"type":"number"
},
"labels":{
"type":"array",
"items":{
"type":"number"
}
},
"sync_id":{
},
"all_day":{
"type":"boolean"
},
"in_history":{
"type":"number"
},
"date_added":{
"type":"string"
},
"indent":{
"type":"number"
},
"date_lang":{
},
"id":{
"type":"string"
},
"content":{
"type":"string"
},
"checked":{
"type":"number"
},
"user_id":{
"type":"number"
},
"due_date_utc":{
},
"priority":{
"type":"number"
},
"parent_id":{
},
"item_order":{
"type":"number"
},
"responsible_uid":{
},
"project_id":{
"type":"string"
},
"collapsed":{
"type":"number"
},
"date_string":{
}
}
}
}
},
"Condition_3":{
"actions":{
"Update_a_task":{
"runAfter":{
},
"metadata":{
"flowSystemMetadata":{
"swaggerOperationId":"UpdateItem"
}
},
"type":"ApiConnection",
"inputs":{
"host":{
"connection":{
"name":"@parameters('$connections')['todoist']['connectionId']"
}
},
"method":"post",
"path":"/sync/updateItem",
"queries":{
"id":"@variables('projectId')",
"item_id":"@body('Parse_JSON_2')?['id']"
},
"body":{
"priority":"2"
},
"authentication":"@parameters('$authentication')"
}
}
},
"runAfter":{
"Parse_JSON_2":[
"Succeeded"
]
},
"expression":"@less(body('Parse_JSON_2')?['priority'], 2)",
"type":"If"
}
},
"runAfter":{
},
"expression":"@equals(1, 1)",
"type":"If"
}
},
"runAfter":{
},
"expression":"@equals(items('Apply_to_each')?['id'], variables('projectId'))",
"type":"If"
}
},
"runAfter":{
"List_projects":[
"Succeeded"
]
},
"type":"Foreach"
},
"Initialize_variable_2":{
"runAfter":{
"Initialize_variable_3":[
"Succeeded"
]
},
"type":"InitializeVariable",
"inputs":{
"variables":[
{
"name":"nextTaskId",
"type":"String"
}
]
}
},
"Initialize_variable_3":{
"runAfter":{
"Initialize_variable":[
"Succeeded"
]
},
"type":"InitializeVariable",
"inputs":{
"variables":[
{
"name":"nextTask",
"type":"Object",
"value":{
"id":-1
}
}
]
}
}
},
"outputs":{
},
"description":"When Todoist task is completed, associated task card from Trello is archived"
},
"parameters":{
"$connections":{
"value":{
"todoist":{
"id":"[concat('/subscriptions/', subscription().subscriptionId, '/providers/Microsoft.Web/locations/', parameters('logicAppLocation'), '/managedApis/', 'todoist')]",
"connectionId":"[resourceId('Microsoft.Web/connections', parameters('todoist_Connection_Name'))]",
"connectionName":"[parameters('todoist_Connection_Name')]"
}
}
}
}
},
"dependsOn":[
"[resourceId('Microsoft.Web/connections', parameters('todoist_Connection_Name'))]"
]
},
{
"type":"Microsoft.Web/connections",
"name":"[parameters('todoist_Connection_Name')]",
"apiVersion":"2016-06-01",
"location":"[parameters('logicAppLocation')]",
"properties":{
"api":{
"id":"[concat('/subscriptions/', subscription().subscriptionId, '/providers/Microsoft.Web/locations/', parameters('logicAppLocation'), '/managedApis/', 'todoist')]"
},
"displayName":"[parameters('todoist_Connection_Name')]"
}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment