Create a single postcard
This request will create a postcard and perform a mail merge to put the address and any variable data in place.
Request
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api-eu1.stannp.com/v1/postcards/create?api_key={API_KEY}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => array(
'test' => "true",
'size' => "A6",
'front' => "https://www.stannp.com/assets/samples/a6-postcard-front.webp",
'back' => "https://www.stannp.com/assets/samples/signature-example.webp",
'message' => "hello world",
'recipient[title]' => "Mr",
'recipient[firstname]' => "John",
'recipient[lastname]' => "Smith",
'recipient[address1]' => "123 Sample Street",
'recipient[city]' => "Sampletown",
'recipient[postcode]' => "AB12 3CD",
'recipient[country]' => "GB",
'tags' => "used.for.reporting",
'addons' => "first_class"
),
));
$response = curl_exec($curl);
curl_close($curl);
print_r($response);
?>
Response
{ "success": true, "data": { "pdf": "https:\/\/www.stannp.com\/assets\/samples\/a6-postcard-sample.pdf", "id": "0", "created": "2020-12-17T15:42:22+00:00", "format": "A6", "cost": "0.78", "status": "test" } }
Get a single postcard
Obtain the mailpiece object for the postcard id specified.
Request
<?php
define("API_KEY", "YOUR API KEY");
$opts = array(
'http' => array(
'method' => 'GET',
'header' => 'Content-type: application/x-www-form-urlencoded'
)
);
$context = stream_context_create($opts);
$result = file_get_contents("https://api-eu1.stannp.com/v1/postcards/get/:id?api_key=" . API_KEY, false, $context);
$response = json_decode($result, true);
print_r($response);
?>
Response
{ "success": true, "data": { "id": "16818211", "timestamp": "2019-10-30 00:14:04", "status": "cancelled", "type": "postcard", "format": "A6", "pdf_file": "https:\/\/dash.stannp.com\/api\/v1\/storage\/get\/port\/1550016843\/pdfs\/sample.pdf", "dispatched": null, "country": "GB", "cost": "0.00", "addons": "", "tags": "", "postcode": "AB12 3CD", "address": "123 Sample Street" } }
Cancel a postcard
You can cancel a postcard if we haven't started processing it yet.
Request
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api-eu1.stannp.com/v1/postcards/cancel?api_key={API_KEY}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => array(
'id' => "12345"
),
));
$response = curl_exec($curl);
curl_close($curl);
print_r($response);
?>
Response
{ "success": true }