Sample code for 30+ languages & platforms
Zig

WIN Air Freight - Send New Pouch Request

See more HTTP Misc Examples

Sends a "POST /api/v1/Awb" to send a new pouch request.

Chilkat Zig Downloads

Zig
const std = @import("std");
const chilkat = @import("chilkat");

pub fn main(init: std.process.Init) !void {
    const alloc = init.arena.allocator();

    // This example assumes the Chilkat HTTP API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    const http = try chilkat.Http.init();
    defer http.deinit();

    // Set the "Accept" header to tell the web server that we'll accept an XML response.
    http.setAccept("application/xml");

    // Tell Chilkat to cache any received cookies to files in a particular directory
    http.setCookieDir("c:/qa_data/cookies");
    http.setSaveCookies(true);

    // Also tell Chilkat to load and send matching cookies from the CookieDir.
    // The authToken cookie is first obtained in the login request. Each subsequent
    // request sends the authToken cookie and saves the new authToken cookie to the CookieDir.
    http.setSendCookies(true);

    // Build out XML pouch request...
    const xml = try chilkat.Xml.init();
    defer xml.deinit();
    xml.setTag("PouchDTO");
    xml.updateChildContent("Mawb|AwbID", "");
    xml.updateChildContent("Mawb|AwbNumber", "001-12312123");
    xml.updateChildContent("Mawb|AwbStatus", "D");
    xml.updateChildContent("Mawb|eAWB", "false");
    xml.updateChildContent("Mawb|WithPaper", "false");
    xml.updateChildContent("Mawb|Parties|Shipper|WinID", "444444");
    xml.updateChildContent("Mawb|Parties|Shipper|AccountNumber", "12345");
    xml.updateChildContent("Mawb|Parties|Shipper|Name", "AABC SHIPPING & PACKAGING, INC.");
    xml.updateChildContent("Mawb|Parties|Shipper|Phone", "111-222-3334");
    xml.updateChildContent("Mawb|Parties|Shipper|Fax", "222-111-3334");
    xml.updateChildContent("Mawb|Parties|Shipper|Email", "");
    xml.updateChildContent("Mawb|Parties|Shipper|Address|Line1", "500 HARBOR DRIVE");
    xml.updateChildContent("Mawb|Parties|Shipper|Address|Line2", "SUITE B1211");
    xml.updateChildContent("Mawb|Parties|Shipper|Address|Place", "BEAUFORT");
    xml.updateChildContent("Mawb|Parties|Shipper|Address|PostalCode", "28516");
    xml.updateChildContent("Mawb|Parties|Shipper|Address|StateProvince", "NC");
    xml.updateChildContent("Mawb|Parties|Shipper|Address|Country|Code", "US");
    xml.updateChildContent("Mawb|Parties|Shipper|Address|Country|Name", "U.S.A.");
    xml.updateChildContent("Mawb|Parties|Consignee|WinID", "0");
    xml.updateChildContent("Mawb|Parties|Consignee|AccountNumber", "");
    xml.updateChildContent("Mawb|Parties|Consignee|Name", "DELTA MANUFACTURING");
    xml.updateChildContent("Mawb|Parties|Consignee|Phone", "444-555-3333");
    xml.updateChildContent("Mawb|Parties|Consignee|Fax", "");
    xml.updateChildContent("Mawb|Parties|Consignee|Email", "");
    xml.updateChildContent("Mawb|Parties|Consignee|Address|Line1", "185 RUE LAMANDE");
    xml.updateChildContent("Mawb|Parties|Consignee|Address|Line2", "");
    xml.updateChildContent("Mawb|Parties|Consignee|Address|Place", "PARIS");
    xml.updateChildContent("Mawb|Parties|Consignee|Address|PostalCode", "75017");
    xml.updateChildContent("Mawb|Parties|Consignee|Address|StateProvince", "");
    xml.updateChildContent("Mawb|Parties|Consignee|Address|Country|Code", "FR");
    xml.updateChildContent("Mawb|Parties|Consignee|Address|Country|Name", "FRANCE");
    xml.updateChildContent("Mawb|Parties|Notify|WinID", "");
    xml.updateChildContent("Mawb|Parties|Notify|AccountNumber", "");
    xml.updateChildContent("Mawb|Parties|Notify|Name", "AABC SHIPPING, INC.");
    xml.updateChildContent("Mawb|Parties|Notify|Phone", "");
    xml.updateChildContent("Mawb|Parties|Notify|Fax", "");
    xml.updateChildContent("Mawb|Parties|Notify|Email", "");
    xml.updateChildContent("Mawb|Parties|Notify|Address|Line1", "110 FARA WAY");
    xml.updateChildContent("Mawb|Parties|Notify|Address|Line2", "");
    xml.updateChildContent("Mawb|Parties|Notify|Address|Place", "OZ");
    xml.updateChildContent("Mawb|Parties|Notify|Address|PostalCode", "11222");
    xml.updateChildContent("Mawb|Parties|Notify|Address|StateProvince", "NY");
    xml.updateChildContent("Mawb|Parties|Notify|Address|Country|Code", "US");
    xml.updateChildContent("Mawb|Parties|Notify|Address|Country|Name", "U.S.A.");
    xml.updateChildContent("Mawb|Parties|Agent|WinID", "");
    xml.updateChildContent("Mawb|Parties|Agent|AccountNumber", "FACCT#1234");
    xml.updateChildContent("Mawb|Accounting|Identifier", "GEN");
    xml.updateChildContent("Mawb|Accounting|Information", "SARFWER");
    xml.updateChildContent("Mawb|Accounting|Identifier", "MCO");
    xml.updateChildContent("Mawb|Accounting|Information", "WERWERWER");
    xml.updateChildContent("Mawb|ShipmentReference|ReferenceNumber", "ZDFASF");
    xml.updateChildContent("Mawb|ShipmentReference|AdditionalInformation", "ZDFASF");
    xml.updateChildContent("Mawb|RoutingDetails|FromAirportCode", "EWN");
    xml.updateChildContent("Mawb|RoutingDetails|ToAirportCode", "LON");
    xml.updateChildContent("Mawb|RoutingDetails|CarrierCode", "AA");
    xml.updateChildContent("Mawb|RoutingDetails|FlightNumber", "N123");
    xml.updateChildContent("Mawb|RoutingDetails|FlightDate", "2016-11-30T00:00:00");
    xml.updateChildContent("Mawb|ChargesDeclaration|CurrencyCode", "USD");
    xml.updateChildContent("Mawb|ChargesDeclaration|ChargeCode", "PP");
    xml.updateChildContent("Mawb|ChargesDeclaration|WeightOrValuation", "P");
    xml.updateChildContent("Mawb|ChargesDeclaration|Other", "P");
    xml.updateChildContent("Mawb|ChargesDeclaration|ValuesForCarriage", "1300.00");
    xml.updateChildContent("Mawb|ChargesDeclaration|ValuesForCustoms", "12000.00");
    xml.updateChildContent("Mawb|ChargesDeclaration|ValuesForInsurance", "11000.00");
    xml.updateChildContent("Mawb|Handling|SpecialServiceInformation", "Please Notify Consigneetestwwwww");
    xml.updateChildContent("Mawb|Handling|OtherServiceInformation", "");
    xml.updateChildContent("Mawb|Handling|SCI", "");
    xml.updateChildContent("Mawb|Handling|SpecialHandling|Code", "AOG");
    xml.updateChildContent("Mawb|Handling|SpecialHandling|Code", "ATT");
    xml.updateChildContent("Mawb|Rates|NumberOfPieces", "12");
    xml.updateChildContent("Mawb|Rates|GrossWeight|Value", "244.70");
    xml.updateChildContent("Mawb|Rates|GrossWeight|UOM", "L");
    xml.updateChildContent("Mawb|Rates|SLAC", "12");
    xml.updateChildContent("Mawb|Rates|RateClassCode", "N");
    xml.updateChildContent("Mawb|Rates|CommodityItemNumber", "");
    xml.updateChildContent("Mawb|Rates|ChargeableWeight", "245.0");
    xml.updateChildContent("Mawb|Rates|RateOrCharge", "8.00");
    xml.updateChildContent("Mawb|Rates|ChargeAmount", "1960.00");
    xml.updateChildContent("Mawb|Rates|NatureAndQuantityOfGoods", "CONSOLIDATION PER ATTACHED MANIFEST.");
    xml.updateChildContent("Mawb|Rates|Dims|Pcs", "12");
    xml.updateChildContent("Mawb|Rates|Dims|Length", "4");
    xml.updateChildContent("Mawb|Rates|Dims|Width", "8");
    xml.updateChildContent("Mawb|Rates|Dims|Height", "4");
    xml.updateChildContent("Mawb|Rates|Dims|UOM", "CMT");
    xml.updateChildContent("Mawb|ChargesSummary|WeightCharge", "1960.00");
    xml.updateChildContent("Mawb|OtherCharges|Description", "AW");
    xml.updateChildContent("Mawb|OtherCharges|Amount", "123.00");
    xml.updateChildContent("Mawb|OtherCharges|ChargeIdentifier", "C");
    xml.updateChildContent("Mawb|OtherCharges|PrepaidCollect", "C");
    xml.updateChildContent("Mawb|OtherCharges|Description", "FC");
    xml.updateChildContent("Mawb|OtherCharges|Amount", "55.00");
    xml.updateChildContent("Mawb|OtherCharges|ChargeIdentifier", "A");
    xml.updateChildContent("Mawb|OtherCharges|PrepaidCollect", "P");
    xml.updateChildContent("Mawb|OtherCharges|Description", "FC");
    xml.updateChildContent("Mawb|OtherCharges|Amount", "101.00");
    xml.updateChildContent("Mawb|OtherCharges|ChargeIdentifier", "C");
    xml.updateChildContent("Mawb|OtherCharges|PrepaidCollect", "C");
    xml.updateChildContent("Mawb|EmailNotifications|Name", "");
    xml.updateChildContent("Mawb|EmailNotifications|Email", "");
    xml.updateChildContent("Mawb|EmailNotifications|Name", "");
    xml.updateChildContent("Mawb|EmailNotifications|Email", "");
    xml.updateChildContent("Mawb|EmailNotifications|Name", "");
    xml.updateChildContent("Mawb|EmailNotifications|Email", "");
    xml.updateChildContent("Mawb|EmailNotifications|Name", "");
    xml.updateChildContent("Mawb|EmailNotifications|Email", "");
    xml.updateChildContent("Mawb|Execution|Date", "2015-08-07T00:00:00");
    xml.updateChildContent("Mawb|Execution|Place", "OZ NY");
    xml.updateChildContent("Mawb|Execution|ShipperSignature", "OAS FREIGHT FORWARDE");
    xml.updateChildContent("Mawb|Execution|CarrierSignature", "OAS FREIGHT FORWARDE");
    xml.updateChildContent("Hawbs|AwbNumber", "001-12312123");
    xml.updateChildContent("Hawbs|HawbNumber", "CGL201107-27");
    xml.updateChildContent("Hawbs|HawbStatus", "D");
    xml.updateChildContent("Hawbs|NumberOfPieces", "12");
    xml.updateChildContent("Hawbs|GrossWeight|Value", "244.70");
    xml.updateChildContent("Hawbs|GrossWeight|UOM", "K");
    xml.updateChildContent("Hawbs|Locations|PortOfOrigin|Code", "EWN");
    xml.updateChildContent("Hawbs|Locations|PortOfDestination|Code", "LON");
    xml.updateChildContent("Hawbs|Commodity", "HWB #: CGL20110");
    xml.updateChildContent("Hawbs|SLAC", "12");
    xml.updateChildContent("Hawbs|Parties|Shipper|Name", "ABC SHIPPNG AGAIN");
    xml.updateChildContent("Hawbs|Parties|Shipper|Phone", "111-222-3333");
    xml.updateChildContent("Hawbs|Parties|Shipper|Fax", "");
    xml.updateChildContent("Hawbs|Parties|Shipper|Email", "");
    xml.updateChildContent("Hawbs|Parties|Shipper|Address|Line1", "100 MAIN STREET");
    xml.updateChildContent("Hawbs|Parties|Shipper|Address|Place", "OZ");
    xml.updateChildContent("Hawbs|Parties|Shipper|Address|PostalCode", "ZIP");
    xml.updateChildContent("Hawbs|Parties|Shipper|Address|StateProvince", "NY");
    xml.updateChildContent("Hawbs|Parties|Shipper|Address|Country|Code", "US");
    xml.updateChildContent("Hawbs|Parties|Consignee|Name", "AABC SHIPPING & PACKAGING, INC.");
    xml.updateChildContent("Hawbs|Parties|Consignee|Phone", "111-222-3334");
    xml.updateChildContent("Hawbs|Parties|Consignee|Fax", "222-111-3334");
    xml.updateChildContent("Hawbs|Parties|Consignee|Email", "");
    xml.updateChildContent("Hawbs|Parties|Consignee|Address|Line1", "500 HARBOR DRIVE");
    xml.updateChildContent("Hawbs|Parties|Consignee|Address|Place", "BEAUFORT");
    xml.updateChildContent("Hawbs|Parties|Consignee|Address|PostalCode", "28516");
    xml.updateChildContent("Hawbs|Parties|Consignee|Address|StateProvince", "NC");
    xml.updateChildContent("Hawbs|Parties|Consignee|Address|Country|Code", "US");
    xml.setEmitXmlDecl(false);

    const http_request_body = try xml.getXml(alloc);
    const resp = try chilkat.HttpResponse.init();
    defer resp.deinit();
    http.httpStr("POST", "http://integration.winwebconnect.com/api/v1/Awb", http_request_body, "utf-8", "application/xml", resp) catch {
        std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
        return;
    };

    const xml_response = try chilkat.Xml.init();
    defer xml_response.deinit();
    xml_response.loadXml(try resp.getBodyStr(alloc)) catch {};

    // See below for an example XML response body.
    std.debug.print("Response Body:\n", .{});
    std.debug.print("{s}\n", .{try xml_response.getXml(alloc)});
    std.debug.print("---\n", .{});

    std.debug.print("Response Header:\n", .{});
    std.debug.print("{s}\n", .{try resp.getHeader(alloc)});
    std.debug.print("Success.\n", .{});
}