PHP code example of synara / sdk

1. Go to this page and download the library: Download synara/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/ */

    

synara / sdk example snippets


use Synara\Client;
use Synara\Api\Models\Event;
use DateTimeImmutable;
use DateInterval;

$client = new Client(
    apiKey: 'your-api-key-here'
);

$event = Event::make(
    uid: 'unique-event-id',
    title: 'Team Meeting',
    startsAt: new DateTimeImmutable('2024-01-15T10:00:00+00:00')
)->withDuration(new DateInterval('PT1H'));

$createdEvent = $client->events()->create($event);
printf("Event created: %s\n", $createdEvent->getUid());

use Synara\Client;
use Synara\Api\Models\Event;
use DateTimeImmutable;
use DateInterval;

$client = new Client(apiKey: 'your-api-key');

$event = Event::make(
    uid: 'meeting-123',
    title: 'Team Standup',
    startsAt: new DateTimeImmutable('2024-01-15T10:00:00-08:00')
)
    ->withDuration(new DateInterval('PT30M'))
    ->withDescription('Daily team standup meeting')
    ->atLocation('Conference Room A');

$createdEvent = $client->events()->create($event);
printf("Created %s starting at %s\n", $createdEvent->getUid(), $createdEvent->getStartsAt()->format('c'));

use Synara\Api\Models\Attendee;

// Create an attendee
$attendee = Attendee::make(
    email: '[email protected]',
    name: 'Alice Smith'
);

// Optional attendee
$optionalAttendee = Attendee::make('[email protected]', 'Bob Jones')
    ->asOptional();

// Attendee with RSVP status
$acceptedAttendee = Attendee::make('[email protected]', 'Charlie Brown')
    ->accepted();

$declinedAttendee = Attendee::make('[email protected]', 'Dave Wilson')
    ->declined();

// Add attendees to event
$event = Event::make(
    uid: 'meeting-123',
    title: 'Team Meeting',
    startsAt: new DateTimeImmutable('2024-01-15T10:00:00Z')
)
    ->addAttendee($attendee)
    ->addAttendee($optionalAttendee)
    ->addAttendee($acceptedAttendee)
    ->addAttendee($declinedAttendee);

$createdEvent = $client->events()->create($event);

$event = $client->events()->find('meeting-123');

$updated = $event
    ->withDescription('Updated description')
    ->atLocation('New Location')
    ->addAttendee(Attendee::make('[email protected]', 'New Attendee'));

$saved = $client->events()->update($updated->getUid(), $updated);
printf("Updated %s to %s\n", $saved->getUid(), $saved->getLocation());

$event = $client->events()->find('meeting-123');

printf("Title: %s\n", $event->getTitle());
printf("Starts: %s\n", $event->getStartsAt()->format('c'));
printf("Location: %s\n", $event->getLocation() ?? 'n/a');

foreach ($event->getAttendees() as $attendee) {
    printf("Attendee: %s (%s)\n", $attendee->getEmail(), $attendee->getName() ?? 'no name');
}

use Synara\Api\Exceptions\AuthenticationException;
use Synara\Api\Exceptions\ValidationException;
use Synara\Api\Exceptions\NetworkException;
use Synara\Api\Exceptions\ApiException;

try {
    $event = $client->events()->create($event);
} catch (AuthenticationException $e) {
    // 401 or 403 - Invalid API key or insufficient permissions
    echo "Authentication failed: {$e->getMessage()}\n";
} catch (ValidationException $e) {
    // 422 - Validation errors
    echo "Validation failed: {$e->getMessage()}\n";
    $errors = $e->getErrors();
    if ($errors) {
        print_r($errors);
    }
} catch (NetworkException $e) {
    // 500+ - Server errors or network issues
    echo "Network error: {$e->getMessage()}\n";
} catch (ApiException $e) {
    // Other API errors
    echo "API error: {$e->getMessage()}\n";
}

use Psr\Http\Client\ClientInterface;
use GuzzleHttp\Client as GuzzleClient;

$customClient = new GuzzleClient([
    'timeout' => 30,
    // ... other Guzzle options
]);

$client = new Client(
    apiKey: 'your-api-key',
    httpClient: $customClient
    // baseUri defaults to https://synara.events
);

$event = Event::make('uid-123', 'Test', new DateTimeImmutable('2024-01-01T10:00:00Z'));
$jsCalendar = $event->toArray();

$event1 = Event::make('uid-123', 'Test', new DateTimeImmutable('2024-01-01T10:00:00Z'));
$event2 = $event1->withDescription('Description');

// $event1 is unchanged
assert($event1->getDescription() === null);
assert($event2->getDescription() === 'Description');
assert($event1 !== $event2); // Different instances
text
{
    \"@type\": \"jsevent\",
    \"uid\": \"uid-123\",
    \"title\": \"Test\",
    \"start\": \"2024-01-01T10:00:00+00:00\"
}