Last active
March 28, 2019 12:00
-
-
Save mrmch/6152701 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1) Set your API key | |
string api_key = "YOUR API KEY"; | |
// Let's create a request | |
string url = "https://api.sendwithus.com/api/v1_0/send"; | |
var httpWebRequest = (HttpWebRequest)WebRequest.Create(url); | |
httpWebRequest.ContentType = "text/json"; | |
httpWebRequest.Method = "POST"; | |
// set headers with api key | |
WebHeaderCollection headers = httpWebRequest.Headers; | |
headers.Add("X_SWU_API_KEY:" + api_key) | |
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) | |
{ | |
// 2) Set the data for request | |
string json = new JavaScriptSerializer().Serialize(new | |
{ | |
email_id = "EMAIL_ID", // required, id of email in sendwithus | |
recipient = new { // required, recipient information | |
address = "[email protected]", // required | |
name = "Customer Name" // optional | |
}, | |
sender = new { // optional | |
address = "[email protected]", // required if sender set | |
name = "From Name", // optional | |
reply_to = "[email protected]" // optional | |
} | |
}); | |
streamWriter.Write(json); | |
streamWriter.Flush(); | |
streamWriter.Close(); | |
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); | |
using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) | |
{ | |
var result = streamReader.ReadToEnd(); | |
// 3) Sample response (JSON) | |
/* | |
{ | |
"success" : true, | |
"status" : "OK", | |
"receipt_id" : "unique-receipt-id", | |
"email" : { | |
"name" : "Welcome New User!", | |
"version_name" : "My First Version" | |
} | |
} | |
*/ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am getting "The remote server returned an error: (400) Bad Request."
I have filled the proper API key