New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

myparcelnl/sdk

This package is designed to send and receive data from MyParcel by means of an API.
617,443 31

Larablocks Analysis

myparcelnl/sdk works with any PHP project: the latest release (11.4.0, Dec 1, 2026) doesn't depend on Laravel.

Recommendation checks

Solid choice

Solid choice: maintained and up to date, meets 2 of 3 checks; below the bar for Recommended on use.

  • Released in the last 12 months (Dec 1, 2026)
  • 31,028 downloads a month (at least 10,000)
  • 31 GitHub stars (needs 100)

State

Actively maintained
  • Last stable release: Dec 1, 2026.
  • 76 releases in the last 12 months.
  • First released: Aug 22, 2016.
  • Monthly downloads: 31,028, up 136% from six months ago.
  • 16 open issues on GitHub.

Data from Packagist and GitHub, checked by Larablocks on Dec 2, 2026.

Install
composer require myparcelnl/sdk
Latest Version:11.4.0
PHP:^7.4 || ^8.0
License:MIT
Last Updated:Dec 1, 2026
Links: GitHub  ·  Packagist
Maintainer: RichardPerdaan

MyParcel PHP SDK

Latest Stable Version Total Downloads Slack support Coverage Status

Requirements

  • PHP >=7.4
  • Composer
composer require myparcelnl/sdk

Quick start

Most v11 services take an API key in the constructor and wrap the generated API client. MyParcel Connect is the exception, see MyParcel Connect.

use MyParcelNL\Sdk\Collection\ShipmentCollection;
use MyParcelNL\Sdk\Model\Shipment\Shipment;
use MyParcelNL\Sdk\Services\Shipment\ShipmentCreateService;

// Build a shipment
$shipment = (new Shipment())
    ->setRecipient([
        'cc'          => 'NL',
        'street'      => 'Antareslaan',
        'number'      => 31,
        'person'      => 'John Doe',
        'city'        => 'Hoofddorp',
        'postal_code' => '2132 JE',
    ])
    ->setCarrier(1)
    ->withPackageType('PACKAGE');

// Create it
$service = new ShipmentCreateService('your-api-key');
$mapping = $service->create((new ShipmentCollection())->push($shipment));
// $mapping = [shipmentId => referenceIdentifier, ...]

Services

Service Description
ShipmentCreateService Create shipments (concepts or with labels)
ShipmentQueryService Query, find by ID, find by reference
ShipmentDeleteService Delete concept shipments
ShipmentPrintService Print shipments to a printer group
ShipmentLabelsService Get label PDFs, links or direct downloads
ShipmentTrackTraceService Fetch track & trace data
ReturnShipmentService Create related or unrelated return shipments
MultiColloShipmentService Split a shipment into multiple colli
CapabilitiesService Check carrier capabilities for a shipment
CarrierContractDefinitionsService Fetch account-level carrier contract definitions
WebhookService Subscribe, unsubscribe, list webhooks
ApiKeyService Validate API key, get principal info
ConnectService Connect a shop with MyParcel Connect and keep its access token usable

See UPGRADE.md for detailed before/after examples per service.

MyParcel Connect

ConnectService authorises a shop in the merchant's browser instead of taking an API key. It is for integrations you publish and other people install, rather than a single shop you run yourself. EcommerceApiFactory then builds an e-commerce client that signs every call, which is how orders are pushed.

Connect covers one call for now, POST /webhook/orders. Every other service in this SDK still takes an API key.

See PHP SDK v11 on the developer portal for how to use it. dev/connect-poc in this repository is a page that runs the whole flow.

Pushing orders

Every order needs a status: Order::STATUS_OPEN or Order::STATUS_CANCELED. The e-commerce service refuses the whole request with HTTP 400 when one order has no status.

use MyParcelNL\Sdk\Client\Generated\EcommerceApi\Model\Order;
use MyParcelNL\Sdk\Services\Ecommerce\EcommerceApiFactory;

$order = new Order([
    'ordered_at' => new DateTime('now'),
    'source_id'  => 'ORDER-2026-01042',
    'status'     => Order::STATUS_OPEN,
]);

$api     = EcommerceApiFactory::make($connect);
$results = $api->webhookOrdersPost([$order]);

To update an order, push it again with the same source_id. For example, when the merchant cancels the order in the shop:

$order->setStatus(Order::STATUS_CANCELED);

$results = $api->webhookOrdersPost([$order]);

MyParcel accepts the update, but does not act on it yet.

When the connection expires

Show the merchant a notice from about one month before the connection expires, so they reconnect in time. When the refresh token expires, the next refresh fails and the shop has to connect again.

A refresh token lasts about a year. MyParcel sends its lifetime as refreshExpiresIn in the answers of /connect/token and /connect/refresh, and the SDK stores the expiry with the installation. ConnectService::getRefreshTokenExpiresAt() returns it as a UTC DateTimeImmutable, read from storage without a request. It returns null when the shop is not connected, or connected with an SDK version that did not store the expiry yet. The first refresh after an update stores it.

$expiresAt = $connect->getRefreshTokenExpiresAt();

