{
  "name": "Post approved HollyHR leave to Slack",
  "nodes": [
    {
      "id": "0c2e8983-8cd2-417a-85ad-f6d50adf06c2",
      "name": "Sticky Note Overview",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -560,
        -16
      ],
      "parameters": {
        "content": "## Post approved HollyHR leave to Slack\n### How it works\nEvery 15 minutes this workflow asks HollyHR for time off approved since it last looked, finds each person's name and posts one Slack message per approval, such as 'Priya Shah is away Mon 1 Dec – Wed 3 Dec.' It shows names and dates only, never the type of leave or any reason.\n### Setup\n1. In HollyHR, open Settings > Developers and create an API key. Under Access choose Custom and tick Read for People and Time off (people:read, time_off:read).\n2. In n8n, create a Bearer Auth credential, paste the key and select it in both HollyHR HTTP Request nodes.\n3. In 'Your settings', enter your HollyHR address: the web address you sign in on, with no slash at the end.\n4. In 'Post to Slack', connect Slack and choose a channel.\n5. To preview the messages first, select 'Post to Slack' and press D to turn it off. Choose 'Execute workflow': a test looks back 24 hours. Turn the node back on, connect Slack and publish.\n### Customization\nChange how often it runs in 'Every 15 minutes'. Edit the wording in 'Write the messages'.",
        "height": 540,
        "width": 460,
        "color": 1
      }
    },
    {
      "id": "68edb6d4-c8d4-4b26-899b-8c24b973a14f",
      "name": "When clicking 'Execute workflow'",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        0,
        304
      ],
      "parameters": {}
    },
    {
      "id": "a0c8f310-a58f-4e07-81f2-697e1b981e5b",
      "name": "Every 15 minutes",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        0,
        112
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "minutes",
              "minutesInterval": 15
            }
          ]
        }
      }
    },
    {
      "id": "31f30df1-151f-446b-8f01-6c15862f5457",
      "name": "Your settings",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        240,
        208
      ],
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "2dc806b9-df42-4d66-82e5-8abf64520574",
              "name": "hollyhrUrl",
              "value": "https://your-workspace.hollyhr.com",
              "type": "string"
            }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "d4de0775-3cb3-4b9c-8123-bf4af899a5f5",
      "name": "Work out what is new",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        480,
        208
      ],
      "parameters": {
        "jsCode": "// Look back to the last check, with five minutes of overlap.\n// A manual test looks back 24 hours. A published run starts from now.\nconst store = $getWorkflowStaticData('global');\nconst now = new Date();\nconst since = store.lastCheckedAt\n  ? new Date(new Date(store.lastCheckedAt).getTime() - 5 * 60 * 1000)\n  : new Date(now.getTime() - ($execution.mode === 'test' ? 24 * 60 : 15) * 60 * 1000);\nstore.lastCheckedAt = now.toISOString();\nreturn [{ json: { since: since.toISOString() } }];"
      }
    },
    {
      "id": "c05a2a40-f09e-4112-8055-3be887e6feb9",
      "name": "Get approved time off",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        720,
        208
      ],
      "parameters": {
        "url": "={{ $('Your settings').first().json.hollyhrUrl.replace(/\\/+$/, '') }}/api/v1/time-off",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBearerAuth",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "status",
              "value": "approved"
            },
            {
              "name": "updated_since",
              "value": "={{ $json.since }}"
            },
            {
              "name": "sort",
              "value": "updated_at_desc"
            },
            {
              "name": "limit",
              "value": "100"
            }
          ]
        },
        "options": {
          "pagination": {
            "pagination": {
              "paginationMode": "updateAParameterInEachRequest",
              "parameters": {
                "parameters": [
                  {
                    "type": "qs",
                    "name": "cursor",
                    "value": "={{ $response.body.pagination.next_cursor }}"
                  }
                ]
              },
              "paginationCompleteWhen": "other",
              "completeExpression": "={{ !$response.body.pagination.has_more }}",
              "limitPagesFetched": true,
              "maxRequests": 20
            }
          }
        }
      },
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 5000
    },
    {
      "id": "e19f0a5d-7018-4d61-8694-cabcd580d6bf",
      "name": "Keep new approvals",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        960,
        208
      ],
      "parameters": {
        "jsCode": "// One item holding every approval not posted before.\nconst store = $getWorkflowStaticData('global');\nconst posted = store.postedLeave ?? [];\nconst approvals = [];\nfor (const page of $input.all()) {\n  for (const leave of page.json.data ?? []) {\n    if (leave.status_code !== 'approved') continue;\n    const key = leave.id + ':' + leave.start_date + ':' + leave.end_date;\n    if (posted.includes(key)) continue;\n    posted.push(key);\n    approvals.push(leave);\n  }\n}\nstore.postedLeave = posted.slice(-500);\nreturn approvals.length ? [{ json: { approvals } }] : [];"
      }
    },
    {
      "id": "7688b143-38be-4115-8385-380b297b2a8e",
      "name": "Get people",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1200,
        208
      ],
      "parameters": {
        "url": "={{ $('Your settings').first().json.hollyhrUrl.replace(/\\/+$/, '') }}/api/v1/people",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBearerAuth",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "limit",
              "value": "100"
            }
          ]
        },
        "options": {
          "pagination": {
            "pagination": {
              "paginationMode": "updateAParameterInEachRequest",
              "parameters": {
                "parameters": [
                  {
                    "type": "qs",
                    "name": "cursor",
                    "value": "={{ $response.body.pagination.next_cursor }}"
                  }
                ]
              },
              "paginationCompleteWhen": "other",
              "completeExpression": "={{ !$response.body.pagination.has_more }}",
              "limitPagesFetched": true,
              "maxRequests": 20
            }
          }
        }
      },
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 5000,
      "executeOnce": true
    },
    {
      "id": "6ad951db-7e6b-4b7f-8737-b52a2ccb904d",
      "name": "Write the messages",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1440,
        208
      ],
      "parameters": {
        "jsCode": "// One Slack message per approval: names and dates only.\nconst names = new Map();\nfor (const page of $input.all()) {\n  for (const person of page.json.data ?? []) names.set(person.id, person.display_name);\n}\nconst day = (iso) => DateTime.fromISO(iso).toFormat('ccc d LLL');\nreturn $('Keep new approvals').first().json.approvals.map((leave) => {\n  const who = names.get(leave.person_id) ?? 'Someone';\n  const when = leave.start_date === leave.end_date\n    ? day(leave.start_date)\n    : day(leave.start_date) + ' – ' + day(leave.end_date);\n  const part = leave.is_from_half_day || leave.is_to_half_day ? ' (part of a day)' : '';\n  return { json: { text: who + ' is away ' + when + part + '.' } };\n});"
      }
    },
    {
      "id": "dc51a328-1885-42a9-8ef7-9baaabdb5a57",
      "name": "Post to Slack",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.3,
      "position": [
        1680,
        208
      ],
      "parameters": {
        "select": "channel",
        "channelId": {
          "__rl": true,
          "value": "",
          "mode": "list"
        },
        "text": "={{ $json.text }}",
        "otherOptions": {}
      }
    }
  ],
  "pinData": {},
  "connections": {
    "When clicking 'Execute workflow'": {
      "main": [
        [
          {
            "node": "Your settings",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Every 15 minutes": {
      "main": [
        [
          {
            "node": "Your settings",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Your settings": {
      "main": [
        [
          {
            "node": "Work out what is new",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Work out what is new": {
      "main": [
        [
          {
            "node": "Get approved time off",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get approved time off": {
      "main": [
        [
          {
            "node": "Keep new approvals",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Keep new approvals": {
      "main": [
        [
          {
            "node": "Get people",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get people": {
      "main": [
        [
          {
            "node": "Write the messages",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Write the messages": {
      "main": [
        [
          {
            "node": "Post to Slack",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "tags": []
}
