PHPackages                             postmen/sdk-php - 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. postmen/sdk-php

ActiveLibrary[API Development](/categories/api)

postmen/sdk-php
===============

PHP for Postmen API. This extension helps developers to integrate with Postmen easily.

1.0.0(10y ago)1137.3k↓50%11[2 PRs](https://github.com/postmen/sdk-php/pulls)MITPHP

Since Jan 29Pushed 5y ago3 watchersCompare

[ Source](https://github.com/postmen/sdk-php)[ Packagist](https://packagist.org/packages/postmen/sdk-php)[ RSS](/packages/postmen-sdk-php/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

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

[](#introduction)

PHP SDK for [Postmen API](https://docs.postmen.com/). For problems and suggestions please open [GitHub issue](https://github.com/postmen/postmen-sdk-php/issues)

**Table of Contents**

- [Installation](#installation)
    - [Requirements](#requirements)
    - [Manual installation](#manual-installation)
    - [Using Composer](#using-composer)
- [Quick Start](#quick-start)
- [class Postmen](#class-postmen)
    - [Postmen($api\_key, $region, $config = array())](#postmenapi_key-region-config--array)
    - [create($resource, $payload, $config = array())](#createresource-payload-config--array)
    - [get($resource, $id = NULL, $query = array(), $config = array())](#getresource-id--null-query--array-config--array)
    - [getError()](#geterror)
    - [callGET($path, $query = array(), $options = array())](#callgetpath-query--array-options--array)
    - [callPOST($path, $body = array(), $options = array())](#callpostpath-body--array-options--array)
    - [callPUT($path, $body = array(), $options = array())](#callputpath-body--array-options--array)
    - [callDELETE($path, $body = array(), $options = array())](#calldeletepath-body--array-options--array)
- [Error Handling](#error-handling)
    - [class PostmenException](#class-postmenexception)
    - [Automatic retry on retryable error](#automatic-retry-on-retryable-error)
- [Examples](#examples)
    - [Full list](#full-list)
    - [How to run](#how-to-run)
    - [Navigation table](#navigation-table)
- [Testing](#testing)
- [License](#license)
- [Contributors](#contributors)

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

[](#installation)

#### Requirements

[](#requirements)

PHP version `>= 5.3` is required. For SDK development PHP `5.6` is required (to run automated tests).

Tested on PHP 5.3, 5.4, 5.5, 5.6.

#### Manual installation

[](#manual-installation)

- Download the source code.
- Reference API class.

```
require('.../path/to/repository/src/Postmen/Postmen.php');
```

#### Using Composer

[](#using-composer)

- If you don't have Composer, [download and install](https://getcomposer.org/download/)
- You have 2 options to download the Postmen PHP SDK

Run the following command to require Postmen PHP SDK

```
composer require postmen/sdk-php

```

OR download the sorce code and run

```
composer install

```

- Autoload the `postmen-php-sdk` package.

```
$loader = require __DIR__ . '/vendor/autoload.php';
```

Quick Start
-----------

[](#quick-start)

In order to get API key and choose a region refer to the [documentation](https://docs.postmen.com/overview.html).

```
use Postmen\Postmen;

$api_key = 'YOUR_API_KEY';
$region = 'sandbox';

// create Postmen API handler object

$api = new Postmen($api_key, $region);

try {
	// as an example we request all the labels

	$result = $api->get('labels');
	echo "RESULT:\n";
	print_r($result);
} catch (exception $e) {
	// if error occurs we can access all
	// the details in following way

	echo "ERROR:\n";
	echo $e->getCode() . "\n";	// error code
	echo $e->getMessage() . "\n";	// error message
	print_r($e->getDetails());	// details
}
```

class Postmen
-------------

[](#class-postmen)

#### Postmen($api\_key, $region, $config = array())

[](#postmenapi_key-region-config--array)

Initiate Postmen SDK object. In order to get API key and choose a region refer to the [documentation](https://docs.postmen.com/overview.html).

ArgumentRequiredTypeDefaultDescription`$api_key`YESStringN / AAPI key`$region`NO if `$config['endpoint']` is setStringN / AAPI region (`sandbox`, `production`)`$config`NOArray`array()`Options`$config['endpoint']`—StringN / ACustom URL API endpoint`$config['retry']`—Boolean`TRUE`Automatic retry on retryable errors`$config['rate']`—Boolean`TRUE`Wait before API call if rate limit exceeded or retry on 429 error`$config['safe']`—Boolean`FALSE`Suppress exceptions on errors, NULL would be returned instead, check [Error Handling](#error-handling)`$config['raw']`—Boolean`FALSE`To return API response as a raw string`$config['array']`—Boolean`FALSE`To return API response as an associative array`$config['proxy']`—Array`array()`Proxy credentials`$config['proxy']['host']`YES if `$config['proxy']` is not emptyStringN / AProxy host`$config['proxy']['port']`NOIntegerN / AProxy port`$config['proxy']['username']`NOStringN / AProxy user name`$config['proxy']['password']`NOStringN / AProxy password#### create($resource, $payload, $config = array())

[](#createresource-payload-config--array)

Creates API `$resource` object, returns new object payload as `Array`.

ArgumentRequiredTypeDefaultDescription`$resource`YESStringN / APostmen API resourse ('rates', 'labels', 'manifests')`$payload`YESArray or StringN / APayload according to API`$config`NOArray`array()`Override constructor [config](#postmenapi_key-region-config--array)**API Docs:**

- [POST /rates](https://docs.postmen.com/#rates-calculate-rates)
- [POST /labels](https://docs.postmen.com/#labels-create-a-label)
- [POST /manifests](https://docs.postmen.com/#manifests-create-a-manifest)
- [POST /cancel-labels](https://docs.postmen.com/#cancel-labels-cancel-a-label)

**Examples:**

- [rates\_create.php](https://github.com/postmen/postmen-sdk-php/blob/master/examples/rates_create.php)
- [labels\_create.php](https://github.com/postmen/postmen-sdk-php/blob/master/examples/labels_create.php)
- [manifests\_create.php](https://github.com/postmen/postmen-sdk-php/blob/master/examples/manifests_create.php)
- [cancel\_labels\_create.php](https://github.com/postmen/postmen-sdk-php/blob/master/examples/cancel_labels_create.php)

#### get($resource, $id = NULL, $query = array(), $config = array())

[](#getresource-id--null-query--array-config--array)

Gets API `$resource` objects (list or a single objects).

ArgumentRequiredTypeDefaultDescription`$resource`YESStringN / APostmen API resourse ('rates', 'labels', 'manifests')`$id`NOString`NULL`Object ID, if not set 'list all' API method is used`$query`NOArray or String`array()`Optional parameters for 'list all' API method`$config`NOArray`array()`Override constructor [config](#postmenapi_key-region-config--array)**API Docs:**

- [GET /rates](https://docs.postmen.com/#rates-list-all-rates)
- [GET /rates/:id](https://docs.postmen.com/#rates-retrieve-rates)
- [GET /labels](https://docs.postmen.com/#labels-list-all-labels)
- [GET /labels/:id](https://docs.postmen.com/#labels-retrieve-a-label)
- [GET /manifests](https://docs.postmen.com/#manifests-list-all-manifests)
- [GET /manifests/:id](https://docs.postmen.com/#manifests-retrieve-a-manifest)
- [GET /cancel-labels](https://docs.postmen.com/#cancel-labels-list-all-cancel-labels)
- [GET /cancel-labels/:id](https://docs.postmen.com/#cancel-labels-retrieve-a-cancel-label)

**Examples:**

- [rates\_retrieve.php](https://github.com/postmen/postmen-sdk-php/blob/master/examples/rates_retrieve.php)
- [labels\_retrieve.php](https://github.com/postmen/postmen-sdk-php/blob/master/examples/labels_retrieve.php)
- [manifests\_retrieve.php](https://github.com/postmen/postmen-sdk-php/blob/master/examples/manifests_retrieve.php)
- [cancel\_labels\_retrieve.php](https://github.com/postmen/postmen-sdk-php/blob/master/examples/cancel_labels_retrieve.php)

#### getError()

[](#geterror)

Returns SDK error, [PostmenException type](#class-postmenexception) if `$conifg['safe'] = TRUE;` was set.

Check [Error Handling](#error-handling) for details.

#### callGET($path, $query = array(), $options = array())

[](#callgetpath-query--array-options--array)

Performs HTTP GET request, returns an `Array` object holding API response.

ArgumentRequiredTypeDefaultDescription`$path`YESStringN / AURL path (e.g. 'v3/labels' for `https://sandbox-api.postmen.com/v3/labels` )`$query`NOArray or String`array()`HTTP GET request query string`$config`NOArray`array()`Override constructor [config](#postmenapi_key-region-config--array)#### callPOST($path, $body = array(), $options = array())

[](#callpostpath-body--array-options--array)

#### callPUT($path, $body = array(), $options = array())

[](#callputpath-body--array-options--array)

#### callDELETE($path, $body = array(), $options = array())

[](#calldeletepath-body--array-options--array)

Performs HTTP POST/PUT/DELETE request, returns an `Array` object holding API response.

ArgumentRequiredTypeDefaultDescription`$path`YESStringN / AURL path (e.g. 'v3/labels' for `https://sandbox-api.postmen.com/v3/labels` )`$body`YESArray or StringN / AHTTP POST/PUT/DELETE request body`$config`NOArray`array()`Override constructor [config](#postmenapi_key-region-config--array)Error Handling
--------------

[](#error-handling)

Particular error details are listed in the [documentation](https://docs.postmen.com/errors.html).

All SDK methods may throw an exception described below.

#### class PostmenException

[](#class-postmenexception)

MethodReturn typeDescriptiongetCode()IntegerError codeisRetryable()BooleanIndicates if error is retryablegetMessage()StringError message (e.g. `The request was invalid or cannot be otherwise served`)getDetails()ArrayError details (e.g. `Destination country must be RUS or KAZ`)In case of `$conifg['safe'] = TRUE;` SDK would not throw exceptions, [getError()](#geterror) must be used instead.

Example: [error.php](https://github.com/postmen/postmen-sdk-php/blob/master/examples/error.php)

#### Automatic retry on retryable error

[](#automatic-retry-on-retryable-error)

If API error is retryable, SDK will wait for delay and retry. Delay starts from 1 second. After each try, delay time is doubled. Maximum number of attempts is 5.

To disable this option set `$conifg['retry'] = FALSE;`

Examples
--------

[](#examples)

#### Full list

[](#full-list)

All examples avalible listed in the table below.

FileDescription[rates\_create.php](https://github.com/postmen/postmen-sdk-php/blob/master/examples/rates_create.php)`rates` object creation[rates\_retrieve.php](https://github.com/postmen/postmen-sdk-php/blob/master/examples/rates_retrieve.php)`rates` object(s) retrieve[labels\_create.php](https://github.com/postmen/postmen-sdk-php/blob/master/examples/labels_create.php)`labels` object creation[labels\_retrieve.php](https://github.com/postmen/postmen-sdk-php/blob/master/examples/labels_retrieve.php)`labels` object(s) retrieve[manifests\_create.php](https://github.com/postmen/postmen-sdk-php/blob/master/examples/manifests_create.php)`manifests` object creation[manifests\_retrieve.php](https://github.com/postmen/postmen-sdk-php/blob/master/examples/manifests_retrieve.php)`manifests` object(s) retrieve[cancel\_labels\_create.php](https://github.com/postmen/postmen-sdk-php/blob/master/examples/cancel_labels_create.php)`cancel-labels` object creation[cancel\_labels\_retrieve.php](https://github.com/postmen/postmen-sdk-php/blob/master/examples/cancel_labels_retrieve.php)`cancel-labels` object(s) retrieve[proxy.php](https://github.com/postmen/postmen-sdk-php/blob/master/examples/proxy.php)Proxy usage[error.php](https://github.com/postmen/postmen-sdk-php/blob/master/examples/error.php)Avalible ways to catch/get errors[response.php](https://github.com/postmen/postmen-sdk-php/blob/master/examples/response.php)Avalible output types#### How to run

[](#how-to-run)

Download the source code, go to `examples` directory.

Put your API key and region to [credentials.php](https://github.com/postmen/postmen-sdk-php/blob/master/examples/credentials.php)

Check the file you want to run before run. Some require you to set additional variables.

#### Navigation table

[](#navigation-table)

For each API method SDK provides PHP wrapper. Use the table below to find SDK method and example that match your need.

  Model \\ Action create get all get by id   rates [ `.create('rates', $payload, $opt)` ](https://github.com/postmen/postmen-sdk-php/blob/master/examples/rates_create.php) [ `.get('rates', NULL, NULL, $opt)` ](https://github.com/postmen/postmen-sdk-php/blob/master/examples/rates_retrieve.php#L16) [ `.get('rates', $id, NULL, $opt)` ](https://github.com/postmen/postmen-sdk-php/blob/master/examples/rates_retrieve.php#L18)   labels [ `.create('labels', $payload, $opt)` ](https://github.com/postmen/postmen-sdk-php/blob/master/examples/labels_create.php) [ `.get('labels', NULL, NULL, $opt)` ](https://github.com/postmen/postmen-sdk-php/blob/master/examples/labels_retrieve.php#L16) [ `.get('labels', $id, NULL, $opt)` ](https://github.com/postmen/postmen-sdk-php/blob/master/examples/labels_retrieve.php#L18)   manifest [ `.create('manifest', $payload, $opt)` ](https://github.com/postmen/postmen-sdk-php/blob/master/examples/manifests_create.php) [ `.get('manifest', NULL, NULL, $opt)` ](https://github.com/postmen/postmen-sdk-php/blob/master/examples/manifests_retrieve.php#L16) [ `.get('manifest', $id, NULL, $opt)` ](https://github.com/postmen/postmen-sdk-php/blob/master/examples/manifests_retrieve.php#L18)   cancel-labels [ `.create('cancel-labels', $payload, $opt)` ](https://github.com/postmen/postmen-sdk-php/blob/master/examples/cancel_labels_create.php) [ `.get('cancel-labels', NULL, NULL, $opt)` ](https://github.com/postmen/postmen-sdk-php/blob/master/examples/cancel_labels_retrieve.php#L16) [ `.get('cancel-labels', $id, NULL, $opt)` ](https://github.com/postmen/postmen-sdk-php/blob/master/examples/cancel_labels_retrieve.php#L18) Testing
-------

[](#testing)

If you contribute to SDK, run automated test before you make pull request.

`phpunit --bootstrap tests/bootstrap.php tests/Postmen.php`

License
-------

[](#license)

Released under the MIT license. See the LICENSE file for details.

Contributors
------------

[](#contributors)

- Sunny Chow - [view contributions](https://github.com/postmen/sdk-php/commits?author=sunnychow)
- Marek Narozniak - [view contributions](https://github.com/postmen/sdk-php/commits?author=marekyggdrasil)

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity37

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 91.8% 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

Unknown

Total

1

Last Release

3763d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/84eff618ecd245e9a99b395eeb81df23e16a044a95a85b1d02a0edec3f42b55a?d=identicon)[aftership](/maintainers/aftership)

---

Top Contributors

[![marekyggdrasil](https://avatars.githubusercontent.com/u/8202674?v=4)](https://github.com/marekyggdrasil "marekyggdrasil (89 commits)")[![sunnychow](https://avatars.githubusercontent.com/u/6318765?v=4)](https://github.com/sunnychow "sunnychow (6 commits)")[![fedor](https://avatars.githubusercontent.com/u/2085674?v=4)](https://github.com/fedor "fedor (1 commits)")[![krzyzak](https://avatars.githubusercontent.com/u/185015?v=4)](https://github.com/krzyzak "krzyzak (1 commits)")

---

Tags

aftershipapipostmensdkshippingshipping-api

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/postmen-sdk-php/health.svg)

```
[![Health](https://phpackages.com/badges/postmen-sdk-php/health.svg)](https://phpackages.com/packages/postmen-sdk-php)
```

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[facebook/php-business-sdk

PHP SDK for Facebook Business

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

PHP wrapper for the Meilisearch API

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

Google API Core for PHP

265103.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)
