PHP code example of stitch-digital / uptick-php-sdk
1. Go to this page and download the library: Download stitch-digital/uptick-php-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/ */
stitch-digital / uptick-php-sdk example snippets
use Uptick\PhpSdk\Uptick\Uptick;
// Create an SDK instance
$uptick = Uptick::make(
baseUrl: 'https://your-company.onuptick.com/api/v2/',
username: 'your_username',
password: 'your_password',
clientId: 'your_client_id',
clientSecret: 'your_client_secret'
);
// List clients (paginated)
$paginator = $uptick->clients()->list();
// Iterate over all clients
foreach ($paginator->items() as $client) {
$clientId = $client->id;
$clientName = $client->attributes->name;
}
// Or collect all items into an array
$allClients = $paginator->collect()->all();
use Saloon\Exceptions\Request\ClientException;
use Saloon\Exceptions\Request\ServerException;
use Uptick\PhpSdk\Uptick\Exceptions\ValidationException;
try {
$paginator = $uptick->clients()->list();
} catch (ValidationException $exception) {
// Get a string describing all errors
$message = $exception->getMessage();
// Get all validation errors as an array
$errors = $exception->getErrors();
// ['field_name' => ['Error message 1', 'Error message 2']]
// Get errors for a specific field
$fieldErrors = $exception->getErrorsForField('field_name');
// Check if a specific field has errors
$hasErrors = $exception->hasErrorsForField('field_name');
// Get all error messages as a flat array
$allMessages = $exception->getAllErrorMessages();
// Access the Saloon Response object for debugging
$response = $exception->getResponse();
} catch (ClientException $exception) {
// Handle 4xx errors (401, 403, 404, etc.)
$message = $exception->getMessage();
$response = $exception->getResponse();
} catch (ServerException $exception) {
// Handle 5xx errors
$message = $exception->getMessage();
$response = $exception->getResponse();
}
$paginator = $uptick->clients()->list();
$allClients = $paginator->collect()->all();
// Now you have an array of all clients
$clientCount = count($allClients);
$firstClient = $allClients[0];
$paginator = $uptick->clients()->list();
// Get the total number of pages
$totalPages = $paginator->getTotalPages();
// Get the first item without iterating
$firstClient = $paginator->items()->current();
$paginator = $uptick->clients()->list();
$paginator->setPerPageLimit(100); // Fetch 100 items per page
foreach ($paginator->items() as $client) {
$clientName = $client->attributes->name;
}
use Uptick\PhpSdk\Uptick\Uptick;
use Uptick\PhpSdk\Uptick\Requests\Clients\ListClientsRequest;
$uptick = Uptick::make(...);
$request = new ListClientsRequest();
$response = $uptick->send($request)->dto();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.