{
  "name": "v2 Like Minds \u2014 Canva Sync",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 2
            }
          ]
        }
      },
      "id": "d9dd1478-8805-45e5-85ce-831820780454",
      "name": "Daily 2am",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.3,
      "position": [
        0,
        0
      ]
    },
    {
      "parameters": {
        "method": "DELETE",
        "url": "https://marketing-agent-production-8efa.up.railway.app/api/memory",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBearerAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ { \"tag\": \"[CANVA]\" } }}",
        "options": {}
      },
      "id": "82295515-d25a-46c0-8699-5d6a01a13eeb",
      "name": "Clear Old Canva Memories",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        224,
        0
      ],
      "executeOnce": true,
      "alwaysOutputData": true,
      "credentials": {
        "httpBearerAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "url": "https://api.canva.com/rest/v1/designs?ownership=owned&sort_by=modified",
        "authentication": "genericCredentialType",
        "genericAuthType": "oAuth2Api",
        "options": {}
      },
      "id": "b0406ce6-168b-46b2-b30c-a427f993b48e",
      "name": "Get Owned Designs",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        448,
        0
      ]
    },
    {
      "parameters": {
        "jsCode": "// The Canva designs API returns designs in the \"items\" array.\nconst designs = $input.first().json.items || [];\nconst results = [];\n\nfor (const design of designs) {\n  const title = design.title || 'Untitled';\n  const id = design.id;\n\n  // updated_at from Canva is a Unix timestamp (seconds).\n  let dateStr = '';\n  if (design.updated_at) {\n    const dt = DateTime.fromSeconds(Number(design.updated_at), { zone: 'Australia/Sydney' });\n    dateStr = dt.setLocale('en-AU').toFormat('dd/MM/yyyy');\n  }\n\n  results.push({\n    json: {\n      title,\n      id,\n      date: dateStr,\n      content: `[CANVA] ${title} (ID: ${id}) \u2014 last updated ${dateStr}`,\n    },\n  });\n}\n\nreturn results;"
      },
      "id": "34474991-6d63-45d5-8817-1faf50a3b04d",
      "name": "Format Designs",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        672,
        0
      ]
    },
    {
      "parameters": {
        "options": {}
      },
      "id": "e6119ec1-4158-4888-8bc2-b6511f24b3a1",
      "name": "Loop Designs",
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 3,
      "position": [
        896,
        0
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://marketing-agent-production-8efa.up.railway.app/api/memory",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBearerAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ { \"content\": $json.content } }}",
        "options": {}
      },
      "id": "e0a133a6-0695-40e2-b65f-ee28e10f1b01",
      "name": "Save to Memory",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        1120,
        0
      ],
      "credentials": {
        "httpBearerAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "canva-search",
        "responseMode": "responseNode",
        "options": {}
      },
      "id": "62e28097-337a-45c2-a140-f6e4f00d3a98",
      "name": "Search Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2.1,
      "position": [
        0,
        224
      ]
    },
    {
      "parameters": {
        "url": "https://api.canva.com/rest/v1/designs",
        "authentication": "genericCredentialType",
        "genericAuthType": "oAuth2Api",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "query",
              "value": "={{ $json.body.query }}"
            },
            {
              "name": "ownership",
              "value": "owned"
            }
          ]
        },
        "options": {}
      },
      "id": "4926bbba-1a02-4604-8672-b01c20de8ea4",
      "name": "Search Designs",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        224,
        224
      ]
    },
    {
      "parameters": {
        "jsCode": "const designs = $input.first().json.items || [];\nconst matches = [];\n\nfor (const design of designs) {\n  let dateStr = '';\n  if (design.updated_at) {\n    const dt = DateTime.fromSeconds(Number(design.updated_at), { zone: 'Australia/Sydney' });\n    dateStr = dt.setLocale('en-AU').toFormat('dd/MM/yyyy');\n  }\n\n  matches.push({\n    name: design.title || 'Untitled',\n    id: design.id,\n    thumbnail: design.thumbnail && design.thumbnail.url ? design.thumbnail.url : null,\n    updated: dateStr,\n  });\n}\n\nreturn [{ json: { designs: matches } }];"
      },
      "id": "fa5a93dc-a66b-4ae8-b948-2ad4c3ae2b84",
      "name": "Shape Results",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        448,
        224
      ]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ { \"designs\": $json.designs } }}",
        "options": {}
      },
      "id": "bf9247db-4012-4ff5-a161-13419ed3ff3c",
      "name": "Respond With Designs",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.5,
      "position": [
        672,
        224
      ]
    }
  ],
  "connections": {
    "Daily 2am": {
      "main": [
        [
          {
            "node": "Clear Old Canva Memories",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Clear Old Canva Memories": {
      "main": [
        [
          {
            "node": "Get Owned Designs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Owned Designs": {
      "main": [
        [
          {
            "node": "Format Designs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Designs": {
      "main": [
        [
          {
            "node": "Loop Designs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Designs": {
      "main": [
        [
          {
            "node": "Save to Memory",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save to Memory": {
      "main": [
        [
          {
            "node": "Loop Designs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Search Webhook": {
      "main": [
        [
          {
            "node": "Search Designs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Search Designs": {
      "main": [
        [
          {
            "node": "Shape Results",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Shape Results": {
      "main": [
        [
          {
            "node": "Respond With Designs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "binaryMode": "separate"
  },
  "versionId": "3d45ab14-bb08-4764-9c63-1b1073302517",
  "nodeGroups": [],
  "id": "6DEBavJiK9QkLyjp",
  "tags": []
}