A PHP SDK for the PostNord API
Installs: 22 471
Open Issues: 4
- php: >=7.4
- psr/http-client: ^1.0
- psr/http-factory: ^1.0
- psr/http-message: ^1.0.1
- thecodingmachine/safe: ^1.0
- kriswallsmith/buzz: ^1.0
- nyholm/psr7: ^1.1
- phpspec/phpspec: ^6.2
- phpunit/phpunit: ^8.5
- setono/code-quality-pack: ^1.2.1
- dev-master / 1.2.x-dev
This package is auto-updated.
Last update: 2023-05-26 11:40:29 UTC
A PHP SDK for the PostNord API.
Open a command console, enter your project directory and execute the following command to download the latest stable version of this library:
$ composer require setono/post-nord-php-sdk
This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.
Here is an example showing you can get the nearest service points.
Notice that this example uses two libraries that are not installed by default: The PSR 17 factory and the HTTP client implementation.
If you don't have any preferences, you can install these two libraries:
$ composer require kriswallsmith/buzz nyholm/psr7.
<?php use Buzz\Client\Curl; use Nyholm\Psr7\Factory\Psr17Factory; use Setono\PostNord\Client\Client; $psr17Factory = new Psr17Factory(); $httpClient = new Curl($psr17Factory); $client = new Client($httpClient, $psr17Factory, $psr17Factory, 'INSERT API KEY'); $client->get('/rest/businesslocation/v1/servicepoint/findNearestByAddress.json', [ 'countryCode' => 'DK', 'postalCode' => '9000', ]);
If you know that you will only use the Location API you could change the base URL when you instantiate the client to make the requests easier to read:
<?php use Buzz\Client\Curl; use Nyholm\Psr7\Factory\Psr17Factory; use Setono\PostNord\Client\Client; $psr17Factory = new Psr17Factory(); $httpClient = new Curl($psr17Factory); $client = new Client($httpClient, $psr17Factory, $psr17Factory, 'INSERT API KEY', 'https://api2.postnord.com/rest/businesslocation/v1/servicepoint'); $client->get('findNearestByAddress.json', [ 'countryCode' => 'DK', 'postalCode' => '9000', ]);
- There is a Symfony bundle integrating this library: Symfony Post Nord Bundle