PHPackages                             soneritics/postnl - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. soneritics/postnl

ActiveLibrary[API Development](/categories/api)

soneritics/postnl
=================

PostNL API and Aanmaken van PostNL vooraanmeldingbestanden om pakketten te verzenden.

v3.3.0(5y ago)511.0k2[2 issues](https://github.com/Soneritics/PostNL/issues)MITPHPCI failing

Since May 28Pushed 5y ago3 watchersCompare

[ Source](https://github.com/Soneritics/PostNL)[ Packagist](https://packagist.org/packages/soneritics/postnl)[ Docs](https://github.com/Soneritics/PostNL)[ RSS](/packages/soneritics-postnl/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (4)Versions (17)Used By (0)

PostNL
======

[](#postnl)

[![Build Status](https://camo.githubusercontent.com/cf99d2841a7f72cf002bc58786a0f41b785ec9b43dea3ac082b6800b9b361a79/68747470733a2f2f6170692e7472617669732d63692e6f72672f536f6e657269746963732f506f73744e4c2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Soneritics/PostNL)[![Coverage Status](https://camo.githubusercontent.com/c39f2c96e4c081f55f353c81cd24d74b6f8dbf770a8589a01610a31af3f1b89d/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f536f6e657269746963732f506f73744e4c2f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/r/Soneritics/PostNL?branch=master)[![Latest Stable](https://camo.githubusercontent.com/f3f9ffe2f7a8ea22e703d24ed6c4c3aad73915e12c47dc6c3b527f98b7442ed8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f736f6e657269746963732f706f73746e6c2e7376673f7374796c653d666c61742d737175617265266c6162656c3d737461626c65)](https://packagist.org/packages/soneritics/postnl?branch=master)[![License](https://camo.githubusercontent.com/505fe3a551fc6e64816f64cee81471b04e7ef943170e4f994c249982b3fd4290/687474703a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e2e737667)](https://camo.githubusercontent.com/505fe3a551fc6e64816f64cee81471b04e7ef943170e4f994c249982b3fd4290/687474703a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e2e737667)

Introduction
------------

[](#introduction)

This library offers a variety of functions for PostNL. Mainly, these are the two categories:

- PostNL API -
- PostNL Voormeldbestand

Minimum requirements
--------------------

[](#minimum-requirements)

- PHP 7.1

Installation
------------

[](#installation)

Use Composer to install: soneritics/postnl

PostNL API
----------

[](#postnl-api)

The base for connecting to the PostNL API will be provided by this plugin. It is advised not to use it in a production environment, as it's nog error-proof, nor (fully automated) tested. It does work, though, and is currently being tested in a production environment :-)

Create an issue if you need help, or need more services than the ones provided.

### Supported APIs

[](#supported-apis)

ServiceImplementedVersion**Send &amp; Track**Barcode webservice✓1\_1Confirming webservice✓1\_10Labelling webservice✓2\_2\*Shippingstatus webservice✓v2**Delivery options**Deliverydate webserviceXN/ALocation webservice✓2\_1Timeframe webservice✓2\_1**Checkout**Postalcode Check✓1> \*`v2_2` supports ERS labels

### Code example: Creating the API

[](#code-example-creating-the-api)

Always start with creating the API object.

```
$apiKey = '*YOUR API KEY*';

$endpoints = new Sandbox;
$customer = (new Customer)
    ->setCustomerCode('DEVC')
    ->setCustomerNumber('11223344')
    ->setAddress((new Address)
        ->setAddressType(AddressType::SENDER)
        ->setCompanyName('Soneritics')
        ->setStreet('De Rosmolen')
        ->setHouseNr('123')
        ->setZipcode('1234AB')
        ->setCity('Amsterdam')
        ->setCountrycode('NL')
    );

$api = new API($apiKey, $customer, $endpoints);
```

### Code example: Fetching a barcode

[](#code-example-fetching-a-barcode)

```
$barcodeService = $api->getBarcodeService();
$barcode = $barcodeService->generateBarcode();
echo "generated barcode: {$barcode}\r\n";
```

### Code example: Generate a label and confirm shipment (basic)

[](#code-example-generate-a-label-and-confirm-shipment-basic)

```
$message = new Message(1, PrinterType::JPG);
$dimension = (new Dimension)->setWeight(1000);
$receivingAddress = (new Address)
    ->setAddressType(AddressType::RECEIVER)
    ->setCompanyName('Jordi Jolink')
    ->setStreet('Some street')
    ->setHouseNr('123')
    ->setZipcode('1234AB')
    ->setCity('Amsterdam')
    ->setCountrycode('NL');

$shipments = (new Shipments)->addShipment(
    (new Shipment)
        ->setAddresses((new Addresses)->addAddress($receivingAddress))
        ->setBarcode($barcode)
        ->setDimension($dimension)
);

$result = $api->getLabellingService()->generateLabel($shipments, $message);
$labelContentsBase64 = $result['ResponseShipments'][0]['Labels'][0]['Content'];
```

### Code example: Get time frames, get a label and confirm the shipment

[](#code-example-get-time-frames-get-a-label-and-confirm-the-shipment)

```
$receivingAddress = (new Address)
    ->setAddressType(AddressType::RECEIVER)
    ->setCompanyName('Soneritics')
    ->setStreet('Some street')
    ->setHouseNr('123')
    ->setZipcode('1234AB')
    ->setCity('Amsterdam')
    ->setCountrycode('NL');

$deliveryOptions = [
    DeliveryOptions::DAYTIME,
    DeliveryOptions::EVENING,
    DeliveryOptions::AFTERNOON,
    DeliveryOptions::MORNING,
    DeliveryOptions::NOON
];

$result = $api->getTimeframeService()->calculateTimeframes($receivingAddress, $deliveryOptions);
echo "Timeframes:\r\n";
print_r($result);

# Confirm time frame
$barcodeService = $api->getBarcodeService();

echo "Confirming timeframe..\r\n";
if (!empty($result['Timeframes']['Timeframe'])) {
    $timeframe = array_pop($result['Timeframes']['Timeframe']);
    if ($timeframe !== null) {
        $deliveryTimestampStart = new DateTime($timeframe['Date'] . ' ' . $timeframe['Timeframes']['TimeframeTimeFrame']['From']);
        $deliveryTimestampEnd = new DateTime($timeframe['Date'] . ' ' . $timeframe['Timeframes']['TimeframeTimeFrame']['To']);

       $contact = (new Contact)->setEmail('mail@no-spam4me.nl');
       $shipments = (new Shipments)->addShipment(
            (new Shipment)
                ->setAddresses((new Addresses)->addAddress($receivingAddress))
                ->setBarcode($barcodeService->generateBarcode())
                ->setDimension($dimension)
                ->setDeliveryDate($deliveryTimestampStart)
                ->setDeliveryTimeStampStart($deliveryTimestampStart)
                ->setDeliveryTimeStampEnd($deliveryTimestampEnd)
                ->setContacts((new Contacts)->addContact($contact))
        );

        $result = $api->getLabellingService()->generateLabel($shipments, $message);
        print_r($result);
    }
}
echo "Timeframe confirmed.\r\n";
```

### Code example: Fetch nearest locations

[](#code-example-fetch-nearest-locations)

```
$receivingAddress = (new Address)
    ->setAddressType(AddressType::RECEIVER)
    ->setZipcode('1234AB')
    ->setCountrycode('NL');

$result = $api->getLocationsService()->getNearestLocations($receivingAddress);
print_r($result);
```

### Code example: Fetch nearest locations by geocode and lookup location info

[](#code-example-fetch-nearest-locations-by-geocode-and-lookup-location-info)

```
$result = $api->getLocationsService()->getNearestLocationsByGeocode(51.963807, 5.968984, 'NL');

if (!empty($result['GetLocationsResult']['ResponseLocation'])) {
    $location = $result['GetLocationsResult']['ResponseLocation'][0];
    print_r($location);

    echo "Location info:\r\n";
    $locationCode = $location['LocationCode'];
    $retailNetworkID = $location['RetailNetworkID'];
    print_r($api->getLocationsService()->getLocationInformation($locationCode, $retailNetworkID));
}
```

### Code example: Fetch nearest location and create a label for pickup at the pickup point

[](#code-example-fetch-nearest-location-and-create-a-label-for-pickup-at-the-pickup-point)

```
$result = $api->getLocationsService()->getNearestLocationsByGeocode(51.963807, 5.968984, 'NL');

if (!empty($result['GetLocationsResult']['ResponseLocation'])) {
    $location = $result['GetLocationsResult']['ResponseLocation'][0];
    $locationCode = $location['LocationCode'];
    $retailNetworkID = $location['RetailNetworkID'];

    $pickupAddress = (new \PostNL\Model\Address)
        ->setAddressType(\PostNL\Enum\AddressType::DELIVERY_ADDRESS_FOR_PICKUP)
        ->setCompanyName($location['Name'])
        ->setStreet($location['Address']['Street'])
        ->setHouseNr($location['Address']['HouseNr'])
        ->setZipcode($location['Address']['Zipcode'])
        ->setCity($location['Address']['City'])
        ->setCountrycode('NL');

    $contact = (new Contact)->setEmail('mail@jordijolink.nl');
    $shipments = (new Shipments)->addShipment(
        (new Shipment)
            ->setAddresses((new Addresses)->addAddress($receivingAddress)->addAddress($pickupAddress))
            ->setBarcode($barcodeService->generateBarcode())
            ->setDimension($dimension)
            ->setContacts((new Contacts)->addContact($contact))
            ->setProductCodeDelivery('3533')
            ->setDeliveryAddress(AddressType::DELIVERY_ADDRESS_FOR_PICKUP)
    );

    $result = $api->getLabellingService()->generateLabel($shipments, $message);
    print_r($result);
}
```

### Code example: Get the shipping status (via a barcode)

[](#code-example-get-the-shipping-status-via-a-barcode)

```
$endpoints = new Sandbox();
$api = new API($key, new Customer(), $endpoints);
$data = $api->getShippingStatusService()->getByBarcode($barcode);

```

---

PostNL Vooraanmelding
---------------------

[](#postnl-vooraanmelding)

### Codetaal: Nederlands

[](#codetaal-nederlands)

Voor de taal van de classes, variabelen en commentaar is gekozen voor Nederlands. Daarbij worden getters en setters als hybride aangeduid, bijvoorbeeld: setKlantnummer. Hiervoor is gekozen aangezien PostNL uitsluitend binnen Nederland verzendt, en daardoor ook vooral door Nederlanders geïmplementeerd zal worden. Daarnaast worden specifieke woorden gebruikt, waarvan de Engelse vertaling de werking erg onduidelijk zal maken.

### Code example

[](#code-example)

```
$afzender = (new Afzender)
    ->setBedrijfsnaam('Bedrijfsnaam')
    ->setPostcode('1234AB')
    ->setHuisnummerPostbusnummer('1')
    ->setLandcode('NL');

$voormelding = (new Voormelding)
    ->setAfzender($afzender)
    ->setKlantCode($customerCode)
    ->setKlantNummer($customerNr)
    ->setVolgnummer($volgnummer)
    ->setAanleverLocatie($bls);

$pakket = (new Pakket)
    ->setGeadresseerdeBedrijfsnaam($company)
    ->setGeadresseerdeVoornaam($firstname)
    ->setGeadresseerdeAchternaam($lastname)
    ->setGeadresseerdePostcode($zipcode)
    ->setGeadresseerdeStraatnaam($streetname)
    ->setGeadresseerdeHuisnummerPostbusnummer($housenumber)
    ->setGeadresseerdeHuisnummerToevoeging($housenumberExtension)
    ->setGeadresseerdeWoonplaats($city)
    ->setGeadresseerdeLandcode($country)
    ->setEmailadres($email)
    ->setZendingcode($shipmentCode);
$voormelding->addPakket($pakket);

// Contents ophalen. Dit kan opgeslagen worden in een LST bestand.
$voormeldContents = $voormelding->genereerInhoud()
```

---

ERS
---

[](#ers)

### Using ERS

[](#using-ers)

The product code for ERS labels is `4910`.

PostNL does not have documentation available for this product code, but you can use the documentation from product code `3085 Return label in the box` as a base. There are additional things required for using ERS:

- The `CustomerCode` (4 letters) should have ERS enabled, or be ERS specific. Contact PostNL support for this.
- The `Addressses` of the `Customer` and `Shipment` all need to have a `name` filled in.
- The `ReturnBarcode` should be set.

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance12

Infrequent updates — may be unmaintained

Popularity29

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity71

Established project with proven stability

 Bus Factor1

Top contributor holds 89.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~74 days

Recently: every ~63 days

Total

15

Last Release

1868d ago

Major Versions

v1.0.0 → v2.12018-06-05

v2.6.1 → v3.0.02020-07-28

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/3717850?v=4)[Jordi Jolink](/maintainers/soneritics)[@Soneritics](https://github.com/Soneritics)

---

Top Contributors

[![Soneritics](https://avatars.githubusercontent.com/u/3717850?v=4)](https://github.com/Soneritics "Soneritics (107 commits)")[![jorisatabix](https://avatars.githubusercontent.com/u/36499489?v=4)](https://github.com/jorisatabix "jorisatabix (10 commits)")[![aln-1](https://avatars.githubusercontent.com/u/17613001?v=4)](https://github.com/aln-1 "aln-1 (2 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/soneritics-postnl/health.svg)

```
[![Health](https://phpackages.com/badges/soneritics-postnl/health.svg)](https://phpackages.com/packages/soneritics-postnl)
```

###  Alternatives

[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M454](/packages/google-gax)[google/common-protos

Google API Common Protos for PHP

173103.7M50](/packages/google-common-protos)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
