TrackMage is your most automated shipment tracking tool ever. Discover the simple way to show your customers where their parcels are, provide support and get more great reviews
- Create a TrackMage account – First of all, you need to sign up for a TrackMage account and retrieve your clientId and clientSecret.
- Minimum requirements – To run the SDK you need to have installed PHP >= 5.6. We highly recommend using v7.2 or higher.
- Install the SDK – Using [Composer] is the recommended way to install the
TrackMage SDK for PHP. The SDK is available on Packagist as the
trackmage/trackmage-sdk-php
packagecomposer require trackmage/trackmage-sdk-php
- See the docs There are API documentation and the generated API client docs
use TrackMage\Client\TrackMageClient;
$clientId = '<client-it>';
$clientSecret = '<client-secret>';
$client = new TrackMageClient($clientId, $clientSecret);
$client->setHost('https://api.stage.trackmage.com'); //optionally
$client->setLogger(new NullLogger()); //optionally
$workspaceId = 100;
$tn = new TrackingNumberPostTrackingNumberSetTrackingNumberMeta();
$tn->setTrackingNumber('TN-1');
$tn->setWorkspace('/workspaces/'.$workspaceId);
$tn = $client->getTrackingNumberApi()->postTrackingNumberCollection($tn);
$items = $client->getTrackingNumberApi()->apiWorkspacesTrackingNumbersGetSubresource($workspaceId);
$workspaces = $client->getWorkspaceApi()->getWorkspaceCollection();
$carriers = self::$client->getCarrierApi()->getCarrierCollection();
Here is the webhook handler example that you need to make accessible on your side.
<?php
$workflow = [
'type' => 'webhook',
'period' => 'immediately',
'title' => 'Webhook for testing',
'workspace' => '/workspaces/<id>',
'enabled' => true,
'concurrency' => '1',
'url' => 'http://acme.example',
'authType' => 'basic',
'username' => 'webhook_user',
'password' => 'password',
'notificationEmails' => [
'[email protected]', '[email protected]',
],
];
$response = $client->getGuzzleClient()->post(
'/workflows', ['json' => $workflow]
);
$data = json_decode($response->getBody()->getContents(), true);
$workflowId = $data['id'];
To run the unit tests:
composer update
./vendor/bin/phpunit
This PHP package is automatically generated by the OpenAPI Generator project:
Download OpenAPI Generator CLI:
wget http://central.maven.org/maven2/org/openapitools/openapi-generator-cli/4.1.0/openapi-generator-cli-4.1.0.jar -O openapi-generator-cli.jar
and run the following:
java -jar openapi-generator-cli.jar generate \
-i https://api.test.trackmage.com/docs.json \
-g php \
-c .openapi-config.json \
--skip-validate-spec \
-o .
where -c .openapi-config.json
is config with php options. See all options:
java -jar openapi-generator-cli.jar config-help -l php
Fix duplicate arguments:
find ./lib/Api/ -name '*.php' -print | php .openapi-generator/dupe_args_fixer.php --fix