PHP code example of tourware / sdk-php

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

    

tourware / sdk-php example snippets




use tourware\Client;

// Create a client for the flowcore API (staging by default)
$client = Client::create(
    xApiKey: 'YOUR_X_API_KEY'
);

// Production:
$prodClient = Client::create(
    xApiKey: 'YOUR_X_API_KEY',
    staging: false
);

// Example: Fetch a travel record
$travel = $client->travels()->find('60feacb365f5f1002750c2b2');

$client->travel()->find('id');
$client->booking()->list();
$client->customer()->create([...]);

use tourware\Entities\Travel;

$travel = $client->entity(new Travel)->find('id');

$travel = $client->raw('travels')->find('id');

$travels = $client
    ->travel()
    ->query()
    ->filter('title')->contains('Kenya')
    ->filter('price.adult')->gte(1500)
    ->sort('updatedAt')->desc()
    ->offset(0)
    ->limit(20)
    ->get();

$title = $travels->get('records.0.title');
$firstName = $travels->get('records.0.responsibleUser.firstname');

$client->travel()->create([
    'title' => 'New Travel Package',
]);

$client->travel()->find('id');

$client->travel()->update('id', [
    'title' => 'Updated Title',
]);

$client->travel()->delete('id');

$client->travel()->list(offset: 0, limit: 50);

$response = $client
    ->custom("/relations/getRelations/travels/bba0b42e4699", method: 'GET')
    ->call();

try {
    $travel = $client->travel()->find('id');
} catch (\tourware\Exceptions\ApiException $e) {
    echo "API Error: " . $e->getMessage();
} catch (\Exception $e) {
    echo "General Error: " . $e->getMessage();
}
bash
composer