{
  "name": "SeoPrimo - weekly quick audit by email",
  "nodes": [
    {
      "parameters": {
        "content": "## SeoPrimo: weekly quick audit\n1. Create the credential **SeoPrimo API** (type Header Auth): name `Authorization`, value `Bearer sp_live_...` (key with scope write).\n2. In **Settings** set your `site_id` (GET /api/v1/sites) and the recipient email.\n3. Pick your SMTP credential in **Send email**.\nThe quick audit costs 10 credits (given back if it fails).",
        "height": 230,
        "width": 420
      },
      "id": "99f0d827-ade2-59a0-b245-fc14cf439d57",
      "name": "Setup",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -60,
        -120
      ]
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "weeks",
              "triggerAtDay": [
                1
              ],
              "triggerAtHour": 8
            }
          ]
        }
      },
      "id": "73fcf736-6a49-5382-989f-2c6c6f396386",
      "name": "Every Monday 8:00",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        0,
        300
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "a3030ce6-b334-5c90-bec9-7b43e5d2ddd2",
              "name": "site_id",
              "value": "REPLACE_WITH_SITE_ID",
              "type": "string"
            },
            {
              "id": "041adf11-8368-5a75-849f-b710c153dd4a",
              "name": "notify_email",
              "value": "you@example.com",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "bc5d0175-3dc8-5d72-9d8e-5a8b82dc68cf",
      "name": "Settings",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        220,
        300
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://seoprimo.it/api/v1/sites/{{ $json.site_id }}/audits",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "options": {}
      },
      "id": "38ad924e-eb9c-521f-97d6-c9887b84029b",
      "name": "Start quick audit",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        440,
        300
      ],
      "credentials": {
        "httpHeaderAuth": {
          "id": "REPLACE_WITH_CREDENTIAL_ID",
          "name": "SeoPrimo API"
        }
      }
    },
    {
      "parameters": {
        "amount": 60,
        "unit": "seconds"
      },
      "id": "303e8e23-533f-57d9-b7be-3914eb50522a",
      "name": "Wait 60 s",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        660,
        300
      ],
      "webhookId": "854046af-a9c5-5778-aa65-129bc44e112f"
    },
    {
      "parameters": {
        "method": "GET",
        "url": "=https://seoprimo.it/api/v1/sites/{{ $('Settings').item.json.site_id }}/audits",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "options": {}
      },
      "id": "9ee0eaf7-519f-5e0c-87f2-04dbbff14023",
      "name": "Read audits",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        880,
        300
      ],
      "credentials": {
        "httpHeaderAuth": {
          "id": "REPLACE_WITH_CREDENTIAL_ID",
          "name": "SeoPrimo API"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "// The quick audit is not a /runs job: read it from GET /sites/{id}/audits and match the id we started.\nconst startedId = $('Start quick audit').first().json.id;\nconst body = $input.first().json;\nconst audit = (body.audits || []).find((a) => a.id === startedId);\nlet status = audit ? audit.status : 'queued';\n// give up after about 20 minutes (20 loops of 60 s)\nif (!['done', 'failed'].includes(status) && $runIndex >= 20) status = 'timeout';\nreturn [{ json: {\n  status,\n  url: audit ? audit.url : null,\n  score: audit ? audit.score : null,\n  preliminary: audit ? audit.preliminary : null,\n  summary: audit ? audit.summary : null,\n  error: audit ? audit.error : null,\n} }];\n"
      },
      "id": "bd315c65-ca86-58e2-b7b5-ec75270e0d61",
      "name": "Pick this audit",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1100,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "34c79586-afd9-5bea-b298-bc27c221951c",
              "leftValue": "={{ $json.status }}",
              "rightValue": "done",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            },
            {
              "id": "6ff50b86-51c4-5adc-a455-f4adb6726d89",
              "leftValue": "={{ $json.status }}",
              "rightValue": "failed",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            },
            {
              "id": "12c4ac1a-002a-5fb3-9a04-c26c2d79ed84",
              "leftValue": "={{ $json.status }}",
              "rightValue": "timeout",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "or"
        },
        "options": {}
      },
      "id": "ac2f1562-864c-530a-a170-42b86506f5c1",
      "name": "Finished?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        1320,
        300
      ]
    },
    {
      "parameters": {
        "method": "GET",
        "url": "=https://seoprimo.it/api/v1/sites/{{ $('Settings').item.json.site_id }}/score",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "options": {}
      },
      "id": "2641a2f0-dbb0-59fc-8e3e-55580c562342",
      "name": "Read full Score",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1540,
        220
      ],
      "credentials": {
        "httpHeaderAuth": {
          "id": "REPLACE_WITH_CREDENTIAL_ID",
          "name": "SeoPrimo API"
        }
      }
    },
    {
      "parameters": {
        "fromEmail": "seoprimo@example.com",
        "toEmail": "={{ $('Settings').item.json.notify_email }}",
        "subject": "=SeoPrimo weekly audit: {{ $('Pick this audit').item.json.status === 'done' ? 'Score ' + $('Pick this audit').item.json.score + '/100' : $('Pick this audit').item.json.status }} ({{ $('Pick this audit').item.json.url }})",
        "emailFormat": "text",
        "text": "=Status: {{ $('Pick this audit').item.json.status }}\nSite: {{ $('Pick this audit').item.json.url }}\nQuick audit Score: {{ $('Pick this audit').item.json.score }}/100{{ $('Pick this audit').item.json.preliminary ? ' (preliminary)' : '' }}\nLatest full Score: {{ $json.score }}\n\n{{ $('Pick this audit').item.json.summary || $('Pick this audit').item.json.error || '' }}\n",
        "options": {}
      },
      "id": "3491e052-5824-576b-b8a8-86360a9f0125",
      "name": "Send email",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 2.1,
      "position": [
        1760,
        220
      ],
      "credentials": {
        "smtp": {
          "id": "REPLACE_WITH_CREDENTIAL_ID",
          "name": "SMTP account"
        }
      }
    }
  ],
  "connections": {
    "Every Monday 8:00": {
      "main": [
        [
          {
            "node": "Settings",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Settings": {
      "main": [
        [
          {
            "node": "Start quick audit",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Start quick audit": {
      "main": [
        [
          {
            "node": "Wait 60 s",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait 60 s": {
      "main": [
        [
          {
            "node": "Read audits",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read audits": {
      "main": [
        [
          {
            "node": "Pick this audit",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Pick this audit": {
      "main": [
        [
          {
            "node": "Finished?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Finished?": {
      "main": [
        [
          {
            "node": "Read full Score",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Wait 60 s",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read full Score": {
      "main": [
        [
          {
            "node": "Send email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "335747fc-9e75-5a07-81ce-52d8930cce65",
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "tags": []
}
