HelloWorld
What’s different
Section titled “What’s different”HelloWorld echoed a string back without authentication. Parcel2Go has no echo endpoint. A connectivity check is two calls instead:
- Request a token. A
200proves your Client ID, secret and environment are right. See Request a token. - Call a simple read endpoint with the token.
GET /api/countriesis a good choice: it’s aGETwith no parameters, and you’ll use it anyway to convert country codes.
Examples
Section titled “Examples”curl -X GET "https://sandbox.parcel2go.com/api/countries" \ -H "Authorization: Bearer $P2G_TOKEN" \ -H "Accept: application/json"<?php// $p2g is the client from the Authentication page$countries = $p2g->request('GET', '/api/countries');[ { "Name": "United Kingdom", "Iso3Code": "GBR", "Iso2Code": "GB", "Subdivision": null, "RequiresDimensions": false }, { "Name": "United States", "Iso3Code": "USA", "Iso2Code": "US", "Subdivision": null, "RequiresDimensions": true }]Abridged: two of the countries shown, and some fields left out.
Compare with the Parcel Monkey HelloWorld call
curl -X POST "https://api.parcelmonkey.co.uk/HelloWorld" \ -H "Content-Type: application/json" \ -H "apiversion: 3.3" \ -d '{ "echo": "Test123"}'<?php$ch = curl_init('https://api.parcelmonkey.co.uk/HelloWorld');curl_setopt_array($ch, [ CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => ['Content-Type: application/json', 'apiversion: 3.3'], CURLOPT_POSTFIELDS => json_encode([ 'echo' => 'Test123', ]),]);$response = json_decode(curl_exec($ch), true);{ "hello": "Success!", "echo": "Test123"}Field mapping
Section titled “Field mapping”| Parcel Monkey | Parcel2Go | Required | Notes |
|---|---|---|---|
echo | No equivalent | No equivalent. Use the token request plus GET /api/countries as the connectivity check. |
| Parcel Monkey | Parcel2Go | Required | Notes |
|---|---|---|---|
hello | No equivalent | A 200 from the token endpoint and from GET /api/countries is the success signal. | |
echo | No equivalent | No equivalent. |
Reference
Section titled “Reference”-
GET /api/countries - Parcel2Go quickstart