{
  "name": "Pixmato: new article to share image",
  "nodes": [
    {
      "parameters": {
        "pollTimes": { "item": [{ "mode": "everyHour" }] },
        "feedUrl": "YOUR_FEED_URL"
      },
      "id": "6d6f7a7e-b07e-456b-8fab-152b747438e0",
      "name": "New article in feed",
      "type": "n8n-nodes-base.rssFeedReadTrigger",
      "typeVersion": 1,
      "position": [0, 300]
    },
    {
      "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    \"title\": {{ JSON.stringify(String($json.title ?? '')) }},\n    \"author\": {{ JSON.stringify(String($json.creator ?? '')) }}\n  },\n  \"output\": { \"format\": \"png\", \"scale\": 1 }\n}",
        "options": {
          "response": { "response": { "fullResponse": true, "neverError": true } },
          "timeout": 60000
        }
      },
      "id": "33b9d913-2383-46ac-94a0-a2c8dce5ed6f",
      "name": "Render share image",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [220, 300],
      "credentials": {
        "httpHeaderAuth": { "id": "pixmatoApiKey", "name": "Pixmato API key" }
      }
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "loose", "version": 2 },
                "conditions": [
                  {
                    "id": "f91a2f8e-ad56-4c8e-b9ef-2cf0bc4b3b5c",
                    "leftValue": "={{ $json.statusCode }}",
                    "rightValue": 200,
                    "operator": { "type": "number", "operation": "equals" }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Image ready"
            },
            {
              "conditions": {
                "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "loose", "version": 2 },
                "conditions": [
                  {
                    "id": "d0ffeed3-4373-4013-8cc5-cb0b02b65df5",
                    "leftValue": "={{ $json.body.details?.continues === true || $json.body.status === 'pending' }}",
                    "rightValue": "",
                    "operator": { "type": "boolean", "operation": "true", "singleValue": true }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Still rendering"
            },
            {
              "conditions": {
                "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "loose", "version": 2 },
                "conditions": [
                  {
                    "id": "7bbca4fe-d177-4e72-b0db-a5706673c4bc",
                    "leftValue": "={{ $json.statusCode }}",
                    "rightValue": 500,
                    "operator": { "type": "number", "operation": "gte" }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Try again"
            }
          ]
        },
        "looseTypeValidation": true,
        "options": { "fallbackOutput": "extra", "renameFallbackOutput": "Needs a fix" }
      },
      "id": "49770b5e-7d25-4e85-8ca0-3b68dd47b1bf",
      "name": "What happened?",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.2,
      "position": [440, 300]
    },
    {
      "parameters": { "amount": 30, "unit": "seconds" },
      "id": "ec9b4291-6d72-43c8-8497-411b9551a28d",
      "name": "Wait 30 seconds",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [680, 300],
      "webhookId": "0549044a-2de6-40d8-bf4a-27bb76a106b6"
    },
    {
      "parameters": {
        "method": "GET",
        "url": "=https://api.pixmato.com{{ $json.body.poll_url ?? $json.body.details.poll_url }}",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "options": {
          "response": { "response": { "fullResponse": true, "neverError": true } }
        }
      },
      "id": "b9b594ff-a198-4f07-8571-bb81e14d66ff",
      "name": "Check render",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [900, 300],
      "credentials": {
        "httpHeaderAuth": { "id": "pixmatoApiKey", "name": "Pixmato API key" }
      }
    },
    {
      "parameters": { "amount": 1, "unit": "minutes" },
      "id": "9040c905-47d6-486c-af56-38145320d784",
      "name": "Wait 1 minute",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [680, 480],
      "webhookId": "bd1cbaf9-7b6e-44c9-9a58-f4924456d6e9"
    },
    {
      "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    \"title\": {{ JSON.stringify(String($('New article in feed').item.json.title ?? '')) }},\n    \"author\": {{ JSON.stringify(String($('New article in feed').item.json.creator ?? '')) }}\n  },\n  \"output\": { \"format\": \"png\", \"scale\": 1 }\n}",
        "options": {
          "response": { "response": { "fullResponse": true, "neverError": true } },
          "timeout": 60000
        }
      },
      "id": "bf9b09ac-fbac-43d5-8f1d-fd826dc3e7a9",
      "name": "Render share image again",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [900, 480],
      "credentials": {
        "httpHeaderAuth": { "id": "pixmatoApiKey", "name": "Pixmato API key" }
      }
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": { "__rl": true, "value": "", "mode": "list" },
        "sheetName": { "__rl": true, "value": "Share images", "mode": "name" },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "article_title": "={{ $('New article in feed').item.json.title }}",
            "article_link": "={{ $('New article in feed').item.json.link }}",
            "image_url": "={{ $json.body.output_url ?? $json.body.outputs?.[0]?.url ?? '' }}",
            "render_id": "={{ $json.body.id ?? $json.body.details?.jobId ?? '' }}",
            "status": "={{ $json.body.code ?? $json.body.status ?? ('HTTP ' + $json.statusCode) }}",
            "error": "={{ $json.body.error ?? '' }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "article_title",
              "displayName": "article_title",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "article_link",
              "displayName": "article_link",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": 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": "cfa03d34-9c0c-4ba8-922d-75451574dad7",
      "name": "Log share image",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [1160, 300],
      "credentials": {
        "googleSheetsOAuth2Api": { "id": "googleSheetsAccount", "name": "Google Sheets account" }
      }
    }
  ],
  "connections": {
    "New article in feed": { "main": [[{ "node": "Render share image", "type": "main", "index": 0 }]] },
    "Render share image": { "main": [[{ "node": "What happened?", "type": "main", "index": 0 }]] },
    "What happened?": {
      "main": [
        [{ "node": "Log share image", "type": "main", "index": 0 }],
        [{ "node": "Wait 30 seconds", "type": "main", "index": 0 }],
        [{ "node": "Wait 1 minute", "type": "main", "index": 0 }],
        [{ "node": "Log share image", "type": "main", "index": 0 }]
      ]
    },
    "Wait 30 seconds": { "main": [[{ "node": "Check render", "type": "main", "index": 0 }]] },
    "Check render": { "main": [[{ "node": "Log share image", "type": "main", "index": 0 }]] },
    "Wait 1 minute": { "main": [[{ "node": "Render share image again", "type": "main", "index": 0 }]] },
    "Render share image again": { "main": [[{ "node": "Log share image", "type": "main", "index": 0 }]] }
  },
  "pinData": {},
  "settings": { "executionOrder": "v1" },
  "meta": { "templateCredsSetupCompleted": false }
}
