{"name":"Airtable to a Facebook Page queue with PubNio (approved records only)","nodes":[{"parameters":{"rule":{"interval":[{"field":"minutes","minutesInterval":15}]}},"id":"e4cb5972-4e69-42f9-aa03-10dd35a0a8c7","name":"Every 15 minutes","type":"n8n-nodes-base.scheduleTrigger","typeVersion":1.2,"position":[0,300]},{"parameters":{"assignments":{"assignments":[{"id":"a80d50b8-70dc-49d7-ad84-547318002059","name":"baseUrl","value":"https://pubnio.com","type":"string"},{"id":"ed19f860-f4db-4e22-a338-0dc2ec4c202f","name":"workspaceId","value":"","type":"string"},{"id":"a7be7a2a-2d69-44d2-aeb8-3c032b0029a5","name":"facebookAccountId","value":"","type":"string"},{"id":"a39d90a8-2ca0-4cf7-a2d7-891b27822635","name":"facebookQueueId","value":"","type":"string"}]},"options":{}},"id":"45d484dd-3d77-430d-a8a7-600641bd426d","name":"PubNio settings","type":"n8n-nodes-base.set","typeVersion":3.4,"position":[220,300]},{"parameters":{"operation":"search","base":{"__rl":true,"value":"","mode":"list"},"table":{"__rl":true,"value":"","mode":"list"},"filterByFormula":"{Status} = 'Approved'","options":{}},"id":"602f6195-31fb-4c14-a8a4-fb189fbdddf4","name":"Read rows","type":"n8n-nodes-base.airtable","typeVersion":2.2,"position":[440,300]},{"parameters":{"mode":"runOnceForEachItem","jsCode":"// One Airtable record takes the next free slot in a PubNio schedule queue for one Facebook Page.\nconst s = $('PubNio settings').first().json;\nconst text = (value) => String(value ?? '').trim();\nconst f = $json.fields || {};\nconst row = {\n  rowId: $json.id,\n  approved: f.Status === 'Approved',\n  key: text(f.pubnio_key),\n  postId: text(f.pubnio_post_id),\n  status: text(f.pubnio_status),\n  sentAt: text(f.pubnio_sent_at),\n  outcome: text(f.pubnio_outcome),\n  problem: text(f.Link) && text(f['Image URL']) ? 'Fill Link or Image URL, not both: a Facebook feed post carries a link preview or uploaded media. Clear one, then clear pubnio_status.' : '',\n};\nconst target = { accountId: s.facebookAccountId, queueId: s.facebookQueueId };\nif (text(f.Link)) target.settings = { link: text(f.Link) };\nconst body = { text: text(f.Message), targets: [target] };\nif (text(f['Image URL'])) body.media = [{ url: text(f['Image URL']) }];\nreturn { json: { ...row, body } };"},"id":"691567ee-29cd-4ff1-a09c-a5d80d73b75a","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":"7cb04dcc-1006-40fa-a057-e333178f605e","leftValue":"={{ $json.approved }}","rightValue":"","operator":{"type":"boolean","operation":"true","singleValue":true}}],"combinator":"and"},"looseTypeValidation":true,"options":{}},"id":"bdaf4d7e-31d1-4864-a16b-49c9bf7bdf0a","name":"Approved?","type":"n8n-nodes-base.if","typeVersion":2.2,"position":[880,300]},{"parameters":{},"id":"7ec895a9-8fa4-445e-aa15-437577268b21","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';\nreturn { json: { ...row, key, sentAt, mediaKey, fresh, action } };"},"id":"1689f7da-0819-44b0-abe9-34425f75696e","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":"58e8ea00-7077-4d77-afbc-38ec31d13926","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":"5c89622a-466d-402d-ac76-1d1191517d44","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":"e7ddc9b7-35bf-4bdd-a578-d0d79b81cad3","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":"f299842e-2823-4d90-aaff-7091926dc5b4","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":"5d8794b1-4c41-483b-a023-7b6554bf6bad","leftValue":"={{ $json.action }}","rightValue":"done","operator":{"type":"string","operation":"equals"}}],"combinator":"and"},"renameOutput":true,"outputKey":"done"}]},"options":{}},"id":"7fe6229a-6495-4d3e-af52-b4254cb10d08","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":"cb8f31c8-6f7c-43bd-a8d2-1a69521e0a6a","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":"1af39cf7-5918-4e68-a26b-56ec35a53432","name":"Record missing answer","type":"n8n-nodes-base.code","typeVersion":2,"position":[3300,400]},{"parameters":{"operation":"update","base":{"__rl":true,"value":"","mode":"list"},"table":{"__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 }}"},"matchingColumns":["id"]},"options":{}},"id":"4bd49961-3c1d-442c-ab7f-4cebf509fd63","name":"Write result to row","type":"n8n-nodes-base.airtable","typeVersion":2.2,"position":[3520,300]},{"parameters":{"operation":"update","base":{"__rl":true,"value":"","mode":"list"},"table":{"__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":"a7dea844-cfe7-49ad-aeeb-da50d434bf01","name":"Save key before sending","type":"n8n-nodes-base.airtable","typeVersion":2.2,"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($('Plan action').item.json.body) }}","options":{"response":{"response":{"fullResponse":true,"neverError":true,"responseFormat":"json"}},"timeout":30000}},"id":"298b1dca-c644-4eb5-a697-dfbcb0c512fc","name":"Create post in PubNio","type":"n8n-nodes-base.httpRequest","typeVersion":4.2,"position":[2880,100],"onError":"continueErrorOutput"},{"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":"0ee29976-8c20-4202-a944-ed08ca87cd36","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":"41fda2e3-9f6e-48de-ad6c-fd30f32be2a1","name":"Record row problem","type":"n8n-nodes-base.code","typeVersion":2,"position":[1780,700]},{"parameters":{},"id":"77215925-1c28-4a1b-a3f1-fe3ef68bcd2d","name":"Nothing to do","type":"n8n-nodes-base.noOp","typeVersion":1,"position":[1780,900]},{"parameters":{"content":"## Airtable → Facebook Page queue\n\nEach approved record takes the next free slot in a PubNio schedule queue; the slot's local date and time land in `pubnio_outcome`.\n\n**Fields:** `Status`, `Message`, `Link` (optional HTTPS link preview) or `Image URL` (optional image), never both, plus text fields `pubnio_key`, `pubnio_post_id`, `pubnio_status`, `pubnio_outcome`, `pubnio_error`, `pubnio_sent_at`.\n\n**Setup:** `workspaceId`, `facebookAccountId`, and `facebookQueueId` (a schedule queue you create in PubNio) in **PubNio settings**; Header Auth credential `PubNio API key`.","height":340,"width":620},"id":"f535592e-46c2-45b9-a7db-826dc0855efa","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":"Record row problem","type":"main","index":0}],[{"node":"Record row problem","type":"main","index":0}],[{"node":"Nothing to do","type":"main","index":0}]]},"Save key before sending":{"main":[[{"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}]]}},"settings":{"executionOrder":"v1"},"pinData":{},"meta":{"templateCredsSetupCompleted":false}}