{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "f8952f15-2a54-4207-bf1f-ca0eea5401c2",
      "name": "Limit",
      "type": "n8n-nodes-base.limit",
      "position": [
        -1880,
        120
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "fc809d41-c4c5-4161-bad6-3acda9dac3f3",
      "name": "Structured Output Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        -1500,
        340
      ],
      "parameters": {
        "schemaType": "manual",
        "inputSchema": "{\n\t\"type\": \"object\",\n\t\"properties\": {\n\t\t\"post\": {\n\t\t\t\"type\": \"string\"\n\t\t}\t\t\n\t}\n}"
      },
      "typeVersion": 1.2
    },
    {
      "id": "649c6459-7a72-4192-b172-3edea35ae770",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -1620,
        340
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o",
          "cachedResultName": "gpt-4o"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "f90a4f81-216b-470f-9885-bc9df8ca375e",
      "name": "Linkedin-Post-Topic",
      "type": "n8n-nodes-base.googleSheetsTrigger",
      "position": [
        -2320,
        120
      ],
      "parameters": {
        "options": {},
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/147NIoP4NAZtmXdjciHyKdOWqpPvJ9ifoS8P6HJxikY8/edit#gid=0",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "147NIoP4NAZtmXdjciHyKdOWqpPvJ9ifoS8P6HJxikY8",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/147NIoP4NAZtmXdjciHyKdOWqpPvJ9ifoS8P6HJxikY8/edit?usp=drivesdk",
          "cachedResultName": "Linkedin Post"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "ccea615a-d960-4493-9a87-69ff1b5380c3",
      "name": "Validate-Status",
      "type": "n8n-nodes-base.if",
      "position": [
        -2100,
        120
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "ddab9b1e-0de2-4eb9-8d7b-b9f0846eb496",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.Status }}",
              "rightValue": "Pending"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "6ee612ac-5a46-4c50-b4ca-3620578e8388",
      "name": "Linedin-Post-Creator",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -1660,
        120
      ],
      "parameters": {
        "text": "=You are a LinkedIn post writer. You will be given a title and your task is to create an engaging LinkedIn post based on that title.\n\nYour post should:\n\nBegin with a compelling hook related to the title\n\nInclude 3-4 paragraphs of informative content\n\nEnd with a question to encourage engagement\n\nInclude 4-6 relevant hashtags\n\nUse appropriate emojis in between\n\nImportant formatting requirements:\n\nFormat all paragraphs with proper newline characters (\\n\\n) between them\n\nEnsure the text is properly escaped for JSON\n\nDo not use double quote (\") in response or any special character\n\nDo not put asterisk\n\nKeep the overall length appropriate for LinkedIn (under 3000 characters)\n\nNow, create a LinkedIn post based on the following title:\n{{ $('Linkedin-Post-Topic').item.json['Linkedin Post Title'] }}",
        "options": {},
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 1.9
    },
    {
      "id": "dad86e35-7fdf-4ad2-999a-39d8d7827769",
      "name": "Format-Content",
      "type": "n8n-nodes-base.code",
      "position": [
        -1280,
        120
      ],
      "parameters": {
        "jsCode": "const items = $input.all();\n\n\n\n\n//const postData = $('Limit').first().json.ID;\n\n// Store this value in a workflow variable that can be accessed by other nodes\n//$variables.PostId = postData;\n\n//$workflow.setContext('postContent', postData);\n\n// Also store it in a more persistent variable if needed across workflows\n//$variables.set('postData', postData);\n\n\n\n const updatedItems = items.map((item) => {\n  item.json.output.post = JSON.stringify(item.json.output.post);\n  return item;\n});\nreturn updatedItems; \n\n\n"
      },
      "typeVersion": 2
    },
    {
      "id": "46baf319-14bd-47fe-8f5b-5eda101ead3a",
      "name": "Linkedin-User-Detail",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -1060,
        120
      ],
      "parameters": {
        "url": "https://api.linkedin.com/v2/userinfo",
        "options": {
          "response": {
            "response": {}
          }
        },
        "sendBody": true,
        "authentication": "genericCredentialType",
        "bodyParameters": {
          "parameters": [
            {}
          ]
        },
        "genericAuthType": "httpHeaderAuth"
      },
      "typeVersion": 4.2
    },
    {
      "id": "50db6b67-e0cc-4c43-accd-9f3ad8517476",
      "name": "Linkedin-post",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -840,
        120
      ],
      "parameters": {
        "url": "https://api.linkedin.com/v2/ugcPosts",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"author\": \"urn:li:person:{{ $('Linkedin-User-Detail').item.json.sub }}\",\n  \"lifecycleState\": \"PUBLISHED\",\n  \"specificContent\": {\n    \"com.linkedin.ugc.ShareContent\": {\n      \"shareCommentary\": {\n        \"text\": {{ $('Format-Content').item.json.output.post }}\n      },\n      \"shareMediaCategory\": \"NONE\"\n      }\n  },\n  \"visibility\": {\n    \"com.linkedin.ugc.MemberNetworkVisibility\": \"PUBLIC\"\n  }\n}",
        "sendBody": true,
        "specifyBody": "json",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth"
      },
      "typeVersion": 4.2
    },
    {
      "id": "f798cd8c-289e-493f-9d27-36a37fe72ae8",
      "name": "Get-Group-id",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -620,
        120
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 1240468053,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/147NIoP4NAZtmXdjciHyKdOWqpPvJ9ifoS8P6HJxikY8/edit#gid=1240468053",
          "cachedResultName": "Groups"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "147NIoP4NAZtmXdjciHyKdOWqpPvJ9ifoS8P6HJxikY8",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/147NIoP4NAZtmXdjciHyKdOWqpPvJ9ifoS8P6HJxikY8/edit?usp=drivesdk",
          "cachedResultName": "Linkedin Post"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.5
    },
    {
      "id": "049fc19a-9c29-491a-b3a7-fe9aadee6583",
      "name": "Pick 1 by 1",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        -400,
        120
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "bea35dda-9e97-4b02-90a9-ce6f17ba4c5a",
      "name": "Post-Linkedin-Groups",
      "type": "n8n-nodes-base.httpRequest",
      "onError": "continueRegularOutput",
      "position": [
        -180,
        160
      ],
      "parameters": {
        "url": "https://api.linkedin.com/v2/ugcPosts",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"author\": \"urn:li:person:{{ $('Linkedin-User-Detail').item.json.sub }}\",\n  \"containerEntity\": \"urn:li:group:{{ $json.GroupIds }}\",\n  \"lifecycleState\": \"PUBLISHED\",\n  \"specificContent\": {\n    \"com.linkedin.ugc.ShareContent\": {\n      \"shareCommentary\": {\n        \"text\": {{ $('Format-Content').item.json.output.post }}\n      },\n      \"shareMediaCategory\": \"NONE\"\n    }\n  },\n  \"visibility\": {\n    \"com.linkedin.ugc.MemberNetworkVisibility\": \"PUBLIC\"\n  }\n}",
        "sendBody": true,
        "specifyBody": "json",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth"
      },
      "typeVersion": 4.2
    },
    {
      "id": "9887fef3-d784-446a-877d-297ad835a6ed",
      "name": "Update-Status",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -180,
        -40
      ],
      "parameters": {
        "columns": {
          "value": {
            "ID": "={{ $('Limit').item.json.ID }}",
            "Status": "Posted"
          },
          "schema": [
            {
              "id": "ID",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "ID",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Linkedin Post Title",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Linkedin Post Title",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Image Path",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Image Path",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Status",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Status",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "row_number",
              "type": "string",
              "display": true,
              "removed": true,
              "readOnly": true,
              "required": false,
              "displayName": "row_number",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "ID"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "update",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/147NIoP4NAZtmXdjciHyKdOWqpPvJ9ifoS8P6HJxikY8/edit#gid=0",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "147NIoP4NAZtmXdjciHyKdOWqpPvJ9ifoS8P6HJxikY8",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/147NIoP4NAZtmXdjciHyKdOWqpPvJ9ifoS8P6HJxikY8/edit?usp=drivesdk",
          "cachedResultName": "Linkedin Post"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.5
    },
    {
      "id": "d2d2d0b1-666d-4cfc-8f3b-e528c1b7d33d",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -3120,
        -360
      ],
      "parameters": {
        "width": 520,
        "height": 1480,
        "content": "LinkedIn AI Agent: Auto-Post Creator & Distributor\nAutomatically generate engaging LinkedIn posts from Google Sheets topics and publish them to your profile and multiple LinkedIn groups. Perfect for:\n\u2705 Content creators \u2014 scale your LinkedIn presence effortlessly\n\u2705 Marketers \u2014 maintain consistent professional posting\n\u2705 Thought leaders \u2014 amplify reach across relevant communities\n\n\u2699\ufe0f What's Used\nn8n Nodes:\nGoogle Sheets Trigger \u2192 AI Agent \u2192 OpenAI Chat Model \u2192 LinkedIn API \u2192 Group Distribution\nExternal Tools:\n\nGoogle Sheets \u2013 Store post topics and group IDs\nOpenAI GPT-4 \u2013 Generate engaging LinkedIn content\nLinkedIn API \u2013 Publish to profile and groups\nCustom Formatting \u2013 Ensure proper LinkedIn formatting\n\n\n\ud83d\udd11 Setup \u2013 Credentials Needed\n\nGoogle Sheets OAuth2 \u2192 Access your content spreadsheet\nOpenAI API Key \u2192 For AI content generation\nLinkedIn OAuth2 \u2192 Publish posts to your profile and groups\nHTTP Request Auth \u2192 LinkedIn API authentication headers\n\n\n\ud83d\udcca Google Sheets Structure Required\nCreate a spreadsheet with two sheets:\nSheet 1 - Main Posts:\n\nID (unique identifier)\nLinkedIn Post Title (topic/title for AI to expand)\nStatus (Pending/Posted)\n\nSheet 2 - Groups:\n\nGroupIds (LinkedIn group IDs you want to post to)\n\nNote: You'll need to collect LinkedIn group IDs from groups you've joined and have posting permissions for.\n\n\ud83d\ude80 Workflow Steps\n\nMonitor Google Sheets\nTrigger watches for new \"Pending\" status posts every minute\nGenerate AI Content\nAI Agent creates engaging LinkedIn posts with:\n\nCompelling hooks\n3-4 informative paragraphs\nEngagement questions\nRelevant hashtags and emojis\n\n\nFormat for LinkedIn\nEnsures proper JSON formatting and character limits\nPublish to Profile\nPosts directly to your personal LinkedIn profile\nDistribute to Groups\nAutomatically shares to all specified LinkedIn groups\nUpdate Status\nMarks the post as \"Posted\" in Google Sheets\n\n\n\ud83d\udcdd Content Generation Features\nAI-Powered Writing:\n\nProfessional tone and structure\nProper LinkedIn formatting with newlines\n4-6 relevant hashtags\nStrategic emoji placement\nUnder 3000 character limit\nEngagement-focused questions\n\nSmart Processing:\n\nJSON-safe formatting\nSpecial character handling\nParagraph structure optimization\n\n\n\ud83d\udca1 Pro Tips\n\nStart with 3-5 LinkedIn groups to test posting permissions\nUse descriptive post titles in your spreadsheet for better AI generation\nMonitor group engagement rules to avoid spam flags\nSchedule posts by updating status from \"Pending\" at desired times\nKeep a backup of successful post formats for consistency"
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "Limit": {
      "main": [
        [
          {
            "node": "Linedin-Post-Creator",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Pick 1 by 1": {
      "main": [
        [
          {
            "node": "Update-Status",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Post-Linkedin-Groups",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get-Group-id": {
      "main": [
        [
          {
            "node": "Pick 1 by 1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Linkedin-post": {
      "main": [
        [
          {
            "node": "Get-Group-id",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format-Content": {
      "main": [
        [
          {
            "node": "Linkedin-User-Detail",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Validate-Status": {
      "main": [
        [
          {
            "node": "Limit",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Linedin-Post-Creator",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Linkedin-Post-Topic": {
      "main": [
        [
          {
            "node": "Validate-Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Linedin-Post-Creator": {
      "main": [
        [
          {
            "node": "Format-Content",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Linkedin-User-Detail": {
      "main": [
        [
          {
            "node": "Linkedin-post",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Post-Linkedin-Groups": {
      "main": [
        [
          {
            "node": "Pick 1 by 1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "Linedin-Post-Creator",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    }
  }
}