{
  "name": "Create Ghost draft post",
  "nodes": [
    {
      "parameters": {
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "typeVersion": 1.4,
      "position": [
        -176,
        272
      ],
      "id": "2e768152-e057-489e-988e-5f9c4c6d8315",
      "name": "Trigger",
      "notes": "[\n  {\n    \"action\": \"sendMessage\",\n    \"sessionId\": \"14ecedfe38864e288aaf375f015f3ae7\",\n    \"chatInput\": {\n      \"title\": \"Post title in sentence case capitalization\",\n      \"content\": \"Post content in Lexical format\",\n      \"excerpt\": \"Post SEO description up to 150 characters\",\n      \"cover_prompt\": \"What to draw on a post cover image\"\n    }\n  }\n]"
    },
    {
      "parameters": {
        "jsCode": "return [{ json: JSON.parse($input.all()[0].json.chatInput) }];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -16,
        272
      ],
      "id": "2982b46f-6e87-4d09-b2ea-bcd1c27a1f84",
      "name": "Parse JSON"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://amursky.com/ghost/api/admin/posts/",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "ghostAdminApi",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "source",
              "value": "html"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ $json.body }}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        1328,
        256
      ],
      "id": "94545735-d2c8-4ceb-b585-17d98d526b4f",
      "name": "Create Ghost Post",
      "credentials": {
        "ghostAdminApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "content": "## Create draft post\n",
        "height": 224,
        "width": 400,
        "color": 7
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1088,
        192
      ],
      "id": "84f03a73-e098-4847-8e2e-182d5752e666",
      "name": "Sticky Note"
    },
    {
      "parameters": {
        "content": "## Generate and upload post cover image\n",
        "height": 400,
        "width": 736,
        "color": 7
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        144,
        -128
      ],
      "id": "342f1207-e005-4269-826c-4a3aff5db12b",
      "name": "Sticky Note1"
    },
    {
      "parameters": {
        "mode": "combine",
        "combineBy": "combineByPosition",
        "options": {}
      },
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3.2,
      "position": [
        960,
        256
      ],
      "id": "bba9559c-3cda-4f2d-a78f-dfcb873fb357",
      "name": "Merge JSON"
    },
    {
      "parameters": {
        "jsCode": "const items = $input.all();\n\nfor (const item of items) {\n  if (item.binary && item.binary.data) {\n    const id = Math.random().toString(36).substring(2, 10);\n    item.binary.data.fileName = `cover-${id}.png`;\n  }\n}\n\nreturn items;"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        352,
        -64
      ],
      "id": "2b95bb4e-29ff-46e8-8f6b-174cf18db691",
      "name": "Generate random cover image file name"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://amursky.com/ghost/api/admin/images/upload/",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "ghostAdminApi",
        "sendBody": true,
        "contentType": "multipart-form-data",
        "bodyParameters": {
          "parameters": [
            {
              "parameterType": "formBinaryData",
              "name": "file",
              "inputDataFieldName": "data"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        544,
        -64
      ],
      "id": "ba2fcaec-a1f6-426e-987c-93e6c8e0e501",
      "name": "Upload cover image",
      "credentials": {
        "ghostAdminApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const item = $input.all()[0].json;\n\nreturn [{\n  json: {\n    body: JSON.stringify({\n      posts: [{\n        status: \"draft\",\n        title: item.title,\n        html: item.content,\n        feature_image: item.feature_image,\n        custom_excerpt: item.excerpt\n      }]\n    })\n  }\n}];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1136,
        256
      ],
      "id": "9f2af234-4d9a-43d7-9252-9fbf2c57eb1e",
      "name": "Prepare post creation request body"
    },
    {
      "parameters": {
        "jsCode": "const item = $input.all()[0].json;\nconst feature_image = item.images[0].url;\n\nreturn [{ json: { feature_image } }];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        736,
        -64
      ],
      "id": "ed85b1a9-a9e5-411b-b416-2a7e5514e8b5",
      "name": "Transform cover image upload response"
    },
    {
      "parameters": {
        "resource": "image",
        "prompt": "=Draw a cover image for an article: {{ $json.cover_prompt }}\n\nStyle:\n- Minimalistic flat vector illustration with very subtle gradients.\n- Soft pastel colors (blue, purple, yellow).\n- Thin smooth outlines.\n- Soft shadows.\n- Lots of whitespace.\n- IMPORTANT: White background\n\nComposition:\n- Centered, balanced layout with 2-4 simple elements.\n- Extremely minimal, no clutter.\n\nContent:\n- Create an abstract visual metaphor representing the main idea of the article below.\n- Add mentioned technologies logos and color palettes in a subtle way, integrated into the design.\n\nConstraints:\n- No text\n- No labels\n- No UI elements\n- No photorealism\n- No complex or small details\n- White background",
        "options": {
          "dalleQuality": "hd",
          "size": "1792x1024",
          "returnImageUrls": false
        }
      },
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 2.1,
      "position": [
        160,
        32
      ],
      "id": "d68e26c4-fc47-46ef-8000-3c15e69aaa70",
      "name": "Generate cover image",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "onError": "continueErrorOutput"
    },
    {
      "parameters": {
        "jsCode": "return [{ json: { feature_image: null } }];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        352,
        112
      ],
      "id": "ce55f97c-272d-4577-87e4-19b65ff57704",
      "name": "Return empty feature_image"
    }
  ],
  "connections": {
    "Trigger": {
      "main": [
        [
          {
            "node": "Parse JSON",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse JSON": {
      "main": [
        [
          {
            "node": "Generate cover image",
            "type": "main",
            "index": 0
          },
          {
            "node": "Merge JSON",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Merge JSON": {
      "main": [
        [
          {
            "node": "Prepare post creation request body",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate random cover image file name": {
      "main": [
        [
          {
            "node": "Upload cover image",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload cover image": {
      "main": [
        [
          {
            "node": "Transform cover image upload response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare post creation request body": {
      "main": [
        [
          {
            "node": "Create Ghost Post",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Transform cover image upload response": {
      "main": [
        [
          {
            "node": "Merge JSON",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate cover image": {
      "main": [
        [
          {
            "node": "Generate random cover image file name",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Return empty feature_image",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Return empty feature_image": {
      "main": [
        [
          {
            "node": "Merge JSON",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": true,
  "settings": {
    "executionOrder": "v1",
    "binaryMode": "separate",
    "availableInMCP": true,
    "timeSavedMode": "fixed",
    "callerPolicy": "workflowsFromSameOwner"
  },
  "versionId": "960108f5-a703-4dd0-8947-9b9d4019ca0e",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "id": "WdJ1AnlVOTpyf1Us",
  "tags": []
}