{
  "name": "Nextcloud - favorite list",
  "nodes": [
    {
      "parameters": {
        "path": "nextcloud-list",
        "responseMode": "responseNode",
        "options": {}
      },
      "id": "3e83bb95-7833-45d0-8a35-311980c10fe7",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        -1456,
        224
      ],
      "webhookId": "52389117-8d93-40c2-972a-3bb5a6bf046f"
    },
    {
      "parameters": {
        "jsCode": "const username = 'USERNAME';\nconst password = 'PASSWORD';\nconst url = 'NEXTCLOUD_BASE_URL'; // eg. 'https://example.com/remote.php/dav/'\nconst principalUsername = 'PRINCIPAL_USERNAME'\n\nconst favSearchBody = `<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<d:searchrequest xmlns:d=\"DAV:\" xmlns:oc=\"http://owncloud.org/ns\" xmlns:nc=\"http://nextcloud.org/ns\">\n  <d:basicsearch>\n    <d:select>\n      <d:prop>\n        <d:getcontenttype />\n        <d:getlastmodified />\n        <d:getcontentlength />\n        <oc:fileid />\n        <oc:favorite />\n        <nc:has-preview />\n        <nc:creation-time />\n        <nc:upload-time />\n      </d:prop>\n    </d:select>\n    <d:from>\n      <d:scope>\n        <d:href>/files/` + principalUsername + `</d:href>\n        <d:depth>infinity</d:depth>\n      </d:scope>\n    </d:from>\n    <d:where>\n      <d:and>\n        <d:eq>\n          <d:prop><oc:favorite /></d:prop>\n          <d:literal>1</d:literal>\n        </d:eq>\n        <d:like>\n          <d:prop><d:getcontenttype /></d:prop>\n          <d:literal>image/%</d:literal>\n        </d:like>\n      </d:and>\n    </d:where>\n    <d:orderby>\n      <d:order>\n        <d:prop>\n          <d:getlastmodified/>\n        </d:prop>\n        <d:descending/>\n      </d:order>\n    </d:orderby>\n    <d:limit>\n      <d:nresults>20</d:nresults>\n    </d:limit>\n  </d:basicsearch>\n</d:searchrequest>`;\n\nconst response = await this.helpers.httpRequest({\n  method: 'SEARCH',\n  url: url,\n  headers: {\n    'Content-Type': 'application/xml',\n    'Accept': 'application/xml'\n  },\n  auth: {\n    username: username,\n    password: password,\n  },\n  body: favSearchBody,\n  returnFullResponse: true,\n});\n\nconst xml = response.body;\nconst responses = [...xml.matchAll(/<d:response>([\\s\\S]*?)<\\/d:response>/g)];\n\nconst files = responses.map(m => {\n  const block = m[1];\n\n  const get = (tag) =>\n    block.match(new RegExp(`<${tag}[^>]*>([^<]+)<\\/${tag}>`))?.[1]?.trim() ?? null;\n\n  const href = get('d:href');\n  const prefix = /\\/remote\\.php\\/dav\\/files\\/[^/]+\\/Photos\\//;\n  const path = href.replace(prefix, '');\n\n\n  const lastModifiedRaw = get('d:getlastmodified');\n\n  return {\n    file_id:        parseInt(get('oc:fileid')),\n    path:           path,\n    last_modified:  lastModifiedRaw ? new Date(lastModifiedRaw).toISOString() : null,\n    content_length: parseInt(get('d:getcontentlength')),\n    url:            \"https://n8n.example.com/webhook/nextcloud-get?path=\" + path,\n    thumbnail_url:  \"https://n8n.example.com/webhook/nextcloud-get?size=thumb&path=\" + path\n  };\n});\n\nreturn files.map(f => ({ json: f }));\n"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -1248,
        224
      ],
      "id": "42cd33eb-2d8f-433d-a7ed-76d402016c9f",
      "name": "Fetch from Nextcloud"
    },
    {
      "parameters": {
        "respondWith": "allIncomingItems",
        "options": {}
      },
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.5,
      "position": [
        -1040,
        224
      ],
      "id": "806ac0af-7a40-4e54-afa6-a236b268c581",
      "name": "Respond"
    }
  ],
  "connections": {
    "Webhook": {
      "main": [
        [
          {
            "node": "Fetch from Nextcloud",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch from Nextcloud": {
      "main": [
        [
          {
            "node": "Respond",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": true,
  "settings": {
    "executionOrder": "v1",
    "binaryMode": "separate",
    "availableInMCP": false
  },
  "versionId": "539d0eee-f692-4f58-a1c6-8323bb0e02d1",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "c744a803fbee0d2a2159403787f35ebac356b936840a6ed99b40231bb88d9690"
  },
  "id": "ouHpYcu669T1Htza",
  "tags": []
}