1. Home
  2. Docs
  3. REST API Code Samples
  4. C#

C#

C# POST code sample

void transactionalEmails_sendTemplate() { string URL = "http://api.inwise.com/rest/v1/transactional/emails/sendTemplate"; string api_key="XXXXXXXXXXX"; string DATA = @"{ "template_id":123456, // according to account's template "message": { "html": " ", "text": "text  text", "subject": "this is message from C# code", "from_email": "YYY@inwise.com", // Sender email address according to the specific account "from_name": "from me ", "charset": "utf-8", "content_type": "html", "to": [ { "email": "YYY@inwise.com", "name": "YYY", "type": "to" // Could be to/cc/bcc } ] } }"; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL); request.Method = "POST"; request.ContentType = "application/json"; request.Accept = "application/json"; request.ContentLength = DATA.Length; request.X-API-Key = api_key; StreamWriter requestWriter = new StreamWriter(request.GetRequestStream(), System.Text.Encoding.ASCII); requestWriter.Write(DATA); requestWriter.Close(); try { WebResponse webResponse = request.GetResponse(); Stream webStream = webResponse.GetResponseStream(); StreamReader responseReader = new StreamReader(webStream); string response = responseReader.ReadToEnd(); Console.Out.WriteLine(response); responseReader.Close(); Response.Write(response); } catch (Exception e1) { Console.Out.WriteLine("-----------------"); Console.Out.WriteLine(e1.Message); Response.Write("asfd"); } }

C# GET code sample

void contacts_getById()
{
string apikey = "API_KEY";
string contact_id = "CONTACT_ID";
string URL = "https://api.inwise.com/rest/v1/contacts/;
try
{
HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(URL);
myReq.Method = "
GET";
myReq.ContentType = "
application/json";
myReq.Accept = "
application/json";
myReq.X-API-Key = apikey;
WebResponse myResponse = myReq.GetResponse();
Stream rebut = myResponse.GetResponseStream();
StreamReader readStream = new StreamReader(rebut, Encoding.UTF8);
string info = readStream.ReadToEnd();
myResponse.Close();
readStream.Close();

xxxx.InnerText = info;
//Response.Write(info);
}

catch (Exception e1)
{
Console.Out.WriteLine("
-----------------");
Console.Out.WriteLine(e1.Message);
Response.Write(e1.ToString());
}
}

How can we help?