X

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.


[POST] https://api-us1.stannp.com/v1/letters/create

Request

                using RestSharp;

var client = new RestClient("https://api-us1.stannp.com/v1/letters/create?api_key={API_KEY}");
var request = new RestRequest(Method.POST);

request.AddParameter("test", "true");
request.AddParameter("idempotency_key", "e367c03e-3082-4c8e-b647-d6810761dcd4");
request.AddParameter("background", "https://www.stannp.com/assets/samples/letter-heading.webp");
request.AddParameter("pages", "Hello {firstname}, <br><br>This is my first letter.");
request.AddParameter("recipient[title]", "Mr");
request.AddParameter("recipient[firstname]", "John");
request.AddParameter("recipient[lastname]", "Smith");
request.AddParameter("recipient[address1]", "123 Sample Street");
request.AddParameter("recipient[address2]", "Sampleland");
request.AddParameter("recipient[town]", "Sampletown");
request.AddParameter("recipient[postcode]", "AB12 3CD");
request.AddParameter("recipient[country]", "US");


IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);
            

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"
    }
}