{
  "name": "Create a task for each new HollyHR starter",
  "nodes": [
    {
      "id": "213d7f1f-9085-44a7-8e45-84909d291d49",
      "name": "Sticky Note Overview",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -560,
        -16
      ],
      "parameters": {
        "content": "## Create a task for each new HollyHR starter\n### How it works\nEvery morning this workflow asks HollyHR for people added since it last looked, then creates one task for each new starter in your task app. The task carries their name, job title, department, manager, start date and work email, so whoever sets up equipment and accounts has what they need. Remove any of these in 'Keep new starters' if your task app is shared more widely.\n### Setup\n1. In HollyHR, open Settings > Developers and create an API key. Under Access choose Custom and tick Read for People only (people:read).\n2. In n8n, create a Bearer Auth credential, paste the key and select it in 'Get recently changed people'.\n3. In 'Your settings', enter your HollyHR address: the web address you sign in on, with no slash at the end.\n4. In 'Create a task', connect Todoist and choose a project. Use any task app: delete the node and add your own.\n5. To preview the task before connecting your task app, select 'Create a task' and press D to turn it off. Choose 'Execute workflow': the first run looks back 24 hours. Turn the node back on, connect your app and publish.\n### Customization\nChange the time in 'Every morning'. Edit the task title and notes in 'Keep new starters'.",
        "height": 540,
        "width": 460,
        "color": 1
      }
    },
    {
      "id": "5ef8f247-657d-4801-8ab5-e0c63f281e7a",
      "name": "When clicking 'Execute workflow'",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        0,
        304
      ],
      "parameters": {}
    },
    {
      "id": "105fbdd4-eb49-46bd-8058-db1bb087ad40",
      "name": "Every morning",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        0,
        112
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "days",
              "triggerAtHour": 8
            }
          ]
        }
      }
    },
    {
      "id": "9c0aefe8-fade-47b6-8a04-beaf78a74c9f",
      "name": "Your settings",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        240,
        208
      ],
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "521117aa-6ca3-4026-82e8-dd0af5739687",
              "name": "hollyhrUrl",
              "value": "https://your-workspace.hollyhr.com",
              "type": "string"
            }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "2874ff86-3d57-4c19-8d04-a691f3eabd54",
      "name": "Work out what is new",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        480,
        208
      ],
      "parameters": {
        "jsCode": "// Look back to the last successful check, with an hour of overlap.\n// n8n keeps this between published runs. A manual test looks back 24 hours.\nconst store = $getWorkflowStaticData('global');\nconst now = new Date();\nconst since = store.lastCheckedAt\n  ? new Date(new Date(store.lastCheckedAt).getTime() - 60 * 60 * 1000)\n  : new Date(now.getTime() - 24 * 60 * 60 * 1000);\nstore.lastCheckedAt = now.toISOString();\nreturn [{ json: { since: since.toISOString() } }];"
      }
    },
    {
      "id": "a6df99bb-2c53-479b-8cdb-a61cd1a83f94",
      "name": "Get recently changed people",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        720,
        208
      ],
      "parameters": {
        "url": "={{ $('Your settings').first().json.hollyhrUrl.replace(/\\/+$/, '') }}/api/v1/people",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBearerAuth",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "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": "ba2f51ba-7d16-4cad-8f09-082785061eaf",
      "name": "Keep new starters",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        960,
        208
      ],
      "parameters": {
        "jsCode": "// One item per person created since the last check.\nconst since = new Date($('Work out what is new').first().json.since);\nconst store = $getWorkflowStaticData('global');\nconst seen = store.seenStarters ?? [];\nconst out = [];\nfor (const page of $input.all()) {\n  for (const person of page.json.data ?? []) {\n    if (new Date(person.created_at) < since) continue;\n    if (seen.includes(person.id)) continue;\n    seen.push(person.id);\n    const name = person.display_name;\n    const details = [\n      ['Job title', person.job_title],\n      ['Department', person.department?.name],\n      ['Manager', person.manager?.display_name],\n      ['Start date', person.start_date],\n      ['Work email', person.work_email],\n    ].filter(([, value]) => value);\n    out.push({\n      json: {\n        personId: person.id,\n        taskTitle: 'Set up ' + name + (person.start_date ? ' (starts ' + person.start_date + ')' : ''),\n        taskNotes: details.map(([label, value]) => label + ': ' + value).join('\\n'),\n        startDate: person.start_date ?? '',\n      },\n    });\n  }\n}\nstore.seenStarters = seen.slice(-500);\nreturn out;"
      }
    },
    {
      "id": "734aad39-70f8-4c4f-8304-d7dd25982bcb",
      "name": "Create a task",
      "type": "n8n-nodes-base.todoist",
      "typeVersion": 2.2,
      "position": [
        1200,
        208
      ],
      "parameters": {
        "operation": "create",
        "project": {
          "__rl": true,
          "value": "",
          "mode": "list"
        },
        "labels": [],
        "content": "={{ $json.taskTitle }}",
        "options": {
          "description": "={{ $json.taskNotes }}",
          "dueDate": "={{ $json.startDate }}"
        }
      }
    }
  ],
  "pinData": {},
  "connections": {
    "When clicking 'Execute workflow'": {
      "main": [
        [
          {
            "node": "Your settings",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Every morning": {
      "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 recently changed people",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get recently changed people": {
      "main": [
        [
          {
            "node": "Keep new starters",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Keep new starters": {
      "main": [
        [
          {
            "node": "Create a task",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "tags": []
}
