PHP code example of clockster / sdk

1. Go to this page and download the library: Download clockster/sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

clockster / sdk example snippets


use Clockster\Client;

$clockster = new Client(getenv('CLOCKSTER_TOKEN'));

$me = $clockster->me();

$locations = $clockster->locations->upsert([
    'items' => [['external_id' => 'HQ', 'title' => 'Head office']],
]);

$clockster->users->upsert([
    'users' => [[
        'external_id' => 'HR-1',
        'first_name' => 'Aisulu',
        'role' => 'employee',
        'location_id' => $locations['data'][0]['id'],
    ]],
]);

$timesheets = $clockster->timesheets->list(dateFrom: '2026-08-01', dateTo: '2026-08-31');

$clockster->users->list(perPage: 100, status: 'active', 

$clockster->users->upsert(['users' => [[
    'external_id' => 'HR-1',
    'first_name' => 'Aisulu',
    'role' => 'employee',
    'location_id' => 3,
    'position_id' => null,   // clears the stored position
    // department_id is not there at all, so the stored department stays.
]]]);

use Clockster\Write;

$clockster->users->upsert(['users' => [Write::filled([
    'external_id' => $row['external_id'],
    'first_name' => $row['first_name'],
    'role' => UsersRole::EMPLOYEE,
    'location_id' => $locations[$row['location_code']],
    'email' => $row['email'],       // blank in the file, so not sent, so not overwritten
    'position_id' => null,          // null is kept: clearing is a thing you may mean
])]]);

/** @return UsersListResponse */
public function list(?int $perPage = null, /* … */): array

use Clockster\Generated\Enum\UsersInclude;
use Clockster\Generated\Enum\UsersRole;
use Clockster\Generated\Enum\UsersStatus;

$clockster->users->upsert(['users' => [['role' => UsersRole::EMPLOYEE, /* … */]]]);
$clockster->users->list(status: UsersStatus::ACTIVE, 

use Clockster\Exception\InvalidBodyException;

$clockster = new Client(getenv('CLOCKSTER_TOKEN'), validate: true);

try {
    $clockster->users->upsert(['users' => $people]);
} catch (InvalidBodyException $refused) {
    // ['body.users.4.first_nane' => ['is not a field the document names here. It names …']]
    report($refused->errors());
}

Clockster\Validator::check('POST', '/company/v3/users/upsert', ['users' => $people]);

foreach ($clockster->users->listAll(perPage: 100, _EOL;
}

use Clockster\Exception\ApiException;
use Clockster\Exception\RateLimitException;
use Clockster\Exception\ValidationException;

try {
    $clockster->users->upsert(['users' => $people]);
} catch (ValidationException $refused) {
    report($refused->code(), $refused->errors(), $refused->requestId());
} catch (RateLimitException $refused) {
    sleep($refused->retryAfter() ?? 60);
} catch (ApiException $refused) {
    report($refused->status(), $refused->code());
}

$clockster->schedules->create($body, idempotencyKey: $attempt);

$stored = $clockster->files->upload(
    file: (string) file_get_contents('agreement.pdf'),
    filename: 'agreement.pdf',
    name: 'agreement',
);

use Clockster\Exception\WebhookVerificationException;
use Clockster\Webhooks;

try {
    $event = Webhooks::verifyGlobals(getenv('CLOCKSTER_WEBHOOK_SECRET'));
} catch (WebhookVerificationException $refused) {
    http_response_code(400);

    exit;
}

http_response_code(200);

use Clockster\Http\Psr18Transport;

$clockster = new Client($token, transport: new Psr18Transport(
    $guzzle,          // Psr\Http\Client\ClientInterface
    $requestFactory,  // Psr\Http\Message\RequestFactoryInterface
    $streamFactory,   // Psr\Http\Message\StreamFactoryInterface
));

$clockster = new Client(
    token: getenv('CLOCKSTER_TOKEN'),
    baseUrl: 'https://demo.clockster.com',  // a demo stand instead of production
    timeout: 60.0,                          // seconds, applied to each request
    userAgent: 'acme-hr/1.4',               // names your integration in our request log
    validate: true,                         // read a body against the document before sending it
);