{
  "name": "Schedule to PostSider's best slot",
  "nodes": [
    {
      "parameters": {},
      "id": "c2d3e4f5-0001-4a5b-9c0d-111111111111",
      "name": "When clicking 'Test workflow'",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        0,
        0
      ]
    },
    {
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "// Edit the values below, then run the workflow.\n// channelId: your connected channel id (app > Settings > Channels).\n// platform: provider identifier used in settings.__type (x, instagram, linkedin, threads, ...).\nconst channelId = 'REPLACE_WITH_CHANNEL_ID';\nconst platform = 'x';\nconst content = 'Scheduled by PostSider at the best time. \u23f0';\n\nreturn [{ json: { channelId, platform, content } }];"
      },
      "id": "c2d3e4f5-0002-4a5b-9c0d-222222222222",
      "name": "1. Post content",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        220,
        0
      ]
    },
    {
      "parameters": {
        "method": "GET",
        "url": "=https://api.postsider.com/public/v1/find-slot/{{ $json.channelId }}"
      },
      "id": "c2d3e4f5-0003-4a5b-9c0d-333333333333",
      "name": "2. Find best slot",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        440,
        0
      ],
      "credentials": {
        "httpHeaderAuth": {
          "id": "1",
          "name": "PostSider API Key"
        }
      }
    },
    {
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "// The API returns a UTC wall-clock date without a timezone, so append 'Z'.\nconst input = $('1. Post content').first().json;\nconst slot = $input.first().json; // { date: '2026-08-16T10:00:00.000' }\n\nreturn [{\n  json: {\n    body: {\n      type: 'schedule',\n      date: slot.date + 'Z',\n      shortLink: false,\n      tags: [],\n      posts: [{\n        integration: { id: input.channelId },\n        value: [{ content: input.content, image: [] }],\n        settings: { __type: input.platform }\n      }]\n    }\n  }\n}];"
      },
      "id": "c2d3e4f5-0004-4a5b-9c0d-444444444444",
      "name": "3. Build schedule payload",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        660,
        0
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.postsider.com/public/v1/posts",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify($json.body) }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Idempotency-Key",
              "value": "=post-{{ $now.toISO() }}"
            }
          ]
        }
      },
      "id": "c2d3e4f5-0005-4a5b-9c0d-555555555555",
      "name": "4. Schedule in PostSider",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        880,
        0
      ],
      "credentials": {
        "httpHeaderAuth": {
          "id": "1",
          "name": "PostSider API Key"
        }
      }
    },
    {
      "parameters": {
        "height": 320,
        "width": 460,
        "content": "SETUP (once):\n\n1. Create an API key in PostSider: app.postsider.com > Settings > API. It starts with ps_.\n2. In n8n create a Header Auth credential: Name = Authorization, Value = your ps_ key.\n3. Select that credential on the '2. Find best slot' and '4. Schedule in PostSider' nodes.\n4. Edit '1. Post content' with your channel id and text.\n\nHow it works: '2. Find best slot' asks PostSider for the next free slot that matches your posting rhythm (the same day-aware logic the dashboard queue uses). '3. Build schedule payload' turns that into a scheduled post and '4.' creates it.\n\nSelf-hosted PostSider? Replace api.postsider.com with your domain (add /api if needed).",
        "color": 3
      },
      "id": "c2d3e4f5-0006-4a5b-9c0d-666666666666",
      "name": "Setup notes",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        0,
        -340
      ]
    },
    {
      "parameters": {
        "content": "SETUP STEP BY STEP\nFollow in order. Do this once per workflow.\n\nSTEP 1 - Create the n8n credential (Header Auth, do this once):\n  \"PostSider API Key\": Name = Authorization, Value = your ps_ key (app.postsider.com > Settings > API > Create key).\n\nSTEP 2 - \"1. Post content\" (Set node):\n  Fill in: text (your post), channelId (a real channel id from app > Settings > Channels).\n\nSTEP 3 - Select the \"PostSider API Key\" credential on:\n  - \"2. Find best slot\"\n  - \"4. Schedule in PostSider\"\n\nSTEP 4 - Run:\n  Click \"Test workflow\" once. PostSider picks the next free slot and schedules the post there.\n\nNOTE\nSelf-hosted PostSider? Replace api.postsider.com with your domain (add /api if your install serves the API under /api).",
        "height": 620,
        "width": 640,
        "color": 3
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        0,
        -700
      ],
      "id": "setup-step-schedule-best-slot",
      "name": "Setup step by step"
    }
  ],
  "connections": {
    "When clicking 'Test workflow'": {
      "main": [
        [
          {
            "node": "1. Post content",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "1. Post content": {
      "main": [
        [
          {
            "node": "2. Find best slot",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "2. Find best slot": {
      "main": [
        [
          {
            "node": "3. Build schedule payload",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "3. Build schedule payload": {
      "main": [
        [
          {
            "node": "4. Schedule in PostSider",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {}
}