{
  "name": "Ads by Breakfast: URL in, 6 ads out",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "ads-by-breakfast",
        "responseMode": "onReceived",
        "options": {}
      },
      "id": "325df9ef-b36a-4483-8ebd-38d7e1c6c812",
      "name": "URL in",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        300
      ],
      "webhookId": "ff93225d-a0d7-4585-8a1e-904c3adb61a3",
      "notes": "POST {\"url\": \"https://shop.example/product\", \"format\": \"reels\", \"deliver_to\": \"client@example.com\"}"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "827baaa6-08d4-47bf-a549-a03f1bba98be",
              "name": "api_base",
              "value": "https://adsbybreakfast.com",
              "type": "string"
            },
            {
              "id": "16d2ab90-9d09-4d49-96b7-80a6ce289c33",
              "name": "url",
              "value": "={{ $json.body.url }}",
              "type": "string"
            },
            {
              "id": "191202f8-85da-4151-81a8-ad367d82ea64",
              "name": "format",
              "value": "={{ $json.body.format || 'reels' }}",
              "type": "string"
            },
            {
              "id": "ae5ec10f-0222-4137-8552-fb6e679d885e",
              "name": "deliver_to",
              "value": "={{ $json.body.deliver_to || '' }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "447b58f4-88fb-4401-86fa-7a0045a94b25",
      "name": "Settings",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        220,
        300
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $json.api_base }}/api/v1/packs",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Idempotency-Key",
              "value": "=n8n-{{ $execution.id }}"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ url: $json.url, format: $json.format, webhook_url: $execution.resumeUrl, metadata: { n8n_execution: String($execution.id), deliver_to: $json.deliver_to } }) }}",
        "options": {}
      },
      "id": "51696af0-b852-4ffd-9ca4-0cd87dbb3861",
      "name": "Create pack",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        440,
        300
      ],
      "notes": "6 credits per pack on a live key. Test keys are free and finish in about 20 seconds."
    },
    {
      "parameters": {
        "resume": "webhook",
        "httpMethod": "POST",
        "limitWaitTime": true,
        "limitType": "afterTimeInterval",
        "resumeAmount": 30,
        "resumeUnit": "minutes",
        "options": {}
      },
      "id": "54fbaaf2-7ae6-4117-87ef-7c6800bb4d22",
      "name": "Wait for pack",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        660,
        300
      ],
      "webhookId": "d0885d19-1b93-4e5b-9c73-7af1e18f90bb",
      "notes": "Wakes on each pack webhook, or every 30 minutes if your n8n cannot receive webhooks. The next node re-checks with your key, so the webhook body is never trusted."
    },
    {
      "parameters": {
        "url": "={{ $('Settings').first().json.api_base }}/api/v1/packs/{{ $('Create pack').first().json.id }}",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "options": {}
      },
      "id": "7d7bc816-e66e-4034-b9a3-53a50363eb08",
      "name": "Get pack",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        880,
        300
      ]
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict"
                },
                "conditions": [
                  {
                    "id": "5c199f99-132d-4119-a5b9-a68fe7b57c53",
                    "leftValue": "={{ $json.status }}",
                    "rightValue": "ready",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "ready"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict"
                },
                "conditions": [
                  {
                    "id": "d1fdc9b2-1493-47ab-a72a-5342397b7a13",
                    "leftValue": "={{ $json.status }}",
                    "rightValue": "failed",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "failed"
            }
          ]
        },
        "options": {
          "fallbackOutput": "extra",
          "renameFallbackOutput": "still cooking"
        }
      },
      "id": "27bfbaea-126f-4022-ab36-a571e0bd9381",
      "name": "Status?",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.2,
      "position": [
        1100,
        300
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "fa4a23d8-9ef1-4478-abe4-e508e61aa772",
              "name": "pack_id",
              "value": "={{ $json.id }}",
              "type": "string"
            },
            {
              "id": "9c2411d1-6ab5-46d8-8bdc-c237587323d4",
              "name": "product_url",
              "value": "={{ $json.url }}",
              "type": "string"
            },
            {
              "id": "9ce996df-74ab-47e5-bbb3-a556e2b6fdb2",
              "name": "zip_url",
              "value": "={{ $json.zip_url }}",
              "type": "string"
            },
            {
              "id": "35ac3251-44b7-4918-a8f0-9c233aaa04d8",
              "name": "image_urls",
              "value": "={{ $json.ads.map(a => a.image_url) }}",
              "type": "array"
            },
            {
              "id": "7d2e0bcd-b379-4cb9-bc80-90494506ae05",
              "name": "headlines",
              "value": "={{ $json.ads.map(a => a.headline) }}",
              "type": "array"
            },
            {
              "id": "03341c42-7086-490f-a4a4-e30733855984",
              "name": "urls_expire_at",
              "value": "={{ $json.urls_expire_at }}",
              "type": "string"
            },
            {
              "id": "b583b6a2-8de0-454a-9a5a-bf52e0568c20",
              "name": "deliver_to",
              "value": "={{ $('Settings').first().json.deliver_to }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "b3a32d8d-d8bf-4136-bb0c-0e2afa8925a0",
      "name": "Pack out",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1340,
        160
      ],
      "notes": "Clean output. Swap the next node for Drive, Slack, a CRM or a client portal."
    },
    {
      "parameters": {
        "fromEmail": "you@your-agency.com",
        "toEmail": "={{ $json.deliver_to }}",
        "subject": "=Your 6 ads for {{ $json.product_url }}",
        "emailFormat": "html",
        "html": "=<p>Your 6 ads are ready.</p><ol>{{ $json.image_urls.map((u, i) => '<li><a href=\"' + u + '\">Ad ' + (i + 1) + '</a>: ' + ($json.headlines[i] || '') + '</li>').join('') }}</ol>{{ $json.zip_url ? '<p><a href=\"' + $json.zip_url + '\">Download all as ZIP</a></p>' : '' }}<p>Links expire {{ $json.urls_expire_at }}.</p>",
        "options": {}
      },
      "id": "b73741a6-2c76-45e8-a4cd-b755a7680c20",
      "name": "Deliver by email",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 2.1,
      "position": [
        1560,
        160
      ]
    },
    {
      "parameters": {
        "errorMessage": "={{ 'Pack ' + $json.id + ' failed: ' + ($json.error ? $json.error.message : 'unknown') }}"
      },
      "id": "5f8668b7-8728-44cd-a469-6ee05fec485a",
      "name": "Pack failed",
      "type": "n8n-nodes-base.stopAndError",
      "typeVersion": 1,
      "position": [
        1340,
        320
      ]
    }
  ],
  "connections": {
    "URL in": {
      "main": [
        [
          {
            "node": "Settings",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Settings": {
      "main": [
        [
          {
            "node": "Create pack",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create pack": {
      "main": [
        [
          {
            "node": "Wait for pack",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait for pack": {
      "main": [
        [
          {
            "node": "Get pack",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get pack": {
      "main": [
        [
          {
            "node": "Status?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Status?": {
      "main": [
        [
          {
            "node": "Pack out",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Pack failed",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Wait for pack",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Pack out": {
      "main": [
        [
          {
            "node": "Deliver by email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {},
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "tags": []
}