PHP code example of dhl / sdk-api-ecom-us

1. Go to this page and download the library: Download dhl/sdk-api-ecom-us 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/ */

    

dhl / sdk-api-ecom-us example snippets


$logger = new \Psr\Log\NullLogger();
$authStorage = new \Dhl\Sdk\EcomUs\Model\Auth\AuthenticationStorage(
    $username = 'u5er',
    $password = 'p4ss'
);

$serviceFactory = new \Dhl\Sdk\EcomUs\Service\ServiceFactory();
$service = $serviceFactory->createLabelService($authStorage, $logger, $sandbox = true);

$requestBuilder = new \Dhl\Sdk\EcomUs\Model\Label\LabelRequestBuilder();
$requestBuilder->setShipperAccount(
    $pickupAccountNumber = '5323000',
    $distributionCenter = 'USMCO1'
);
$requestBuilder->setShipperAddress(
    $country = 'US',
    $postalCode = '33324',
    $city = 'Plantation',
    $streetLines = ['1210 South Pine Island Road'],
    $company = 'DHL eCommerce'
);
$requestBuilder->setReturnAddress(
    $country = 'US',
    $postalCode = '33324',
    $city = 'Plantation',
    $streetLines = ['1210 South Pine Island Road'],
    $company = 'DHL eCommerce'
);
$requestBuilder->setRecipientAddress(
    $country = 'US',
    $postalCode = '90232',
    $city = 'Culver City',
    $streetLines = ['10441 Jefferson Blvd.', 'Suite 200'],
    $name = 'Jane Doe',
    $company = 'Foo Factory',
    $email = '[email protected]',
    $phone = '800 123456',
    $state = 'CA'
);

$requestBuilder->setPackageId($uniquePackageId = 'TEST-9876543210');
$requestBuilder->setPackageDetails(
    $shippingProduct = 'PLT',
    $currency = 'USD',
    $packageWeight = 1.2,
    $weightUnit = 'LB'
);

$labelRequest = $requestBuilder->create();
$label = $service->createLabel($labelRequest);

$logger = new \Psr\Log\NullLogger();
$authStorage = new \Dhl\Sdk\EcomUs\Model\Auth\AuthenticationStorage(
    $username = 'u5er',
    $password = 'p4ss'
);

$serviceFactory = new \Dhl\Sdk\EcomUs\Service\ServiceFactory();
$service = $serviceFactory->createManifestationService($authStorage, $logger, $sandbox = true);

// create manifest for all available packages
$manifest = $service->createManifest($pickupAccountNumber = '5323000');

// OR create manifest for certain packages, identified by number
$manifest = $service->createPackageManifest(
    $pickupAccountNumber = '5323000',
    $packageIds = [
        "TEST-0123456789",
        "TEST-9876543210"
    ]
);

// documentation may not be instantly available, try again later
if ($manifest->getStatus() !== \Dhl\Sdk\EcomUs\Api\Data\ManifestInterface::STATUS_COMPLETED) {
    $manifest = $service->getManifest(
        $pickupAccountNumber = '5323000',
        $requestId = $manifest->getRequestId()
    );
}