public async Task <HttpResponseMessage> AtualizaStatusPedido(string token, string jsonBody) { var atualizaStatusPedidoJson = new StringContent(jsonBody, Encoding.UTF8, "application/json"); var authentication = new AuthenticationHeaderValue("bearer", token); var result = HttpPostService.PostService(_url, atualizaStatusPedidoJson, authentication); return(await Task.FromResult(result)); }
public MarketingContent[] GetContent() { try { var svcCredentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(_serverId + ":" + _apiKey)); var httpPostServer = new HttpPostService(); return(httpPostServer.Get <MarketingContent[]>("https://api.socketlabs.com/marketing/v1/content", "Authorization: Basic " + svcCredentials)); } catch (Exception ex) { Console.WriteLine("Error, something bad happened: " + ex.Message); return(null); } }
public async Task <string> GetToken(AuthenticationRequest authenticationRequest) { var jsonContent = new StringContent(JsonConvert.SerializeObject(authenticationRequest), Encoding.UTF8, "application/json"); var result = HttpPostService.PostService(_url, jsonContent, null); if (result.StatusCode != HttpStatusCode.OK) { return(await Task.FromResult(string.Empty)); } else { var contentBody = result.Content.ReadAsStringAsync().Result; var contentResult = JsonConvert.DeserializeObject <LoginResult>(contentBody); return(await Task.FromResult(contentResult.Token)); } }
private void SendMEssage(PostBody postBody) { try { var httpPostServer = new HttpPostService(); var response = httpPostServer.PostAndGetResponse <PostResponse>(postBody, "https://inject.socketlabs.com/api/v1/email", null); // Display the results. if (response.ErrorCode.Equals("Success")) { Console.WriteLine("Successful injection!"); } else if (response.ErrorCode.Equals("Warning")) { Console.WriteLine("Warning, not all recipients/messages were sent."); foreach (var result in response.MessageResults) { Console.WriteLine($"Message #{result.Index} {result.ErrorCode}"); foreach (var address in result.AddressResults) { Console.WriteLine( $"{address.EmailAddress} {address.ErrorCode} Sent: {address.Accepted}"); } } } else { Console.WriteLine("Failed injection!"); Console.WriteLine(response.ErrorCode); } } catch (Exception ex) { Console.WriteLine("Error, something bad happened: " + ex.Message); } }
public void SendWithInlineRecipientAdding() { // Construct the object used to generate JSON for the POST request. var postBody = new PostBody { ServerId = _serverId, ApiKey = _apiKey, Messages = new[] { new EmailMessage { Subject = "Email subject line for SDK example.", To = new[] { new Address { EmailAddress = "%%DeliveryAddress%%", FriendlyName = "%%DeliveryName%%" } }, From = new Address { EmailAddress = "*****@*****.**", FriendlyName = "From Address" }, TextBody = "The text portion of the message.", HtmlBody = "<h1>The HTML portion of the message</h1><br/><p>A paragraph.</p>", } } }; var mergeRows = new List <MergeRow[]>(); var contact1 = new List <MergeRow>(); contact1.Add(new MergeRow() { Field = "DeliveryAddress", Value = "*****@*****.**" }); contact1.Add(new MergeRow() { Field = "DeliveryName", Value = "recipient1" }); mergeRows.Add(contact1.ToArray()); var contact2 = new List <MergeRow>(); contact2.Add(new MergeRow() { Field = "DeliveryAddress", Value = "*****@*****.**" }); contact2.Add(new MergeRow() { Field = "DeliveryName", Value = "recipient1" }); mergeRows.Add(contact2.ToArray()); postBody.Messages[0].MergeData = new MergeData(); postBody.Messages[0].MergeData.PerMessage = mergeRows.ToArray(); try { var httpPostServer = new HttpPostService(); var response = httpPostServer.PostAndGetResponse <PostResponse>(postBody, "https://inject.socketlabs.com/api/v1/email", null); if (response.ErrorCode.Equals("Success")) { Console.WriteLine("Successful injection!"); } else { Console.WriteLine("Failed injection!"); Console.WriteLine(response.ErrorCode); } } catch (Exception ex) { Console.WriteLine("Error, something bad happened: " + ex.Message); } }
public void SendMergeMessageWithMultipleRecipientsUsingHelper() { // Construct the object used to generate JSON for the POST request. // The you can add any merge field you like if you are using API templates. var postBody = new PostBody { ServerId = _serverId, ApiKey = _apiKey, Messages = new[] { new EmailMessage { Subject = "%%Subject%%", To = new[] { new Address { EmailAddress = "%%DeliveryAddress%%", FriendlyName = "%%FriendlyName%%" } }, From = new Address { EmailAddress = "%%FromEmail%%", FriendlyName = "%%FromName%%" }, TextBody = "%%TextBody%%", HtmlBody = "%%HtmlBody%%", } } }; var bulkRecipientData = new BulkRecipientHelper(); bulkRecipientData.AddGlobalMergeField("Subject", "Email subject line for SDK example."); bulkRecipientData.AddGlobalMergeField("TextBody", "The text portion of the message. Using Merge %%CustomField%%."); bulkRecipientData.AddGlobalMergeField("HtmlBody", "<h1>The HTML portion of the message</h1><br/><p>A paragraph using Merge %%CustomField%%..</p>"); bulkRecipientData.AddGlobalMergeField("FromName", "Example Name"); bulkRecipientData.AddGlobalMergeField("FromEmail", "*****@*****.**"); bulkRecipientData.AddRecipient("*****@*****.**", "recipient 1"); bulkRecipientData.AddCustomFieldToRecipient("*****@*****.**", "CustomField", "Example 1"); bulkRecipientData.AddRecipient("*****@*****.**", "recipient 2"); bulkRecipientData.AddCustomFieldToRecipient("*****@*****.**", "CustomField", "Example 2"); bulkRecipientData.AddRecipient("*****@*****.**", "recipient 3"); bulkRecipientData.AddCustomFieldToRecipient("*****@*****.**", "CustomField", "Example 3"); postBody.Messages[0].MergeData = bulkRecipientData.GetMergeData(); try { var httpPostServer = new HttpPostService(); var response = httpPostServer.PostAndGetResponse <PostResponse>(postBody, "https://inject.socketlabs.com/api/v1/email", null); // Display the results. if (response.ErrorCode.Equals("Success")) { Console.WriteLine("Successful injection!"); } else if (response.ErrorCode.Equals("Warning")) { Console.WriteLine("Warning, not all recipients/messages were sent."); foreach (var result in response.MessageResults) { Console.WriteLine($"Message #{result.Index} {result.ErrorCode}"); foreach (var address in result.AddressResults) { Console.WriteLine($"{address.EmailAddress} {address.ErrorCode} Sent: {address.Accepted}"); } } } else { Console.WriteLine("Failed injection!"); Console.WriteLine(response.ErrorCode); } } catch (Exception ex) { Console.WriteLine("Error, something bad happened: " + ex.Message); } }