PHP code example of soerbv / shipsgo

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

    

soerbv / shipsgo example snippets


use SoerBV\Shipsgo\Shipsgo;

$shipsgo = new Shipsgo('YOUR_SHIPSGO_TOKEN');

$shipment = $shipsgo->ocean->shipments->create(
    containerNumber: 'MSCU1234567',
    carrier: 'MSCU',
    reference: 'PO-12345',
);

echo $shipment->status->value;   // e.g. "SAILING"
echo $shipment->carrier?->name;  // "MSC"

use SoerBV\Shipsgo\{Config, Shipsgo};

$shipsgo = new Shipsgo('TOKEN');

// Or for full control:
$shipsgo = new Shipsgo(new Config(
    token: 'TOKEN',
    baseUri: 'https://api.shipsgo.com/v2',
    timeoutSeconds: 30,
));

// Create
$shipment = $shipsgo->ocean->shipments->create(
    containerNumber: 'MSCU1234567',  // or bookingNumber
    carrier: 'MSCU',
    reference: 'PO-12345',
    followers: ['[email protected]'],
    tags: ['IMPORT'],
);

// Get one by id
$shipment = $shipsgo->ocean->shipments->get(123);
foreach ($shipment->containers as $container) {
    echo $container->number . ' — ' . $container->status->value . PHP_EOL;
}

// Or look up by container / booking number (returns ?Shipment, 2 API calls)
$shipment = $shipsgo->ocean->shipments->findByContainerNumber('MSCU1234567');
$shipment = $shipsgo->ocean->shipments->findByBookingNumber('MEDUQY000000');

// List with pagination + filters
$page = $shipsgo->ocean->shipments->list(
    filters: ['status' => 'eq:SAILING'],
    orderBy: '-created_at',
    skip: 0,
    take: 50,
);
foreach ($page as $summary) {
    echo $summary->reference . PHP_EOL;
}
if ($page->meta->more) {
    // fetch next page with skip: 50
}

// Update reference
$shipsgo->ocean->shipments->update(123, 'PO-12345-updated');

// Tags / followers
$tag = $shipsgo->ocean->shipments->addTag(123, 'URGENT');
$shipsgo->ocean->shipments->removeTag(123, $tag->id);
$shipsgo->ocean->shipments->addFollower(123, '[email protected]');

// Route as GeoJSON
$geo = $shipsgo->ocean->shipments->geojson(123);

// Delete
$shipsgo->ocean->shipments->delete(123);

// Carriers
$carriers = $shipsgo->ocean->carriers->list();

$shipment = $shipsgo->air->shipments->create(
    awbNumber: '333-88888888',
    reference: 'AWB-REF',
);

$shipment = $shipsgo->air->shipments->get(456);
echo $shipment->airline?->name;

// Or look up by AWB number (returns ?Shipment, 2 API calls)
$shipment = $shipsgo->air->shipments->findByAwbNumber('333-88888888');

$page = $shipsgo->air->shipments->list(take: 50);
$airlines = $shipsgo->air->airlines->list();

$shipsgo->air->shipments->get(456);
echo $shipsgo->lastCredits()?->remaining;

$this->app->singleton(Shipsgo::class, fn () => new Shipsgo(config('services.shipsgo.token')));