{"name":"Google Sheets to every network with PubNio (approved rows, per-destination outcomes, retry)","nodes":[{"parameters":{"rule":{"interval":[{"field":"minutes","minutesInterval":15}]}},"id":"bb537d7b-3617-4595-a6f2-be9d64c42d3c","name":"Every 15 minutes","type":"n8n-nodes-base.scheduleTrigger","typeVersion":1.2,"position":[0,300]},{"parameters":{"assignments":{"assignments":[{"id":"4b09b1b3-23cc-414b-a23e-31084525d35a","name":"baseUrl","value":"https://pubnio.com","type":"string"},{"id":"27697a9b-0576-4c56-ad87-a59a4ce577c5","name":"workspaceId","value":"","type":"string"}]},"options":{}},"id":"8166ae24-2e63-4665-aeed-752d116f27c1","name":"PubNio settings","type":"n8n-nodes-base.set","typeVersion":3.4,"position":[220,300]},{"parameters":{"documentId":{"__rl":true,"value":"","mode":"list"},"sheetName":{"__rl":true,"value":"","mode":"list"},"options":{}},"id":"a3f7acc4-a451-4a3d-a8b1-baaf0c26c776","name":"Read rows","type":"n8n-nodes-base.googleSheets","typeVersion":4.7,"position":[440,300]},{"parameters":{"mode":"runOnceForEachItem","jsCode":"// One row fans out to every network listed in `networks`; PubNio picks the one ready account per network.\nconst s = $('PubNio settings').first().json;\nconst text = (value) => String(value ?? '').trim();\nconst row = {\n  rowId: text($json.id),\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  approved: $json.approved === true || text($json.approved).toUpperCase() === 'TRUE',\n  mediaUrl: text($json.image_url),\n  retryFailed: $json.retry_failed === true || text($json.retry_failed).toUpperCase() === 'TRUE',\n};\nconst platforms = text($json.networks).toLowerCase().split(/[\\s,]+/).filter(Boolean);\nconst body = { text: text($json.text), platforms };\nreturn { json: { ...row, body } };"},"id":"c5bdf305-f867-42a2-a986-65e6787476a1","name":"Normalize row","type":"n8n-nodes-base.code","typeVersion":2,"position":[660,300]},{"parameters":{"conditions":{"options":{"caseSensitive":true,"leftValue":"","typeValidation":"loose","version":2},"conditions":[{"id":"99cfae37-994e-4d42-a163-5a12a682d23a","leftValue":"={{ $json.approved }}","rightValue":"","operator":{"type":"boolean","operation":"true","singleValue":true}},{"id":"dc6ba036-fbd1-4a1a-a7ab-ec0a59264af0","leftValue":"={{ $json.rowId }}","rightValue":"","operator":{"type":"string","operation":"notEmpty","singleValue":true}}],"combinator":"and"},"looseTypeValidation":true,"options":{}},"id":"0896a8eb-f25e-41d9-a410-248b40afa48e","name":"Approved?","type":"n8n-nodes-base.if","typeVersion":2.2,"position":[880,300]},{"parameters":{},"id":"045a7968-bbce-4556-ab4a-890574111f46","name":"Not approved: skip","type":"n8n-nodes-base.noOp","typeVersion":1,"position":[1100,600]},{"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';\nif (row.postId && row.retryFailed) action = 'retry';\nreturn { json: { ...row, key, sentAt, mediaKey, fresh, action } };"},"id":"d6a73c52-c62b-41a7-ad57-dc265c346cf7","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":"aa61ae41-9ea0-4a12-a8ef-ac2dfd74d6bd","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":"b072799e-8141-4b8a-a68f-c98b06768937","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":"5a05859e-1fe0-4eee-ada8-a83e3cce2b9e","leftValue":"={{ $json.action }}","rightValue":"retry","operator":{"type":"string","operation":"equals"}}],"combinator":"and"},"renameOutput":true,"outputKey":"retry"},{"conditions":{"options":{"caseSensitive":true,"leftValue":"","typeValidation":"strict","version":2},"conditions":[{"id":"cf57c099-ac29-448f-a124-7494052fb3c3","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":"fa6c0749-b4f0-47eb-a9e9-deb6a620264a","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":"b59b02da-1b3f-4bfa-a0ef-21a0c321f53b","leftValue":"={{ $json.action }}","rightValue":"done","operator":{"type":"string","operation":"equals"}}],"combinator":"and"},"renameOutput":true,"outputKey":"done"}]},"options":{}},"id":"c2a1d429-e7cd-460a-a580-6195b5cf8e06","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":"48275598-6907-4a2c-af0c-94ec1db34f18","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":"4f344e55-8f73-493c-a2f6-eae5f0ce7e65","name":"Record missing answer","type":"n8n-nodes-base.code","typeVersion":2,"position":[3300,400]},{"parameters":{"operation":"update","documentId":{"__rl":true,"value":"","mode":"list"},"sheetName":{"__rl":true,"value":"","mode":"list"},"columns":{"mappingMode":"defineBelow","value":{"id":"={{ $json.rowId }}","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 }}","retry_failed":"={{ $json.retryFailed === true }}"},"matchingColumns":["id"]},"options":{}},"id":"dbd87eba-d7c5-42c7-aa62-46abee74ddac","name":"Write result to row","type":"n8n-nodes-base.googleSheets","typeVersion":4.7,"position":[3520,300]},{"parameters":{"operation":"update","documentId":{"__rl":true,"value":"","mode":"list"},"sheetName":{"__rl":true,"value":"","mode":"list"},"columns":{"mappingMode":"defineBelow","value":{"id":"={{ $('Plan action').item.json.rowId }}","pubnio_key":"={{ $('Plan action').item.json.key }}","pubnio_status":"sending","pubnio_sent_at":"={{ $('Plan action').item.json.sentAt }}","pubnio_error":""},"matchingColumns":["id"]},"options":{}},"id":"c82cf28c-8703-49a3-ad3b-8d7dea179f2b","name":"Save key before sending","type":"n8n-nodes-base.googleSheets","typeVersion":4.7,"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":"27541ffd-d251-46d6-a3dd-83785ba6ea40","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":"533032a6-a753-4fc5-af3f-75bea4635741","leftValue":"={{ $('Plan action').item.json.mediaUrl }}","rightValue":"","operator":{"type":"string","operation":"notEmpty","singleValue":true}}],"combinator":"and"},"looseTypeValidation":true,"options":{}},"id":"867054e9-2579-47cc-a50a-51a35ef91f23","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":"3fc6e11b-6dde-4f8d-ae1f-abbf1ac0b98f","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":"e82bc2a0-c6df-4e80-a09f-4169e18dd359","leftValue":"={{ $json.statusCode >= 200 && $json.statusCode < 300 }}","rightValue":"","operator":{"type":"boolean","operation":"true","singleValue":true}}],"combinator":"and"},"looseTypeValidation":true,"options":{}},"id":"73424062-2838-42cc-a283-216df9a2d655","name":"Import accepted?","type":"n8n-nodes-base.if","typeVersion":2.2,"position":[2220,100]},{"parameters":{"amount":10,"unit":"seconds"},"id":"723df820-5a8c-4fc3-aef4-f65f7a225ca2","name":"Wait for media","type":"n8n-nodes-base.wait","typeVersion":1.1,"position":[2440,100],"webhookId":"8904d4e8-1e5d-444f-adc7-60489364ea4d"},{"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":"7e3e09fe-893b-4a86-abd7-7c369fef9ce0","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":"bcd5d97c-40b9-4d62-ac1c-5dfcaf7f68d7","leftValue":"={{ $json.statusCode === 200 && $json.body.status === 'ready' }}","rightValue":"","operator":{"type":"boolean","operation":"true","singleValue":true}}],"combinator":"and"},"looseTypeValidation":true,"options":{}},"id":"e4bc4879-716a-4ee9-a20d-ccc4559fb8a0","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":"c38f1578-4829-4b40-a45b-cec5d779dfc6","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":"06e9336f-05b4-463c-a6c9-a17dfbffac81","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":"eb62e322-85a8-4f69-ac5b-da10b5e72a48","name":"Record row problem","type":"n8n-nodes-base.code","typeVersion":2,"position":[1780,700]},{"parameters":{},"id":"616bdfdc-66d3-4a93-ad91-d1dba1527856","name":"Nothing to do","type":"n8n-nodes-base.noOp","typeVersion":1,"position":[1780,900]},{"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":"08ce822b-ba04-4cdd-aae6-ad9f3f93a7b2","name":"Read post before retry","type":"n8n-nodes-base.httpRequest","typeVersion":4.2,"position":[1780,1100],"onError":"continueErrorOutput"},{"parameters":{"jsCode":"// One item per delivery PubNio says can be retried (canRetry). A delivery\n// that may already be live is never retried: PubNio reports it as unresolved.\nreturn $input.all().flatMap((item, index) => {\n  const plan = $('Plan action').itemMatching(index).json;\n  const body = item.json.body || {};\n  const row = { rowId: plan.rowId, key: plan.key, sentAt: plan.sentAt, postId: plan.postId };\n  const retryable = (body.deliveries || []).filter((d) => d.canRetry);\n  if (!retryable.length) return [{ json: { ...row, status: body.status || plan.status, retry: false }, pairedItem: index }];\n  return retryable.map((d) => ({ json: { ...row, targetId: d.targetId, attemptId: d.attemptId, label: d.provider + ' ' + d.placement, retry: true }, pairedItem: index }));\n});"},"id":"d21d4298-a800-44c9-aab3-8553a44b3772","name":"Pick retryable deliveries","type":"n8n-nodes-base.code","typeVersion":2,"position":[2000,1100]},{"parameters":{"conditions":{"options":{"caseSensitive":true,"leftValue":"","typeValidation":"loose","version":2},"conditions":[{"id":"c1c37afe-6122-4d66-a654-7a1693e0358a","leftValue":"={{ $json.retry }}","rightValue":"","operator":{"type":"boolean","operation":"true","singleValue":true}}],"combinator":"and"},"looseTypeValidation":true,"options":{}},"id":"8c0713b6-638e-4717-abac-11effb89408f","name":"Anything to retry?","type":"n8n-nodes-base.if","typeVersion":2.2,"position":[2220,1100]},{"parameters":{"method":"POST","url":"={{ $('PubNio settings').first().json.baseUrl }}/api/v1/posts/{{ $json.postId }}/targets/{{ $json.targetId }}/retry","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"}]},"sendBody":true,"specifyBody":"json","jsonBody":"={{ JSON.stringify({ expectedAttemptId: $json.attemptId }) }}","options":{"response":{"response":{"fullResponse":true,"neverError":true,"responseFormat":"json"}},"timeout":30000}},"id":"06358194-64b2-4cd2-a0c8-89395371eaec","name":"Retry delivery","type":"n8n-nodes-base.httpRequest","typeVersion":4.2,"position":[2440,1020],"onError":"continueRegularOutput"},{"parameters":{},"id":"12edb97b-1c8c-4b9f-a2e3-ad35ffcbc692","name":"Collect retry results","type":"n8n-nodes-base.merge","typeVersion":3.2,"position":[2660,1100]},{"parameters":{"jsCode":"// One result per row. Retrying with the same expectedAttemptId twice returns\n// the same replacement attempt, so a rerun cannot queue a second copy.\nconst rows = new Map();\n$input.all().forEach((item, index) => {\n  const sent = item.json.retry === false ? null : item.json;\n  const pick = sent ? $('Pick retryable deliveries').itemMatching(index).json : item.json;\n  const row = rows.get(pick.rowId) || { rowId: pick.rowId, key: pick.key, sentAt: pick.sentAt, postId: pick.postId, status: '', outcome: [], error: [], retryFailed: false };\n  if (!sent) {\n    row.status = pick.status || '';\n    row.outcome.push('Nothing to retry: no failed delivery is marked retryable.');\n  } else if (sent.statusCode === 202) {\n    row.status = 'queued';\n    row.outcome.push(pick.label + ': retry queued as attempt ' + sent.body.attemptId);\n  } else {\n    const body = sent.body || {};\n    row.error.push(pick.label + ': ' + (sent.statusCode || 'no answer') + ' ' + (body.code || body.title || (sent.error && sent.error.message) || ''));\n  }\n  rows.set(pick.rowId, row);\n});\nreturn [...rows.values()].map((row) => ({ json: { ...row, outcome: row.outcome.join('\\n'), error: row.error.join('\\n') } }));"},"id":"a5a76e50-0f0f-4a50-ae46-c9bed0da8980","name":"Summarize retries","type":"n8n-nodes-base.code","typeVersion":2,"position":[2880,1100]},{"parameters":{"content":"## Google Sheets → every connected network\n\nOne approved row posts to each network in `networks` and records one outcome line per destination. Tick `retry_failed` on a row to resend only the destinations PubNio marks retryable. 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**Sheet columns:** `id`, `approved`, `text`, `image_url` (optional), `networks` (e.g. `instagram, linkedin, x`), `retry_failed` (checkbox), then `pubnio_key`, `pubnio_post_id`, `pubnio_status`, `pubnio_outcome`, `pubnio_error`, `pubnio_sent_at`.\n\n**Setup:** `workspaceId` in **PubNio settings**; Header Auth credential `PubNio API key`. Each network needs exactly one connected account in the workspace.","height":380,"width":620},"id":"2fce393f-45df-41a9-acb1-a7ae1051b7fe","name":"Setup","type":"n8n-nodes-base.stickyNote","typeVersion":1,"position":[-40,-80]}],"connections":{"Every 15 minutes":{"main":[[{"node":"PubNio settings","type":"main","index":0}]]},"PubNio settings":{"main":[[{"node":"Read rows","type":"main","index":0}]]},"Read 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":"Read post before retry","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}]]},"Read post before retry":{"main":[[{"node":"Pick retryable deliveries","type":"main","index":0}],[{"node":"Record missing answer","type":"main","index":0}]]},"Pick retryable deliveries":{"main":[[{"node":"Anything to retry?","type":"main","index":0}]]},"Anything to retry?":{"main":[[{"node":"Retry delivery","type":"main","index":0}],[{"node":"Collect retry results","type":"main","index":1}]]},"Retry delivery":{"main":[[{"node":"Collect retry results","type":"main","index":0}]]},"Collect retry results":{"main":[[{"node":"Summarize retries","type":"main","index":0}]]},"Summarize retries":{"main":[[{"node":"Write result to row","type":"main","index":0}]]}},"settings":{"executionOrder":"v1"},"pinData":{},"meta":{"templateCredsSetupCompleted":false}}