{
  "name": "Turn new WooCommerce products into branded social images with PostImager",
  "nodes": [
    {
      "parameters": {
        "content": "## New product to social image\n\nWhen a WooCommerce product is created, this makes a 1080 by 1080 PNG from a fixed template: your product name, price, photo and brand colour. It then downloads the file, ready to post.\n\nNo AI draws the image, so your text comes out as you sent it.\n\n### Set up\n1. Create a free key at postimager.com, under API keys.\n2. Add a Header Auth credential: name `Authorization`, value `Bearer` followed by your key. Select it on **Render product image**.\n3. Edit **Your brand**.\n4. Press **Test workflow** to run the sample product.\n5. Connect WooCommerce on **New product in WooCommerce**, then activate.\n\n### Limits\nPostImager is a free beta: 50 renders a month per account. Photos must be public JPEG or PNG, up to 5 MB. WebP is refused.",
        "height": 460,
        "width": 420
      },
      "id": "5c1e0a10-0001-4f6e-8a10-000000000001",
      "name": "How this works",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [-520, -180]
    },
    {
      "parameters": {
        "content": "## Post it (off by default)\n\nThe file arrives as binary `data`. Turn on the Facebook node and enter your Page ID, or swap in any node that takes an image.\n\nThe Facebook step has not been run by the template's author. Everything before it has.\n\nThe render's `output.download.url` also works for services that want a public link. It lasts 24 hours.",
        "height": 280,
        "width": 340,
        "color": 4
      },
      "id": "5c1e0a10-0002-4f6e-8a10-000000000002",
      "name": "About posting",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [1480, -300]
    },
    {
      "parameters": {
        "event": "product.created"
      },
      "id": "5c1e0a10-0003-4f6e-8a10-000000000003",
      "name": "New product in WooCommerce",
      "type": "n8n-nodes-base.wooCommerceTrigger",
      "typeVersion": 1,
      "position": [-60, -100],
      "webhookId": "5c1e0a10-0003-4f6e-8a10-00000000aaaa"
    },
    {
      "parameters": {},
      "id": "5c1e0a10-0004-4f6e-8a10-000000000004",
      "name": "Test with a sample product",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [-280, 120]
    },
    {
      "parameters": {
        "mode": "raw",
        "jsonOutput": "{\n  \"id\": 1001,\n  \"name\": \"Speckled stoneware mug, 350 ml\",\n  \"price\": \"24.00\",\n  \"regular_price\": \"29.00\",\n  \"on_sale\": true,\n  \"short_description\": \"<p>Hand-glazed, dishwasher safe, and made in small batches.</p>\",\n  \"images\": []\n}\n",
        "options": {}
      },
      "id": "5c1e0a10-0005-4f6e-8a10-000000000005",
      "name": "Sample product",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [-60, 120]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            { "id": "a1", "name": "brand_name", "value": "Your Store", "type": "string" },
            { "id": "a2", "name": "brand_color", "value": "#B4441B", "type": "string" },
            { "id": "a3", "name": "currency", "value": "$", "type": "string" },
            { "id": "a4", "name": "badge", "value": "New", "type": "string" }
          ]
        },
        "includeOtherFields": true,
        "options": {}
      },
      "id": "5c1e0a10-0006-4f6e-8a10-000000000006",
      "name": "Your brand",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [180, 0]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://postimager.com/v1/renders?wait=60",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            { "name": "Idempotency-Key", "value": "={{ 'woo-product-' + $json.id }}" }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ template: 'product-card', size: 'square', format: 'png', variables: { brand_name: $json.brand_name.slice(0, 40), brand_color: $json.brand_color, badge: $json.badge.slice(0, 20), product_name: $json.name.slice(0, 80), price: ($json.currency + $json.price).slice(0, 24), ...($json.on_sale && $json.regular_price ? { compare_at_price: ($json.currency + $json.regular_price).slice(0, 24) } : {}), description: ($json.short_description || '').replace(/<[^>]+>/g, '').trim().slice(0, 140), image_url: $json.images?.[0]?.src || 'sample:mug', cta: 'Shop now' } }) }}",
        "options": {}
      },
      "id": "5c1e0a10-0007-4f6e-8a10-000000000007",
      "name": "Render product image",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [400, 0],
      "credentials": {
        "httpHeaderAuth": { "id": "", "name": "PostImager API key" }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict" },
          "conditions": [
            {
              "id": "c1",
              "leftValue": "={{ $json.status }}",
              "rightValue": "completed",
              "operator": { "type": "string", "operation": "equals" }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "5c1e0a10-0008-4f6e-8a10-000000000008",
      "name": "Render finished?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [620, 0]
    },
    {
      "parameters": {
        "url": "={{ $json.output.download.url }}",
        "options": {
          "response": { "response": { "responseFormat": "file" } }
        }
      },
      "id": "5c1e0a10-0009-4f6e-8a10-000000000009",
      "name": "Download image",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [860, -100]
    },
    {
      "parameters": {
        "errorMessage": "=PostImager render {{ $json.id }} is {{ $json.status }}, so there is no image yet. It may still finish: read it again with GET /v1/renders/{{ $json.id }}."
      },
      "id": "5c1e0a10-000a-4f6e-8a10-00000000000a",
      "name": "Stop: no image yet",
      "type": "n8n-nodes-base.stopAndError",
      "typeVersion": 1,
      "position": [860, 100]
    },
    {
      "parameters": {
        "httpRequestMethod": "POST",
        "graphApiVersion": "",
        "node": "YOUR_PAGE_ID",
        "edge": "photos",
        "sendBinaryData": true,
        "binaryPropertyName": "data",
        "options": {}
      },
      "id": "5c1e0a10-000b-4f6e-8a10-00000000000b",
      "name": "Post to your Facebook Page",
      "type": "n8n-nodes-base.facebookGraphApi",
      "typeVersion": 1,
      "position": [1120, -100],
      "disabled": true
    }
  ],
  "connections": {
    "New product in WooCommerce": { "main": [[{ "node": "Your brand", "type": "main", "index": 0 }]] },
    "Test with a sample product": { "main": [[{ "node": "Sample product", "type": "main", "index": 0 }]] },
    "Sample product": { "main": [[{ "node": "Your brand", "type": "main", "index": 0 }]] },
    "Your brand": { "main": [[{ "node": "Render product image", "type": "main", "index": 0 }]] },
    "Render product image": { "main": [[{ "node": "Render finished?", "type": "main", "index": 0 }]] },
    "Render finished?": {
      "main": [
        [{ "node": "Download image", "type": "main", "index": 0 }],
        [{ "node": "Stop: no image yet", "type": "main", "index": 0 }]
      ]
    },
    "Download image": { "main": [[{ "node": "Post to your Facebook Page", "type": "main", "index": 0 }]] }
  },
  "settings": { "executionOrder": "v1" },
  "pinData": {}
}
