Create a Single Letter
This request will create a letter and perform a mail merge to put the address and any variable data in place. You can specify a template or provide the content directly.
Request
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api-us1.stannp.com/v1/letters/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' => "1",
'file' => "https://www.stannp.com/assets/samples/letter-heading.pdf",
'recipient[title]' => "Mr",
'recipient[firstname]' => "John",
'recipient[lastname]' => "Smith",
'recipient[address1]' => "1000 N west street",
'recipient[address2]' => "Suite 1200 #1939",
'recipient[town]' => "Wilmington",
'recipient[zipcode]' => "19801",
'recipient[country]' => "US",
'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\/letter-sample-12345-12345-abcdeg.pdf", "id": "0", "created": "2022-10-01T15:42:22+00:00", "format": "us-letter", "cost": "0.76", "status": "test" } }
Post a Letter (Already Mail Merged)
Post a single letter that already has an address on the PDF file. Use this endpoint if you have already mail-merged your letter and it meets our design guidelines.
Request
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api-us1.stannp.com/v1/letters/post?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' => "1",
'country' => "US",
'pdf' => "https://www.stannp.com/assets/samples/letter-sample-abcdefg-12356.pdf"
),
));
$response = curl_exec($curl);
curl_close($curl);
print_r($response);
?>
Response
{ "success": true, "data": { "pdf": "https:\/\/www.stannp.com\/assets\/samples\/letter-sample.pdf", "id": "0", "created": "2022-12-01T15:42:22+00:00", "format": "letter", "cost": "0.78", "status": "test" } }
Get a Single Letter
Obtain the mailpiece object for the letter 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-us1.stannp.com/v1/letters/get/:id?api_key=" . API_KEY, false, $context);
$response = json_decode($result, true);
print_r($response);
?>
Response
{ "success": true, "data": { "id": "16818210", "timestamp": "2019-02-13 00:14:04", "status": "cancelled", "type": "letter", "format": "A4", "pdf_file": "https:\/\/dash.stannp.com\/api\/v1\/storage\/get\/port\/1550016843\/pdfs\/15500168437775c63614bd88b1-d26cc45469-A4-K5aZSp.pdf", "country": "US", "cost": "0.00" } }
Cancel a Letter
Cancel a letter if it has not started processing yet.
Request
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api-us1.stannp.com/v1/letters/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 }