Download the PHP package szymsza/ppl-create-package-label-api without Composer
On this page you can find all versions of the php package szymsza/ppl-create-package-label-api. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download szymsza/ppl-create-package-label-api
More information about szymsza/ppl-create-package-label-api
Files in szymsza/ppl-create-package-label-api
Package ppl-create-package-label-api
Short Description A PHP package using OAUTH implementation to allow easier communication with PPL CPL API (aka MyAPI2).
License MIT
Informations about the package ppl-create-package-label-api
PPL MyApi2 client in PHP
PPL (Professional Parcel Logistic) recently launched a new version of their API called Create package label or MyApi2. This package allows you to connect to the API by simply providing your credentials without the need to set up OAuth. Further, it offers some helper functions for encoding requests or decoding responses.
Requirements
- PHP 7.4 or higher
Installation
Credentials
You must request your credentials and the API documentation from PPL support. Klient.ppl.cz credentials will not work.
Usage
The library's primary purpose is being only an OAuth wrapper dealing with authentication. Therefore, for most endpoints you will need to send raw requests and parse the received data yourself.
However, a simple example covering frequent use cases can be found in example/example.php
. After filling in your credentials, the script should work without any further configuration. After consulting this example script and the API documentation, using other endpoints should be intuitive.
Initializing the client
Basic connection
Call the API to get basic information, such as the API version or the current timee. Useful to test your connection.
Call the API to get Swaggger JSON describing the available API endpoints. You can view this JSON by pasting it, e.g., to https://editor.swagger.io/.
Request methods
The class offers three methods to initiate requests:
requestJson(string $path, string $method = 'get', array $data = []): array|object|null
initiates the request and returns the response as a decoded JSON array or object. This is useful in case the response of the endpoint is JSON and you do not care about the received headers.requestHeader(string $path, string $method = 'get', array $data = [], string $header = 'Location'): string
initiates the request and returns the value of a single header from the response. This is useful in case you do not care about the response body or values of other headers.request(string $path, string $method = 'get', array $data = [])
initiates the request and returns the rawResponseInterface
object. This is useful in case you cannot use either of the methods above, e.g., if you need both the response body and the headers.
For examply, you can use requestJson
to fetch available products like this:
Creating a shipment label
For using other endpoints consult the documentation and pick one of the adequate request
methods mentioned above.