{"name":"Webhook to LinkedIn with PubNio (queue requests, approve in a data table)","nodes":[{"parameters":{"httpMethod":"POST","path":"pubnio-post-request","authentication":"headerAuth","responseMode":"responseNode","options":{}},"id":"3b15e948-c72d-46e2-a297-c3af0bb16640","name":"Post request","type":"n8n-nodes-base.webhook","typeVersion":2.1,"position":[0,0],"webhookId":"5b0e7c1e-2f3a-4d6b-9c8e-1a2b3c4d5e6f"},{"parameters":{"conditions":{"options":{"caseSensitive":true,"leftValue":"","typeValidation":"loose","version":2},"conditions":[{"id":"9be97571-0735-4cc8-adf0-28825f8203a5","leftValue":"={{ $json.body.id }}","rightValue":"","operator":{"type":"string","operation":"notEmpty","singleValue":true}},{"id":"1c243e22-ad20-4c13-a95f-4d00cca34bf1","leftValue":"={{ $json.body.text }}","rightValue":"","operator":{"type":"string","operation":"notEmpty","singleValue":true}}],"combinator":"and"},"looseTypeValidation":true,"options":{}},"id":"b9900967-78a7-4446-a301-f5328d19bb89","name":"Has id and text?","type":"n8n-nodes-base.if","typeVersion":2.2,"position":[220,0]},{"parameters":{"mode":"runOnceForEachItem","jsCode":"// The caller's own ID is the stable row ID: a retried request is\n// answered as a duplicate and queues nothing.\nreturn { json: {\n  source_id: 'request-' + String($json.body.id).trim(),\n  text: String($json.body.text).trim(),\n  detail: String($json.body.image_url || '').trim(),\n} };"},"id":"e3f32140-1fdd-445a-a13e-5d07007c2c1b","name":"Compose post","type":"n8n-nodes-base.code","typeVersion":2,"position":[440,-100]},{"parameters":{"respondWith":"json","responseBody":"={{ JSON.stringify({ error: 'Send JSON with id and text.' }) }}","options":{"responseCode":400}},"id":"911ab6d6-a6cf-4d50-a89f-46ac0d60ad66","name":"Reject request","type":"n8n-nodes-base.respondToWebhook","typeVersion":1.4,"position":[440,160]},{"parameters":{"operation":"rowExists","dataTableId":{"__rl":true,"value":"pubnio_requests","mode":"name"},"filters":{"conditions":[{"keyName":"source_id","keyValue":"={{ $json.source_id }}"}]}},"id":"816c3dea-93ae-40c2-a119-f5a8aaecf843","name":"Already queued?","type":"n8n-nodes-base.dataTable","typeVersion":1.1,"position":[660,-260]},{"parameters":{"respondWith":"json","responseBody":"={{ JSON.stringify({ queued: true, duplicate: true, id: $json.source_id }) }}","options":{"responseCode":200}},"id":"d59cea01-2e08-4b67-a832-b41de7fddf56","name":"Answer duplicate","type":"n8n-nodes-base.respondToWebhook","typeVersion":1.4,"position":[880,-260]},{"parameters":{"operation":"rowNotExists","dataTableId":{"__rl":true,"value":"pubnio_requests","mode":"name"},"filters":{"conditions":[{"keyName":"source_id","keyValue":"={{ $json.source_id }}"}]}},"id":"7b872d75-33dd-41a7-a8d4-b061de42a69f","name":"Skip items already queued","type":"n8n-nodes-base.dataTable","typeVersion":1.1,"position":[660,0]},{"parameters":{"operation":"insert","dataTableId":{"__rl":true,"value":"pubnio_requests","mode":"name"},"columns":{"mappingMode":"defineBelow","value":{"source_id":"={{ $json.source_id }}","text":"={{ $json.text }}","detail":"={{ $json.detail }}","approved":"={{ false }}"},"matchingColumns":[]},"options":{}},"id":"3ffe02c3-062d-4280-a1a9-5dec399797d3","name":"Queue for approval","type":"n8n-nodes-base.dataTable","typeVersion":1.1,"position":[880,0]},{"parameters":{"rule":{"interval":[{"field":"minutes","minutesInterval":15}]}},"id":"8eda6f62-bc82-485c-ac12-1e7989aceef0","name":"Every 15 minutes","type":"n8n-nodes-base.scheduleTrigger","typeVersion":1.2,"position":[0,400]},{"parameters":{"assignments":{"assignments":[{"id":"afac8d7d-acf1-42e5-af4c-9bdf6464ba85","name":"baseUrl","value":"https://pubnio.com","type":"string"},{"id":"fd7fc55e-e3bf-4e60-a8d3-809a43378d3e","name":"workspaceId","value":"","type":"string"},{"id":"c55cc2a0-8f99-487d-af8a-19d6feb2265f","name":"linkedinAccountId","value":"","type":"string"}]},"options":{}},"id":"04dda128-06fd-4964-a4bd-161d7a3d4b6e","name":"PubNio settings","type":"n8n-nodes-base.set","typeVersion":3.4,"position":[220,400]},{"parameters":{"operation":"get","dataTableId":{"__rl":true,"value":"pubnio_requests","mode":"name"},"filters":{"conditions":[{"keyName":"approved","condition":"isTrue"}]},"returnAll":true},"id":"15ebcca7-f678-4f95-a4b3-9ed856d163be","name":"Read approved rows","type":"n8n-nodes-base.dataTable","typeVersion":1.1,"position":[440,400]},{"parameters":{"mode":"runOnceForEachItem","jsCode":"// One approved data table row becomes one post.\nconst s = $('PubNio settings').first().json;\nconst text = (value) => String(value ?? '').trim();\nconst row = {\n  rowId: text($json.source_id),\n  approved: $json.approved === true,\n  key: text($json.pubnio_key),\n  postId: text($json.pubnio_post_id),\n  status: text($json.pubnio_status),\n  sentAt: text($json.pubnio_sent_at),\n  outcome: text($json.pubnio_outcome),\n  mediaUrl: text($json.detail),\n};\nconst body = { text: text($json.text), accounts: [s.linkedinAccountId] };\nreturn { json: { ...row, body } };"},"id":"a59fccab-4adb-4ae3-ae96-17bc679c874d","name":"Normalize row","type":"n8n-nodes-base.code","typeVersion":2,"position":[660,400]},{"parameters":{"conditions":{"options":{"caseSensitive":true,"leftValue":"","typeValidation":"loose","version":2},"conditions":[{"id":"ae0246c8-db9d-4fe5-a34e-00bfdfd62000","leftValue":"={{ $json.approved }}","rightValue":"","operator":{"type":"boolean","operation":"true","singleValue":true}},{"id":"72ac9217-fb61-4d3e-aac1-dedf3d8b489f","leftValue":"={{ $json.rowId }}","rightValue":"","operator":{"type":"string","operation":"notEmpty","singleValue":true}}],"combinator":"and"},"looseTypeValidation":true,"options":{}},"id":"8cac91e6-aee7-41e1-a7d6-efaf475da38e","name":"Approved?","type":"n8n-nodes-base.if","typeVersion":2.2,"position":[880,400]},{"parameters":{},"id":"5795f4b6-6e99-475c-aac9-f3aafd0d9365","name":"Not approved: skip","type":"n8n-nodes-base.noOp","typeVersion":1,"position":[1100,700]},{"parameters":{"mode":"runOnceForEachItem","jsCode":"// Decide what one approved row needs. The idempotency key is a hash of the\n// row ID, saved on the row before the first request, so a rerun after a\n// timeout sends the same key and PubNio replays its first answer.\nconst hash = (value) => {\n  let h1 = 1779033703, h2 = 3144134277, h3 = 1013904242, h4 = 2773480762;\n  for (let i = 0; i < value.length; i++) {\n    const k = value.charCodeAt(i);\n    h1 = h2 ^ Math.imul(h1 ^ k, 597399067);\n    h2 = h3 ^ Math.imul(h2 ^ k, 2869860233);\n    h3 = h4 ^ Math.imul(h3 ^ k, 951274213);\n    h4 = h1 ^ Math.imul(h4 ^ k, 2716044179);\n  }\n  h1 = Math.imul(h3 ^ (h1 >>> 18), 597399067);\n  h2 = Math.imul(h4 ^ (h2 >>> 22), 2869860233);\n  h3 = Math.imul(h1 ^ (h3 >>> 17), 951274213);\n  h4 = Math.imul(h2 ^ (h4 >>> 19), 2716044179);\n  h1 ^= h2 ^ h3 ^ h4; h2 ^= h1; h3 ^= h1; h4 ^= h1;\n  return [h1, h2, h3, h4].map((h) => (h >>> 0).toString(16).padStart(8, '0')).join('');\n};\nconst row = $json;\nconst replayWindowMs = 23 * 60 * 60 * 1000; // PubNio replays a key for 24 hours.\nconst finished = ['published', 'provider_draft', 'failed', 'cancelled', 'rejected', 'needs_review'];\nconst fresh = !row.key;\nconst key = row.key || 'n8n-' + $workflow.id + '-' + hash(String(row.rowId));\nconst sentAt = fresh ? new Date().toISOString() : row.sentAt;\n// One media import per row and URL; a resend after a rejection gets a new sentAt, so a new import.\nconst mediaKey = row.mediaUrl ? key + '-m' + hash(row.mediaUrl + '|' + sentAt).slice(0, 16) : '';\nlet action = 'submit';\nif (row.postId) action = finished.includes(row.status) ? 'done' : 'sync';\nelse if (finished.includes(row.status)) action = 'done';\n// A saved key without a readable send time fails closed: it may be older than the replay window.\nelse if (!fresh && !(Date.now() - Date.parse(row.sentAt) <= replayWindowMs)) action = 'stale';\nelse if (fresh && row.problem) action = 'invalid';\nreturn { json: { ...row, key, sentAt, mediaKey, fresh, action } };"},"id":"f2d9425e-7d9b-4cf0-a6b0-5e723df3ab95","name":"Plan action","type":"n8n-nodes-base.code","typeVersion":2,"position":[1100,300]},{"parameters":{"rules":{"values":[{"conditions":{"options":{"caseSensitive":true,"leftValue":"","typeValidation":"strict","version":2},"conditions":[{"id":"7061ce0d-3bcf-4927-a322-f0236675de0c","leftValue":"={{ $json.action }}","rightValue":"submit","operator":{"type":"string","operation":"equals"}}],"combinator":"and"},"renameOutput":true,"outputKey":"submit"},{"conditions":{"options":{"caseSensitive":true,"leftValue":"","typeValidation":"strict","version":2},"conditions":[{"id":"0012eaa5-f2e1-416e-ac6e-403cc6113b41","leftValue":"={{ $json.action }}","rightValue":"sync","operator":{"type":"string","operation":"equals"}}],"combinator":"and"},"renameOutput":true,"outputKey":"sync"},{"conditions":{"options":{"caseSensitive":true,"leftValue":"","typeValidation":"strict","version":2},"conditions":[{"id":"66dcef57-1130-4a48-a337-e48767889aaa","leftValue":"={{ $json.action }}","rightValue":"stale","operator":{"type":"string","operation":"equals"}}],"combinator":"and"},"renameOutput":true,"outputKey":"stale"},{"conditions":{"options":{"caseSensitive":true,"leftValue":"","typeValidation":"strict","version":2},"conditions":[{"id":"b5612b0e-ca05-4457-ab83-3a090938f45e","leftValue":"={{ $json.action }}","rightValue":"invalid","operator":{"type":"string","operation":"equals"}}],"combinator":"and"},"renameOutput":true,"outputKey":"invalid"},{"conditions":{"options":{"caseSensitive":true,"leftValue":"","typeValidation":"strict","version":2},"conditions":[{"id":"af2b375b-7f5e-4fb6-a8f0-1ee292d18ff5","leftValue":"={{ $json.action }}","rightValue":"done","operator":{"type":"string","operation":"equals"}}],"combinator":"and"},"renameOutput":true,"outputKey":"done"}]},"options":{}},"id":"c2b035db-b756-4c12-a2c3-8a10e90d121a","name":"Route by action","type":"n8n-nodes-base.switch","typeVersion":3.2,"position":[1320,300]},{"parameters":{"mode":"runOnceForEachItem","jsCode":"// Map PubNio's answer onto the row. A 202 only means PubNio accepted the\n// work; the row says published only when a delivery reports it.\nconst plan = $('Plan action').item.json;\nconst res = $input.item.json;\nconst body = res.body && typeof res.body === 'object' ? res.body : {};\nconst code = Number(res.statusCode);\nconst reject = (out) => Object.assign(out, { status: 'rejected', key: '', sentAt: '' });\nconst active = ['submitting', 'confirming', 'queued', 'scheduled'];\nconst settled = ['unresolved', 'failed', 'published', 'provider_draft', 'cancelled'];\nconst pick = (states) => active.find((s) => states.includes(s)) || settled.find((s) => states.includes(s)) || 'queued';\nconst line = (t) => [\n  t.provider + ' ' + t.placement + ': ' + t.status,\n  t.status === 'scheduled' && t.scheduledAt ? 'at ' + t.scheduledAt : '',\n  t.localDate ? '(queue slot ' + t.localDate + ' ' + t.localTime + ' ' + t.timezone + ')' : '',\n  t.url || '',\n  t.issue ? '[' + t.issue + ']' : '',\n  t.nextAction ? 'Next: ' + t.nextAction : '',\n].filter(Boolean).join(' ');\nconst out = {\n  rowId: plan.rowId,\n  key: plan.key,\n  sentAt: plan.sentAt,\n  postId: plan.postId || '',\n  status: plan.status || '',\n  outcome: plan.outcome || '',\n  error: '',\n  revision: plan.draftRevision || '',\n  media: plan.sentMedia || '',\n  retryFailed: plan.retryFailed,\n};\nif (code >= 200 && code < 300) {\n  const targets = body.deliveries || body.targets || [];\n  out.postId = body.postId || out.postId;\n  out.status = body.status || pick(targets.map((t) => t.status));\n  out.outcome = targets.map(line).join('\\n');\n  if (body.revision) out.revision = body.revision;\n  if (plan.mediaUrl !== undefined) out.media = plan.mediaUrl;\n  return { json: out };\n}\nconst problem = body.code || String(body.type || '').split('/').filter(Boolean).pop() || 'http_' + code;\nout.error = [\n  code + ' ' + problem + (body.title ? ': ' + body.title : ''),\n  ...(body.issues || body.errors || []).map((i) => (i.code || 'invalid') + ' at ' + (i.path || []).join('.') + ': ' + i.message),\n  body.currentRevision ? 'The draft is now revision ' + body.currentRevision + '.' : '',\n  body.nextAction ? 'Next: ' + body.nextAction : '',\n].filter(Boolean).join('\\n');\n// A read or a draft step failed: keep the post and its last known state.\nif (plan.postId) out.status = code === 404 ? 'needs_review' : plan.status;\n// The key was used for another body, or the same text and media already went to\n// this account in the last 24 hours: resending cannot help, so a person decides.\nelse if (problem === 'idempotency_conflict' || problem === 'duplicate_content') out.status = 'needs_review';\n// In progress, rate limited, or a server error: the outcome is unknown, so the\n// next run resends the same key and PubNio replays the first answer.\nelse if (code === 409 || code === 429 || code >= 500) out.status = 'sending';\n// PubNio refused the request and stored nothing. Fix the row, then clear\n// pubnio_status to send it again.\nelse reject(out);\nreturn { json: out };"},"id":"119811a2-769b-4ca7-ab68-9f900aaf00ab","name":"Record PubNio answer","type":"n8n-nodes-base.code","typeVersion":2,"position":[3300,200]},{"parameters":{"mode":"runOnceForEachItem","jsCode":"// The request got no answer (timeout or network). PubNio may have accepted\n// it, so keep the key: the next run resends it and PubNio replays.\nconst plan = $('Plan action').item.json;\nconst error = $json.error || {};\nconst out = {\n  rowId: plan.rowId,\n  key: plan.key,\n  sentAt: plan.sentAt,\n  postId: plan.postId || '',\n  status: plan.postId ? plan.status : 'sending',\n  outcome: plan.outcome || '',\n  error: '',\n  revision: plan.draftRevision || '',\n  media: plan.sentMedia || '',\n  retryFailed: plan.retryFailed,\n};\nout.error = 'No answer from PubNio: ' + (error.message || error.description || 'request failed');\nreturn { json: out };"},"id":"18172a56-de57-4ca2-ae44-57fdde0ef740","name":"Record missing answer","type":"n8n-nodes-base.code","typeVersion":2,"position":[3300,400]},{"parameters":{"operation":"update","dataTableId":{"__rl":true,"value":"pubnio_requests","mode":"name"},"filters":{"conditions":[{"keyName":"source_id","condition":"eq","keyValue":"={{ $json.rowId }}"}]},"columns":{"mappingMode":"defineBelow","value":{"pubnio_key":"={{ $json.key }}","pubnio_post_id":"={{ $json.postId }}","pubnio_status":"={{ $json.status }}","pubnio_outcome":"={{ $json.outcome }}","pubnio_error":"={{ $json.error }}","pubnio_sent_at":"={{ $json.sentAt }}"},"matchingColumns":[]},"options":{}},"id":"887d3354-af23-481b-a4e4-1c3fea2865c8","name":"Write result to row","type":"n8n-nodes-base.dataTable","typeVersion":1.1,"position":[3520,300]},{"parameters":{"operation":"update","dataTableId":{"__rl":true,"value":"pubnio_requests","mode":"name"},"filters":{"conditions":[{"keyName":"source_id","condition":"eq","keyValue":"={{ $('Plan action').item.json.rowId }}"}]},"columns":{"mappingMode":"defineBelow","value":{"pubnio_key":"={{ $('Plan action').item.json.key }}","pubnio_status":"sending","pubnio_sent_at":"={{ $('Plan action').item.json.sentAt }}","pubnio_error":""},"matchingColumns":[]},"options":{}},"id":"b34154f3-aa5b-443c-a95b-d2ce10b8ca71","name":"Save key before sending","type":"n8n-nodes-base.dataTable","typeVersion":1.1,"position":[1560,100]},{"parameters":{"method":"POST","url":"={{ $('PubNio settings').first().json.baseUrl }}/api/v1/posts","authentication":"genericCredentialType","genericAuthType":"httpHeaderAuth","sendQuery":true,"queryParameters":{"parameters":[{"name":"workspaceId","value":"={{ $('PubNio settings').first().json.workspaceId }}"}]},"sendHeaders":true,"headerParameters":{"parameters":[{"name":"Idempotency-Key","value":"={{ $('Plan action').item.json.key }}"},{"name":"PubNio-Version","value":"2026-12-02"}]},"sendBody":true,"specifyBody":"json","jsonBody":"={{ JSON.stringify(Object.assign({}, $('Plan action').item.json.body, $('Plan action').item.json.mediaUrl ? { media: [{ mediaId: $json.body.mediaId }] } : {})) }}","options":{"response":{"response":{"fullResponse":true,"neverError":true,"responseFormat":"json"}},"timeout":30000}},"id":"739fc130-38d5-447d-aefa-7cb68048f2f4","name":"Create post in PubNio","type":"n8n-nodes-base.httpRequest","typeVersion":4.2,"position":[2880,100],"onError":"continueErrorOutput"},{"parameters":{"conditions":{"options":{"caseSensitive":true,"leftValue":"","typeValidation":"loose","version":2},"conditions":[{"id":"1be75205-4474-4102-a2bb-82691f254152","leftValue":"={{ $('Plan action').item.json.mediaUrl }}","rightValue":"","operator":{"type":"string","operation":"notEmpty","singleValue":true}}],"combinator":"and"},"looseTypeValidation":true,"options":{}},"id":"5eadf120-1e29-42de-a4e1-f2994a65128b","name":"Row has media?","type":"n8n-nodes-base.if","typeVersion":2.2,"position":[1780,100]},{"parameters":{"method":"POST","url":"={{ $('PubNio settings').first().json.baseUrl }}/api/v1/media/import","authentication":"genericCredentialType","genericAuthType":"httpHeaderAuth","sendQuery":true,"queryParameters":{"parameters":[{"name":"workspaceId","value":"={{ $('PubNio settings').first().json.workspaceId }}"}]},"sendHeaders":true,"headerParameters":{"parameters":[{"name":"Idempotency-Key","value":"={{ $('Plan action').item.json.mediaKey }}"},{"name":"PubNio-Version","value":"2026-12-02"}]},"sendBody":true,"specifyBody":"json","jsonBody":"={{ JSON.stringify({ url: $('Plan action').item.json.mediaUrl }) }}","options":{"response":{"response":{"fullResponse":true,"neverError":true,"responseFormat":"json"}},"timeout":30000}},"id":"b355ca11-f910-4058-a33d-23004b78ea7b","name":"Import media","type":"n8n-nodes-base.httpRequest","typeVersion":4.2,"position":[2000,100],"onError":"continueErrorOutput"},{"parameters":{"conditions":{"options":{"caseSensitive":true,"leftValue":"","typeValidation":"loose","version":2},"conditions":[{"id":"db6420bc-98d9-4ee6-a83a-98bb4521a163","leftValue":"={{ $json.statusCode >= 200 && $json.statusCode < 300 }}","rightValue":"","operator":{"type":"boolean","operation":"true","singleValue":true}}],"combinator":"and"},"looseTypeValidation":true,"options":{}},"id":"42aaa60f-ecf5-4e7f-a222-e71951eca23d","name":"Import accepted?","type":"n8n-nodes-base.if","typeVersion":2.2,"position":[2220,100]},{"parameters":{"amount":10,"unit":"seconds"},"id":"ba18d82b-20ae-4965-a45b-74374423006e","name":"Wait for media","type":"n8n-nodes-base.wait","typeVersion":1.1,"position":[2440,100],"webhookId":"0c6e6c51-5f1f-4910-a640-f8d0361a3c15"},{"parameters":{"method":"GET","url":"={{ $('PubNio settings').first().json.baseUrl }}/api/v1/media/{{ $json.body.mediaId }}/status","authentication":"genericCredentialType","genericAuthType":"httpHeaderAuth","sendQuery":true,"queryParameters":{"parameters":[{"name":"workspaceId","value":"={{ $('PubNio settings').first().json.workspaceId }}"}]},"sendHeaders":true,"headerParameters":{"parameters":[{"name":"PubNio-Version","value":"2026-12-02"}]},"options":{"response":{"response":{"fullResponse":true,"neverError":true,"responseFormat":"json"}},"timeout":30000}},"id":"abf061b8-1c07-43b5-a9f9-83176bc189c3","name":"Read media status","type":"n8n-nodes-base.httpRequest","typeVersion":4.2,"position":[2660,100],"onError":"continueErrorOutput"},{"parameters":{"conditions":{"options":{"caseSensitive":true,"leftValue":"","typeValidation":"loose","version":2},"conditions":[{"id":"3991419a-43dd-4460-aafe-9a7a3cb3b5b1","leftValue":"={{ $json.statusCode === 200 && $json.body.status === 'ready' }}","rightValue":"","operator":{"type":"boolean","operation":"true","singleValue":true}}],"combinator":"and"},"looseTypeValidation":true,"options":{}},"id":"e71ce69d-5cec-4b44-a5eb-fcc8920795b2","name":"Media ready?","type":"n8n-nodes-base.if","typeVersion":2.2,"position":[2880,100]},{"parameters":{"mode":"runOnceForEachItem","jsCode":"// PubNio imports the row's media URL into the workspace before the post\n// can use it. The import is keyed per row and URL, so the next run replays\n// it and reads the same media again instead of importing a copy.\nconst plan = $('Plan action').item.json;\nconst res = $json;\nconst body = res.body && typeof res.body === 'object' ? res.body : {};\nconst code = Number(res.statusCode);\nconst reject = (out) => Object.assign(out, { status: 'rejected', key: '', sentAt: '' });\nconst out = {\n  rowId: plan.rowId,\n  key: plan.key,\n  sentAt: plan.sentAt,\n  postId: plan.postId || '',\n  status: 'sending',\n  outcome: plan.outcome || '',\n  error: '',\n  revision: plan.draftRevision || '',\n  media: plan.sentMedia || '',\n  retryFailed: plan.retryFailed,\n};\nconst problem = body.code || String(body.type || '').split('/').filter(Boolean).pop() || 'http_' + code;\n// A saved draft keeps its post and status; only its error says what went wrong.\nif (plan.postId) Object.assign(out, { status: plan.status, error: '' });\nif (code >= 200 && code < 300 && body.status === 'failed') {\n  out.error = 'Media import failed: ' + ((body.issue && body.issue.code) || 'unknown') + ' for ' + plan.mediaUrl + '. Fix the URL, then clear pubnio_status to send the row again.';\n  if (!plan.postId) reject(out);\n} else if (code >= 200 && code < 300) {\n  if (!plan.postId) out.status = 'media_processing';\n  out.outcome = 'PubNio is still importing ' + plan.mediaUrl + '; the next run checks it again.';\n} else if (problem === 'idempotency_conflict') {\n  if (!plan.postId) out.status = 'needs_review';\n  out.error = code + ' ' + problem + ': the media key was already used for another URL.';\n} else if (code === 409 || code === 429 || code >= 500) {\n  out.error = code + ' ' + problem + ' while importing ' + plan.mediaUrl + '; the next run tries again.';\n} else {\n  out.error = [code + ' ' + problem + (body.title ? ': ' + body.title : ''), ...(body.issues || body.errors || []).map((i) => (i.code || 'invalid') + ' at ' + (i.path || []).join('.') + ': ' + i.message)].join('\\n');\n  if (!plan.postId) reject(out);\n}\nreturn { json: out };"},"id":"2973397e-8173-4cfa-a6be-26a12f09624b","name":"Record media status","type":"n8n-nodes-base.code","typeVersion":2,"position":[3100,300]},{"parameters":{"method":"GET","url":"={{ $('PubNio settings').first().json.baseUrl }}/api/v1/posts/{{ $('Plan action').item.json.postId }}","authentication":"genericCredentialType","genericAuthType":"httpHeaderAuth","sendQuery":true,"queryParameters":{"parameters":[{"name":"workspaceId","value":"={{ $('PubNio settings').first().json.workspaceId }}"}]},"sendHeaders":true,"headerParameters":{"parameters":[{"name":"PubNio-Version","value":"2026-12-02"}]},"options":{"response":{"response":{"fullResponse":true,"neverError":true,"responseFormat":"json"}},"timeout":30000}},"id":"259e1c15-a5da-45ca-a8df-c53f43c21e04","name":"Read post status","type":"n8n-nodes-base.httpRequest","typeVersion":4.2,"position":[1780,500],"onError":"continueErrorOutput"},{"parameters":{"mode":"runOnceForEachItem","jsCode":"// Nothing is sent for these rows. A key that went out more than 23 hours ago\n// (or whose send time is unreadable) without a post ID may already have\n// posted, and PubNio replays a key for 24 hours only. A row the workflow\n// cannot send as written is rejected until a person fixes it.\nconst plan = $json;\nconst out = {\n  rowId: plan.rowId,\n  key: plan.key,\n  sentAt: plan.sentAt,\n  postId: plan.postId || '',\n  status: 'needs_review',\n  outcome: plan.outcome || '',\n  error: '',\n  revision: plan.draftRevision || '',\n  media: plan.sentMedia || '',\n  retryFailed: plan.retryFailed,\n};\nif (plan.action === 'invalid') {\n  Object.assign(out, { status: 'rejected', key: '', sentAt: '', error: plan.problem });\n  return { json: out };\n}\nout.error = 'Key ' + plan.key + ' was sent at ' + (plan.sentAt || 'an unknown time') + ' and no post ID came back. Find the post in PubNio and paste its ID into pubnio_post_id, or clear pubnio_key, pubnio_sent_at, and pubnio_status to send it as a new post.';\nreturn { json: out };"},"id":"26b33034-83cf-4bd0-a5b8-e2025ed25940","name":"Record row problem","type":"n8n-nodes-base.code","typeVersion":2,"position":[1780,700]},{"parameters":{},"id":"d6fbdbe6-f70f-4605-ad66-0d862792a5c8","name":"Nothing to do","type":"n8n-nodes-base.noOp","typeVersion":1,"position":[1780,900]},{"parameters":{"respondWith":"json","responseBody":"={{ JSON.stringify({ queued: true, duplicate: false, id: $json.source_id }) }}","options":{"responseCode":202}},"id":"f10593ed-db12-4456-ab88-9677cfb9d553","name":"Answer queued","type":"n8n-nodes-base.respondToWebhook","typeVersion":1.4,"position":[1320,0]},{"parameters":{"content":"## Webhook → LinkedIn\n\nAny system can `POST` `{\"id\", \"text\", \"image_url\"?}` to the **Post request** URL (Header Auth). New IDs are queued and answered `202`; a repeated ID is answered `200` with `duplicate: true` and queues nothing. A person approves rows in the data table; the scheduled part posts each approved row once to one LinkedIn account. PubNio does not post this network's media from a URL, so the workflow imports the URL into your workspace first and posts the imported media; a URL PubNio cannot fetch marks the row rejected.\n\n**Data table `pubnio_requests`** (create it under Overview → Data tables): `source_id`, `text`, `detail` (string), `approved` (boolean), and strings `pubnio_key`, `pubnio_post_id`, `pubnio_status`, `pubnio_outcome`, `pubnio_error`, `pubnio_sent_at`. Approve a row by setting `approved` to true in the table. `detail` holds the optional image URL.\n\n**Setup:** Header Auth credential for the webhook; `workspaceId` and `linkedinAccountId` in **PubNio settings**; Header Auth credential `PubNio API key` on the PubNio nodes.","height":340,"width":700},"id":"ae970fa6-70b5-4114-a988-1578dec4dc4c","name":"Setup","type":"n8n-nodes-base.stickyNote","typeVersion":1,"position":[-40,-600]}],"connections":{"Post request":{"main":[[{"node":"Has id and text?","type":"main","index":0}]]},"Has id and text?":{"main":[[{"node":"Compose post","type":"main","index":0}],[{"node":"Reject request","type":"main","index":0}]]},"Compose post":{"main":[[{"node":"Already queued?","type":"main","index":0},{"node":"Skip items already queued","type":"main","index":0}]]},"Already queued?":{"main":[[{"node":"Answer duplicate","type":"main","index":0}]]},"Skip items already queued":{"main":[[{"node":"Queue for approval","type":"main","index":0}]]},"Every 15 minutes":{"main":[[{"node":"PubNio settings","type":"main","index":0}]]},"PubNio settings":{"main":[[{"node":"Read approved rows","type":"main","index":0}]]},"Read approved rows":{"main":[[{"node":"Normalize row","type":"main","index":0}]]},"Normalize row":{"main":[[{"node":"Approved?","type":"main","index":0}]]},"Approved?":{"main":[[{"node":"Plan action","type":"main","index":0}],[{"node":"Not approved: skip","type":"main","index":0}]]},"Plan action":{"main":[[{"node":"Route by action","type":"main","index":0}]]},"Record PubNio answer":{"main":[[{"node":"Write result to row","type":"main","index":0}]]},"Record missing answer":{"main":[[{"node":"Write result to row","type":"main","index":0}]]},"Route by action":{"main":[[{"node":"Save key before sending","type":"main","index":0}],[{"node":"Read post status","type":"main","index":0}],[{"node":"Record row problem","type":"main","index":0}],[{"node":"Record row problem","type":"main","index":0}],[{"node":"Nothing to do","type":"main","index":0}]]},"Import media":{"main":[[{"node":"Import accepted?","type":"main","index":0}],[{"node":"Record missing answer","type":"main","index":0}]]},"Import accepted?":{"main":[[{"node":"Wait for media","type":"main","index":0}],[{"node":"Record media status","type":"main","index":0}]]},"Wait for media":{"main":[[{"node":"Read media status","type":"main","index":0}]]},"Read media status":{"main":[[{"node":"Media ready?","type":"main","index":0}],[{"node":"Record missing answer","type":"main","index":0}]]},"Media ready?":{"main":[[{"node":"Create post in PubNio","type":"main","index":0}],[{"node":"Record media status","type":"main","index":0}]]},"Record media status":{"main":[[{"node":"Write result to row","type":"main","index":0}]]},"Save key before sending":{"main":[[{"node":"Row has media?","type":"main","index":0}]]},"Row has media?":{"main":[[{"node":"Import media","type":"main","index":0}],[{"node":"Create post in PubNio","type":"main","index":0}]]},"Create post in PubNio":{"main":[[{"node":"Record PubNio answer","type":"main","index":0}],[{"node":"Record missing answer","type":"main","index":0}]]},"Read post status":{"main":[[{"node":"Record PubNio answer","type":"main","index":0}],[{"node":"Record missing answer","type":"main","index":0}]]},"Record row problem":{"main":[[{"node":"Write result to row","type":"main","index":0}]]},"Queue for approval":{"main":[[{"node":"Answer queued","type":"main","index":0}]]}},"settings":{"executionOrder":"v1"},"pinData":{},"meta":{"templateCredsSetupCompleted":false}}