<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
deschutesdesigngroupllc / perscom-php-sdk example snippets
use Perscom\PerscomConnection;
use Perscom\Data\ResourceObject;
use Perscom\Data\SortObject;
use Perscom\Data\FilterObject;
// The following are examples on the user resource, but the same principles
// can be applied to any PERSCOM resource.
$perscom = new PerscomConnection('YOUR_API_KEY');
// Optionally rce
$response = $perscom->users()->get(id: 1);
// Create a resource
$response = $perscom->users()->create(data: [
'name' => 'User 1',
'email' => '[email protected]'
]);
// Update a resource
$response = $perscom->users()->update(id: 1, data: [
'name' => 'User 1 New Name'
]);
// Delete a resource
$response = $perscom->users()->delete(id: 1);
// Search for a resource
$response = $perscom->users()->search(
value: 'foobar',
sort: new SortObject('first_name', 'asc'),
filter: new FilterObject('created_at', '<', '2024-01-01')
);
// Batch create a resource
$response = $perscom->users()->batchCreate([
new ResourceObject(data: [
'name' => 'User 1',
'email' => '[email protected]'
]),
new ResourceObject(data: [
'name' => 'User 2',
'email' => '[email protected]'
])
]);
// Batch update a resource
$response = $perscom->users()->batchUpdate([
new ResourceObject(id: 1, data: [
'name' => 'User 1 New Name'
]),
new ResourceObject(id: 2, data: [
'name' => 'User 2 New Name'
])
]);
// Batch delete a resource
$response = $perscom->users()->batchDelete([
new ResourceObject(id: 1),
new ResourceObject(id: 2)
]);
// Uploading an attachment
$response = $perscom->users()->attachments(userId: 1)->create(data: [
'name' => 'Attachment 1',
'file' => fopen('/../file.pdf', 'r')
]);
// Other examples
$response = $perscom->users()->profilePhoto(userId: 1)->create(filePath: 'image.jpg');
$response = $perscom->users()->assignmentRecords(userId: 1)->delete(id: 1);
// Parse the response into a usable array
$data = $response->json();
use Perscom\PerscomConnection;
use Perscom\Exceptions\AuthenticationException;
try {
$perscom = new PerscomConnection('YOUR_API_KEY');
$response = $perscom->users()->all()->json();
} catch (AuthenticationException $exception) {
Log::error('The provided API key is invalid');
}
use Perscom\PerscomConnection;
use Perscom\Http\Requests\Crud\GetAllRequest;
use Saloon\Http\Response;
use Saloon\Exceptions\Request\RequestException;
// Create a PERSCOM instance
$perscom = new PerscomConnection('YOUR_API_KEY');
// Create a promise
$promise = $perscom->sendAsync(new GetAllRequest('users'));
// Send the request
$promise
->then(function (Response $response) {
// Handle successful response
})
->otherwise(function (RequestException $exception) {
// Handle failed request
});
// Resolve the promise
$promise->wait();
shell
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.