{
  "id": "C1xiyGkvbb4Fnsmt",
  "name": "Content Repurpose Workflow",
  "active": false,
  "isArchived": false,
  "versionId": "1476e954-1063-4c61-ab16-6c707b70b3e4",
  "settings": {
    "executionOrder": "v1",
    "availableInMCP": true
  },
  "connections": {
    "Receive Blog Post": {
      "main": [
        [
          {
            "node": "Generate LinkedIn Posts",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate LinkedIn Posts": {
      "main": [
        [
          {
            "node": "Generate Tweets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Tweets": {
      "main": [
        [
          {
            "node": "Parse and Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse and Merge": {
      "main": [
        [
          {
            "node": "Append to Google Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Append to Google Sheets": {
      "main": [
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "nodes": [
    {
      "id": "10cb1a7c-d8ed-4d91-8bb1-0676bcac670c",
      "name": "Receive Blog Post",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2.1,
      "position": [
        0,
        0
      ],
      "parameters": {
        "httpMethod": "POST",
        "path": "content-repurpose",
        "responseMode": "responseNode"
      }
    },
    {
      "id": "387bc352-bc6f-45e4-9827-7e9316ce593b",
      "name": "Generate LinkedIn Posts",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        224,
        0
      ],
      "parameters": {
        "method": "POST",
        "url": "={{ $vars.OPENROUTER_BASE_URL }}/chat/completions",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "httpHeaderAuth",
        "sendBody": true,
        "contentType": "json",
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ model: $vars.OPENROUTER_MODEL, messages: [{ role: \"system\", content: \"You are a LinkedIn content strategist. Given a blog post, generate exactly 5 LinkedIn posts optimized for engagement. Each post should be 150-300 words with relevant hashtags. Respond ONLY with valid JSON: {\\\"posts\\\": [\\\"post1\\\", \\\"post2\\\", \\\"post3\\\", \\\"post4\\\", \\\"post5\\\"]}\" }, { role: \"user\", content: \"Blog post:\\n\" + ($json.body?.blog_text ?? $json.blog_text ?? \"\") }] }) }}",
        "options": {
          "timeout": 30000
        }
      }
    },
    {
      "id": "537d53d5-705f-4161-9b2c-d0cf6bbfa366",
      "name": "Generate Tweets",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        448,
        0
      ],
      "parameters": {
        "method": "POST",
        "url": "={{ $vars.OPENROUTER_BASE_URL }}/chat/completions",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "httpHeaderAuth",
        "sendBody": true,
        "contentType": "json",
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ model: $vars.OPENROUTER_MODEL, messages: [{ role: \"system\", content: \"You are a Twitter/X content strategist. Given LinkedIn posts, generate exactly 10 tweets under 280 characters each with relevant hashtags. Respond ONLY with valid JSON: {\\\"tweets\\\": [\\\"tweet1\\\", \\\"tweet2\\\", \\\"tweet3\\\", \\\"tweet4\\\", \\\"tweet5\\\", \\\"tweet6\\\", \\\"tweet7\\\", \\\"tweet8\\\", \\\"tweet9\\\", \\\"tweet10\\\"]}\" }, { role: \"user\", content: \"LinkedIn posts:\\n\" + $json.choices[0].message.content }] }) }}",
        "options": {
          "timeout": 30000
        }
      }
    },
    {
      "id": "85f5aab2-3a03-4f83-9562-58891bbd5a13",
      "name": "Parse and Merge",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        672,
        0
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "language": "javaScript",
        "jsCode": "// Parse LinkedIn posts\nconst linkedinRaw = $('Generate LinkedIn Posts').first().json?.choices?.[0]?.message?.content ?? '';\nlet linkedin = { posts: [] };\ntry {\n  const s = linkedinRaw.replace(/```(?:json)?\\n?/g, '').trim();\n  linkedin = JSON.parse(s);\n} catch(e) {\n  linkedin = { posts: [`Parse error: ${e.message}`] };\n}\n\n// Parse tweets\nconst tweetsRaw = $input.first().json?.choices?.[0]?.message?.content ?? '';\nlet tweetsData = { tweets: [] };\ntry {\n  const s = tweetsRaw.replace(/```(?:json)?\\n?/g, '').trim();\n  tweetsData = JSON.parse(s);\n} catch(e) {\n  tweetsData = { tweets: [`Parse error: ${e.message}`] };\n}\n\nconst blogText = $('Receive Blog Post').first().json?.body?.blog_text ?? $('Receive Blog Post').first().json?.blog_text ?? '';\n\nreturn [{json: {\n  blog_text: blogText,\n  linkedin_posts: linkedin.posts ?? [],\n  tweets: tweetsData.tweets ?? [],\n  generated_at: new Date().toISOString()\n}}];"
      }
    },
    {
      "id": "0e982c79-8af7-401a-9ff3-c3556af0db69",
      "name": "Append to Google Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        896,
        0
      ],
      "parameters": {
        "resource": "sheet",
        "operation": "append",
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "YOUR_SPREADSHEET_ID"
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Sheet1"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "blog_text": "={{ $json.blog_text.substring(0, 500) }}",
            "linkedin_posts": "={{ JSON.stringify($json.linkedin_posts) }}",
            "tweets": "={{ JSON.stringify($json.tweets) }}",
            "generated_at": "={{ $json.generated_at }}"
          },
          "schema": [
            {
              "id": "blog_text",
              "displayName": "blog_text",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": false
            },
            {
              "id": "linkedin_posts",
              "displayName": "linkedin_posts",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": false
            },
            {
              "id": "tweets",
              "displayName": "tweets",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": false
            },
            {
              "id": "generated_at",
              "displayName": "generated_at",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": false
            }
          ]
        }
      }
    },
    {
      "id": "c64c32be-931e-4182-9a7a-5084e9e48080",
      "name": "Respond to Webhook",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.5,
      "position": [
        1120,
        0
      ],
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ { linkedin_posts: $json.linkedin_posts, tweets: $json.tweets } }}"
      }
    }
  ],
  "tags": [],
  "meta": {
    "aiBuilderAssisted": true,
    "builderVariant": "mcp"
  },
  "description": "Transforms a blog post into 5 LinkedIn posts and 10 tweets via two sequential OpenRouter AI calls, logs to Google Sheets, and responds with structured JSON."
}