Idempotent Requests
Our API supports an optional idempotency key for safely retrying requests without performing a repeat operation. If a request is idempotent, we will return the original response body with a 409
HTTP status. We match the body of the request so only identical requests will be treated as idempotent.
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' => "true",
'idempotency_key' => "e367c03e-3082-4c8e-b647-d6810761dcd4",
'background' => "https://www.stannp.com/assets/samples/letter-heading.webp",
'pages' => "Hello {firstname}, <br><br>This is my first letter.",
'recipient[title]' => "Mr",
'recipient[firstname]' => "John",
'recipient[lastname]' => "Smith",
'recipient[address1]' => "123 Sample Street",
'recipient[address2]' => "Sampleland",
'recipient[town]' => "Sampletown",
'recipient[postcode]' => "AB12 3CD",
'recipient[country]' => "US"
),
));
$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": "2020-12-17T15:42:22+00:00", "format": "letter", "cost": "0.78", "status": "test" } }