Home > Uncategorized > Send a #Postcard via c# using @StannpApp

Send a #Postcard via c# using @StannpApp

app-postcard-reverse-holder

This code will request that a message is printed onto a postcard and posted to an address of your choice, for about 40p (ish) – pretty cool.

You’ll need your own API key, and you should test it with your own address first.

var strPostData = “test=false”;
strPostData += “&size=A6”;
strPostData += “&front=https%3A%2F%2Fwww.stannp.com%2Fassets%2Fsamples%2Fa6-postcard-front.jpg”;
strPostData += “&message=hello+there!”;
strPostData += “&signature=https://www.stannp.com/assets/samples/signature-example.jpg”;
strPostData += “&recipient[title]=Mr”;
strPostData += “&recipient[firstname]=You”;
strPostData += “&recipient[lastname]=You”;
strPostData += “&recipient[address1]=Your Address”;
strPostData += “&recipient[address2]=London”;
strPostData += “&recipient[town]=London”;
strPostData += “&recipient[postcode]=Your Postcode”;
strPostData += “&recipient[country]=GB”;
WebClient wc = new WebClient();
var strUrl = “https://dash.stannp.com/api/v1/postcards/create”;
string credentials = Convert.ToBase64String( Encoding.ASCII.GetBytes(“{{YOUR API KEY HERE}}:”));
wc.Headers[HttpRequestHeader.Authorization] = string.Format(
“Basic {0}”, credentials);
try
{
wc.Headers[HttpRequestHeader.ContentType] = “application/x-www-form-urlencoded”;
var strResponse = wc.UploadString(strUrl , “POST”, strPostData);
}
catch (WebException exception)
{
string responseText;

var responseStream = exception.Response?.GetResponseStream();

if (responseStream != null)
{
using (var reader = new StreamReader(responseStream))
{
responseText = reader.ReadToEnd();
}
}
}

Advertisements
Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: