Advertisement
Guest User

Untitled

a guest
Oct 24th, 2017
453
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.21 KB | None | 0 0
  1.     using System;
  2.     using System.Net;
  3.     using System.IO;
  4.    
  5.     class ExamplePostmen
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             WebRequest httpWebRequest = WebRequest.Create("https://sandbox-api.postmen.com/v3/labels");
  10.             string json = "{\"async\":false,\"billing\":{\"paid_by\":\"shipper\"},\"customs\":{\"billing\":{\"paid_by\":\"recipient\"},\"purpose\":\"merchandise\"},\"return_shipment\":false,\"service_type\":\"fedex-smartpost\",\"paper_size\":\"4x6\",\"shipper_account\":{\"id\":\"00000000-0000-0000-0000-000000000000\"},\"shipment\":{\"ship_from\":{\"contact_name\":\"Fred Newth\",\"company_name\":\"RC Scale Model\",\"street1\":\"2802 Live Oak Drive, \",\"city\":\"Grapevine\",\"state\":\"Texas\",\"postal_code\":\"76051\",\"country\":\"USA\",\"phone\":\"9727410501\",\"email\":\"test@test.com\",\"type\":\"business\"},\"ship_to\":{\"contact_name\":\"Jon Poole\",\"street1\":\"212 South Street\",\"city\":\"Concord\",\"state\":\"New Hampshire\",\"postal_code\":\"03301\",\"country\":\"USA\",\"phone\":\"6034919890\",\"email\":\"test@test.test\",\"type\":\"residential\"},\"parcels\":[{\"description\":\"Food XS\",\"box_type\":\"custom\",\"weight\":{\"value\":2,\"unit\":\"kg\"},\"dimension\":{\"width\":20,\"height\":40,\"depth\":40,\"unit\":\"cm\"},\"items\":[{\"description\":\"Food Bar\",\"origin_country\":\"USA\",\"quantity\":2,\"price\":{\"amount\":3,\"currency\":\"USD\"},\"weight\":{\"value\":0.6,\"unit\":\"kg\"},\"sku\":\"Epic_Food_Bar\",\"hs_code\":\"1234.12\"}]}]}}";
  11.    
  12.             httpWebRequest.ContentType = "application/json";
  13.             httpWebRequest.Method = "POST";
  14.             httpWebRequest.Headers["postmen-api-key"] = "8fc7966b-679b-4a57-911d-c5a663229c9e";
  15.    
  16.             using (StreamWriter streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
  17.             {
  18.                 streamWriter.Write(json);
  19.                 streamWriter.Flush();
  20.                 streamWriter.Close();
  21.             }
  22.    
  23.             HttpWebResponse httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
  24.             using (StreamReader streamReader = new StreamReader(httpResponse.GetResponseStream()))
  25.             {
  26.                 string result = streamReader.ReadToEnd();
  27.                 Console.WriteLine(result);
  28.             }
  29.         }
  30.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement