Royal Mail Price API

An API to calculate the price of sending items via Royal Mail.

Host your own public or private API

or

Use the PHP library

Below is an example of how to calculate the price of sending an item via 2nd Class that is 10cm x 10cm x 2cm with the HTTP API.

curl -G http://localhost/index.php \
        -d "length=10" \
        -d "width=10" \
        -d "depth=2" \
        -d "services=secondclass"
[
    {
        "service": "2nd Class",
        "prices": [
            {
                "price": "0.73",
                "compensation": 20
            }
        ]
    }
]

To get started with running your own API click the link below to go to the GitHub repository.

JustinHook/royal-mail-price-api

Below is an example of how to calculate the price of sending an item via 2nd Class that is 10cm x 10cm x 2cm with the PHP library.

<?php
use \RoyalMailPriceCalculator\Calculator;
use \RoyalMailPriceCalculator\Package;
use \RoyalMailPriceCalculator\Services\SecondClassService;

$calculator = new Calculator();

$package = new Package();
$package->setDimensions(10, 10, 2);
$package->setWeight(90);

$calculator->setServices([
        new SecondClassService()
        ]);

foreach ($calculator->calculatePrice($package) as $calculated) {
    echo $calculated['service']->getName() . "\n";
    foreach ($calculated['prices'] as $price) {
        echo "  →  £{$price['price']} (Compensation: £{$price['compensation']})\n";
    }
    echo "\n";
}
2nd Class Service
  →  £0.73 (Compensation: £20)

To start using the calculator library in your PHP app click the link below to go to the GitHub repository.

JustinHook/royal-mail-price-calculator