if (null !== $expiresAt && $expiresAt < new DateTimeImmutable('+1 month')) {
    // Show the reconnect notice.
}

ConnectService::getAccessTokenExpiresAt() does the same for the access token, which lasts about an hour. The SDK refreshes the access token itself, so you only need this date for display.

Value mapping

Use ApiMapperService to convert between delivery-options names, v1 IDs and v2 names.

use MyParcelNL\Sdk\Services\Mapping\ApiMapperService;

$mapper = ApiMapperService::forCarrier();

$mapper->idFromLegacyName('dhlforyou'); // 9
$mapper->v2NameFromId(9);              // 'DHL_FOR_YOU'
$mapper->legacyNameFromV2Name('DPD');  // 'dpd'

Use forDeliveryType() or forPackageType() for the other categories. Conversion methods return null if no mapping exists. Use allRows() for one category or allDomains() for all three.

Shipment option names are handled by Services\Mapping\ShipmentOptionMapper. Its v2PropertyFromName() method returns the generated capabilities v2 model property, or null. For example, signature and requiresSignature both map to requires_signature. v1NameFromV2Property() maps the other way, to the v1 option name of the shipments endpoint: requires_signature gives signature. It returns null when the shipments endpoint has no such option.

Unsupported capabilities options

Capabilities requests omit unknown or unsupported option names. Check the request before sending it so your application can report these options or change the request.

use MyParcelNL\Sdk\Model\Capabilities\CapabilitiesRequest;

$request = CapabilitiesRequest::forCountry('NL')
    ->withOptions(['signature' => null, 'tracked' => null]);

$request->getUnsupportedOptions(); // ['tracked']

This check validates option names accepted by the request model. It does not validate option values or determine which options a carrier offers.

Capabilities that the shipments endpoint does not have

The capabilities API can return a value that this SDK version cannot send to the shipments endpoint, such as a new carrier. A shipment with that value fails when the request goes out. SupportedCapabilitiesFilter::filter() removes these carriers, delivery types, package types and options from a capabilities or contract definitions response, and returns copies. The services do not call it, so their responses stay complete.

use MyParcelNL\Sdk\Services\Capabilities\SupportedCapabilitiesFilter;

$definitions = SupportedCapabilitiesFilter::filter($service->getContractDefinitions());

To check one value, use isCarrierSupported(), isDeliveryTypeSupported(), isPackageTypeSupported() or isOptionSupported().

Storing a response

jsonSerialize() throws on an enum value that this SDK version does not know, such as a new carrier in a capabilities response. To store a response, for example in a cache, use CoreApiModels::toArray(). It keeps such a value as it is and gives the fields with their API names.

use MyParcelNL\Sdk\Client\CoreApiModels;

$cached = array_map([CoreApiModels::class, 'toArray'], $service->getContractDefinitions());

A request with an unknown enum value still throws.

Legacy services

The following are still available but will be replaced in a future release:

  • Web services (@internal): AccountWebService, CarrierOptionsWebService, PrinterGroupWebService
  • Order v1 fulfilment: OrderCollection (@internal), OrderNotesCollection (@internal), Order, OrderLine, OrderNote, Product
  • Carrier models, shared models, helpers (@internal) — see UPGRADE.md for the full list

Use CarrierContractDefinitionsService for new account-level carrier contract definition lookups instead of CarrierOptionsWebService.

Testing

# Run all tests
./vendor/bin/phpunit

# Run without live API tests
./vendor/bin/phpunit --exclude-group=live

Tests use two mocking strategies:

  • Legacy web services: Mockery via $this->mockCurl() in TestCase
  • v11 service wrappers: Constructor injection of a mock API instance

Existing tests serve as examples for both patterns.

Support

For questions and support please contact us via support@myparcel.nl or chat with our developers directly on Slack.

Contribute

  1. Check for open issues or open a new issue to start a discussion
  2. Fork the repository and branch off from main
  3. Write tests for the new feature or bug fix
  4. Ensure all tests pass: ./vendor/bin/phpunit
  5. Submit a pull request

Related Packages

postnl/postnl-ecommerce-sdk

Collection of PostNL API's for ecommerce processes.

9,433 0
doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

670,032,257 9,703
laravel/framework

The Laravel Framework.

640,572,096 35,338
laravel/tinker

Powerful REPL for the Laravel framework.

546,909,908 7,440
laravel/serializable-closure

Laravel Serializable Closure provides an easy and secure way to serialize closur...

465,816,364 607

Version History

Version Released PHP License
11.4.0 ^7.4 || ^8.0 MIT
11.3.3 ^7.4 || ^8.0 MIT
11.3.2 ^7.4 || ^8.0 MIT
11.3.1 ^7.4 || ^8.0 MIT
11.3.0 ^7.4 || ^8.0 MIT
Pre-releases (77)
Version Released PHP License
12.0.0-beta.10 ^8.3 MIT
12.0.0-beta.9 ^8.3 MIT
12.0.0-beta.8 ^8.3 MIT
12.0.0-beta.7 ^8.3 MIT
12.0.0-beta.6 ^8.3 MIT