Create Time Off for each users

Hello!

Here at my company we would like to synchronize the time offs of the employees between our vacations request system and clockify.

To do so, I would need to create Time Off for each user in Clockify. This does not seem to be possible currently, as the time off is created for the user corresponding to the API key.

Is there a way to do that I do not see? What would you suggest?

Thanks

Hi @Loic_W,

Thank you for reaching out!

Would you be able to give me some more details about what you are trying to achieve - do you want to pull user’s balance via API?

You can check our updated API documentation for the Time Off, if you haven’t already:

Cheers!

Hi Loic,

I want to jump in here, and offer a possible solution :

  1. Create a Time Off Policy (can be skipped if you have it created already)

  2. Use GET https://api.clockify.me/api/v1/workspaces/{workspaceId}/users to get all the userIDs

  3. Update balance on that policy via PATCH https://pto.api.clockify.me/v1/workspaces/{workspaceId}/balance/policy/{policyId}

And in the body add all the userIDs as an array.

The data structure of the Update balance call is :

{
“note”: “string”,
“userIds”: [
“string”
],
“value”: -10000 (value being the time off you are adding)
}

So you would really need the userIDs rather than their API keys. The API key you can use for this call would be either workspace Owner’s or and Admin’s key.

If the users have different values being added, you can simply run this call in a loop where each time it would take userID and value as variables for each run.

Hello,
thanks for your detailed answers!

So what we are trying to achieve is to have the timeoffs synchronized between our holidays and part-time system and Clockify.
Ideally, these time offs should appear in Clockify with the accurate days the employee is off. This would greatly help the project managers with the schedule part of Clockify. Currently they replicate the timeoffs by hand to be able to properly plan the employee resource on each project.

I hope this is clear now. Your proposed solution to update the policy balance should not help in that case, if I am not mistaken?

Hi Loic,

Apologies for not realizing this was about creating the request.

We offer request creation API call, where you will just have to approve it later on.

You would still require to have all the user IDs :

-POST https://pto.api.clockify.me/v1/workspaces/{workspaceId}/policies/{policyId}/users/{userId}/requests

The structure of the body should be like :
{

  • “note”: “string”,

  • “timeOffPeriod”: {

    • “halfDayPeriod”: “string”,

    • “isHalfDay”: true,

    • “period”: {

      • “days”: 0,

      • “end”: “string”,

      • “start”: “string”}}

}

So in this case, just fill in the body with the details from your vacation request system.

Hope this helps!

Hello @Mishko,

This seems to definitely work out for our case (this endpoint is not shown in the doc I believe).
Getting the userId will not be an issue, I tested that already

Many thanks

1 Like