{
  "name": "Pixmato: Google Sheets rows to product images",
  "nodes": [
    {
      "parameters": {},
      "id": "d040cdca-35a0-4572-8faf-b50c330989bf",
      "name": "Start",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [0, 300]
    },
    {
      "parameters": {
        "documentId": { "__rl": true, "value": "", "mode": "list" },
        "sheetName": { "__rl": true, "value": "Products", "mode": "name" },
        "options": {}
      },
      "id": "84856575-3c9c-4360-a20c-729cc373636e",
      "name": "Read product rows",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [220, 300],
      "credentials": {
        "googleSheetsOAuth2Api": { "id": "googleSheetsAccount", "name": "Google Sheets account" }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "loose", "version": 2 },
          "conditions": [
            {
              "id": "11853616-2f2b-4d15-aa6e-f754b7dd89a8",
              "leftValue": "={{ $json.image_url }}",
              "rightValue": "",
              "operator": { "type": "string", "operation": "empty", "singleValue": true }
            }
          ],
          "combinator": "and"
        },
        "looseTypeValidation": true,
        "options": {}
      },
      "id": "b444829e-0529-46ee-85c1-da64757e6ce2",
      "name": "Only rows without an image",
      "type": "n8n-nodes-base.filter",
      "typeVersion": 2.2,
      "position": [440, 300]
    },
    {
      "parameters": {
        "conditions": {
          "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "loose", "version": 2 },
          "conditions": [
            {
              "id": "54f70d39-0fd3-40b6-8196-592aa2f06a33",
              "leftValue": "={{ $json.render_id }}",
              "rightValue": "",
              "operator": { "type": "string", "operation": "notEmpty", "singleValue": true }
            }
          ],
          "combinator": "and"
        },
        "looseTypeValidation": true,
        "options": {}
      },
      "id": "3c1941b3-90f4-4dea-b044-98e4af0cf3d4",
      "name": "Sent to Pixmato before?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [660, 300]
    },
    {
      "parameters": {
        "method": "GET",
        "url": "=https://api.pixmato.com/v1/renders/{{ $json.render_id }}",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "options": {
          "response": { "response": { "fullResponse": true, "neverError": true } }
        }
      },
      "id": "a5a31713-f390-478c-bd0a-f3086f8eac59",
      "name": "Check earlier render",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [900, 180],
      "credentials": {
        "httpHeaderAuth": { "id": "pixmatoApiKey", "name": "Pixmato API key" }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.pixmato.com/v1/renders",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"template\": \"YOUR_TEMPLATE_ID\",\n  \"modifications\": {\n    \"product\": {{ JSON.stringify(String($json.product ?? '')) }},\n    \"price\": {{ JSON.stringify(String($json.price ?? '')) }},\n    \"photo\": {{ JSON.stringify(String($json.photo_url ?? '')) }}\n  },\n  \"output\": { \"format\": \"png\", \"scale\": 2 }\n}",
        "options": {
          "batching": { "batch": { "batchSize": 1, "batchInterval": 500 } },
          "response": { "response": { "fullResponse": true, "neverError": true } },
          "timeout": 60000
        }
      },
      "id": "ca2154d1-8885-4971-b958-e6814f3b8138",
      "name": "Render image",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [900, 420],
      "credentials": {
        "httpHeaderAuth": { "id": "pixmatoApiKey", "name": "Pixmato API key" }
      }
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "loose", "version": 2 },
                "conditions": [
                  {
                    "id": "bbf0ae3e-c682-47d2-aa34-39160f2636f1",
                    "leftValue": "={{ $json.body.output_url ?? $json.body.outputs?.[0]?.url ?? '' }}",
                    "rightValue": "",
                    "operator": { "type": "string", "operation": "notEmpty", "singleValue": true }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Image ready"
            },
            {
              "conditions": {
                "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "loose", "version": 2 },
                "conditions": [
                  {
                    "id": "be997bbb-1605-453e-8f10-b6e0429f74b9",
                    "leftValue": "={{ $json.body.details?.continues === true || ['pending', 'processing'].includes($json.body.status) }}",
                    "rightValue": "",
                    "operator": { "type": "boolean", "operation": "true", "singleValue": true }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Still rendering"
            }
          ]
        },
        "looseTypeValidation": true,
        "options": { "fallbackOutput": "extra", "renameFallbackOutput": "Failed" }
      },
      "id": "74c47bbf-1d95-4164-977b-ca8b53652a8b",
      "name": "What happened?",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.2,
      "position": [1140, 300]
    },
    {
      "parameters": {
        "operation": "update",
        "documentId": { "__rl": true, "value": "", "mode": "list" },
        "sheetName": { "__rl": true, "value": "Products", "mode": "name" },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "row_number": "={{ $('Read product rows').item.json.row_number }}",
            "image_url": "={{ $json.body.output_url ?? $json.body.outputs[0].url }}",
            "render_id": "={{ $json.body.id }}",
            "status": "done",
            "error": ""
          },
          "matchingColumns": ["row_number"],
          "schema": [
            {
              "id": "row_number",
              "displayName": "row_number",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "number",
              "canBeUsedToMatch": true,
              "readOnly": true,
              "removed": false
            },
            {
              "id": "image_url",
              "displayName": "image_url",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "render_id",
              "displayName": "render_id",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "status",
              "displayName": "status",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "error",
              "displayName": "error",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            }
          ]
        },
        "options": {}
      },
      "id": "1d283432-c625-4c9c-821b-671a71d37c22",
      "name": "Save image link",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [1400, 140],
      "credentials": {
        "googleSheetsOAuth2Api": { "id": "googleSheetsAccount", "name": "Google Sheets account" }
      }
    },
    {
      "parameters": {
        "operation": "update",
        "documentId": { "__rl": true, "value": "", "mode": "list" },
        "sheetName": { "__rl": true, "value": "Products", "mode": "name" },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "row_number": "={{ $('Read product rows').item.json.row_number }}",
            "render_id": "={{ $json.body.details?.jobId ?? $json.body.id }}",
            "status": "still rendering",
            "error": ""
          },
          "matchingColumns": ["row_number"],
          "schema": [
            {
              "id": "row_number",
              "displayName": "row_number",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "number",
              "canBeUsedToMatch": true,
              "readOnly": true,
              "removed": false
            },
            {
              "id": "render_id",
              "displayName": "render_id",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "status",
              "displayName": "status",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "error",
              "displayName": "error",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            }
          ]
        },
        "options": {}
      },
      "id": "f897384a-72c3-41a9-aa45-68ce573d87d3",
      "name": "Save render ID to check later",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [1400, 300],
      "credentials": {
        "googleSheetsOAuth2Api": { "id": "googleSheetsAccount", "name": "Google Sheets account" }
      }
    },
    {
      "parameters": {
        "operation": "update",
        "documentId": { "__rl": true, "value": "", "mode": "list" },
        "sheetName": { "__rl": true, "value": "Products", "mode": "name" },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "row_number": "={{ $('Read product rows').item.json.row_number }}",
            "render_id": "",
            "status": "failed",
            "error": "={{ $json.body.error ?? ('HTTP ' + $json.statusCode) }}"
          },
          "matchingColumns": ["row_number"],
          "schema": [
            {
              "id": "row_number",
              "displayName": "row_number",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "number",
              "canBeUsedToMatch": true,
              "readOnly": true,
              "removed": false
            },
            {
              "id": "render_id",
              "displayName": "render_id",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "status",
              "displayName": "status",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "error",
              "displayName": "error",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            }
          ]
        },
        "options": {}
      },
      "id": "fa6e88e9-5284-4a1d-bd7f-151a098c8bcc",
      "name": "Save error",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [1400, 460],
      "credentials": {
        "googleSheetsOAuth2Api": { "id": "googleSheetsAccount", "name": "Google Sheets account" }
      }
    }
  ],
  "connections": {
    "Start": { "main": [[{ "node": "Read product rows", "type": "main", "index": 0 }]] },
    "Read product rows": { "main": [[{ "node": "Only rows without an image", "type": "main", "index": 0 }]] },
    "Only rows without an image": { "main": [[{ "node": "Sent to Pixmato before?", "type": "main", "index": 0 }]] },
    "Sent to Pixmato before?": {
      "main": [
        [{ "node": "Check earlier render", "type": "main", "index": 0 }],
        [{ "node": "Render image", "type": "main", "index": 0 }]
      ]
    },
    "Check earlier render": { "main": [[{ "node": "What happened?", "type": "main", "index": 0 }]] },
    "Render image": { "main": [[{ "node": "What happened?", "type": "main", "index": 0 }]] },
    "What happened?": {
      "main": [
        [{ "node": "Save image link", "type": "main", "index": 0 }],
        [{ "node": "Save render ID to check later", "type": "main", "index": 0 }],
        [{ "node": "Save error", "type": "main", "index": 0 }]
      ]
    }
  },
  "pinData": {},
  "settings": { "executionOrder": "v1" },
  "meta": { "templateCredsSetupCompleted": false }
}
