Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Net;
- using System.IO;
- class ExamplePostmen
- {
- static void Main(string[] args)
- {
- WebRequest httpWebRequest = WebRequest.Create("https://sandbox-api.postmen.com/v3/labels");
- 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\"}]}]}}";
- httpWebRequest.ContentType = "application/json";
- httpWebRequest.Method = "POST";
- httpWebRequest.Headers["postmen-api-key"] = "8fc7966b-679b-4a57-911d-c5a663229c9e";
- using (StreamWriter streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
- {
- streamWriter.Write(json);
- streamWriter.Flush();
- streamWriter.Close();
- }
- HttpWebResponse httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
- using (StreamReader streamReader = new StreamReader(httpResponse.GetResponseStream()))
- {
- string result = streamReader.ReadToEnd();
- Console.WriteLine(result);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement