Here's a step-by-step process to build your Asana to Notion workflow with n8n.io:
use n8n their cloud service (details on their website).
Familiarize yourself with the n8n interface. It uses a node-based system to build workflows.
2. Building the Workflow:
Start Node: Add an "On Update Asana" node as the trigger. This will initiate the workflow whenever a task is updated in Asana.
Connect Asana Account: Configure the Asana node with your API key and Workspace ID.
Extract Task Details: Add a "Code" node after the Asana node. Here, write JavaScript code to extract relevant task details like name, description, due date, etc., from the Asana data received by the previous node.
```javascript const gids = [];
// get all the unique Asana task gids for (item of items) { var gid = parseInt(item.json.resource.gid); var resource_type = item.json.resource.resource_type; if (!(gids.includes(gid)) && resource_type == "task") { gids.push(gid); } }
// show in output const new_items = []; for (gid of gids) { var new_item = { "json": { "gid": 0, "gids": [], "notionfilter": "" } }; new_item = JSON.stringify(new_item); new_item = JSON.parse(new_item); new_item.json.gid = gid; new_item.json.gids = gids; new_items.push(new_item);
// Notion filter notionfilter = { or: [], }
for (gid of gids) { const filter = { property: 'Asana GID', number: { equals: gid } } notionfilter["or"].push(filter); }
new_item.json.notionfilter = JSON.stringify(notionfilter); }
console.log(gids); return new_items;
* **Get Existing Tasks :** If you want to check for existing tasks before creating/updating in Notion, add a "**Get Tasks**" node connected to the Asana node. This retrieves a list of tasks from Asana for comparison (configure filters if needed).
* **Connect to Notion:** Add a "**Notion**" node and configure it with your Notion API key and database ID. This specifies the "Tasks" database in Notion where you want to manage the tasks.
* **New vs. Update Decision:** Add another "**Code**" node. Here, write JavaScript code to analyze the Asana data and determine if the task is new (not found in the retrieved list) or an update (exists in the list). This code can compare task IDs, names, or other unique identifiers.
* ```javascript
const gids_to_update = [];
const database_ids = [];
for (item of $items("Find tasks")) {
gids_to_update.push(parseInt(item.json.property_asana_gid));
database_ids.push(item.json.id);
}
console.log(gids_to_update);
console.log(database_ids);
var gid;
let i = 0;
for (item of $items("Get tasks")) {
gid = parseInt(item.json.gid);
if (gids_to_update.includes(gid)) {
item.json.action = "Update"
item.json.database_id = database_ids[i];
} else {
item.json.action = "Create"
}
i++;
}
return $items("Get tasks");
- Conditional Branching: Add a "Conditional" node. Connect the previous code node's output to this. Based on the "new" or "update" flag set in the code, the workflow will branch into separate paths.
3. Handling New Tasks:
- If the task is new, connect the "Conditional" node's "new" output to a "Notion Create Page" node. Configure this node to create a new page in your Notion "Tasks" database using the extracted task details from the first code node.
4. Handling Updated Tasks:
- If the task is an update, connect the "Conditional" node's "update" output to a "Notion Update Page" node. Configure this node to update the existing Notion page (matching the Asana task ID or another identifier) with the latest details from the first code node.
5. Testing and Deployment:
Save and test your workflow thoroughly with sample Asana tasks.
Once satisfied, deploy your workflow in n8n.io. This will ensure it runs automatically whenever a task is updated in Asana.