Sample code for 30+ languages & platforms
Zig Requires Chilkat v11.0.0+

Peoplevox GetReportData

See more Peoplevox Examples

Demonstrates how to export data from a Peoplevox Warehouse Management System (WMS) using a system report template.

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 requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    // Sends a POST that looks like this:

    //     POST /PEOPLEVOX_CLIENT_ID/resources/integrationservicev4.asmx HTTP/1.1
    //     Content-Type: text/xml;charset=UTF-8
    //     SOAPAction: http://www.peoplevox.net/GetReportData
    //     Content-Length: (automatically computed and added by Chilkat)
    //     Host: qac.peoplevox.net
    //
    //     <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:peop="http://www.peoplevox.net/">
    //        <soap:Header>
    //           <peop:UserSessionCredentials>
    //              <peop:UserId>PEOPLEVOX_USER_ID</peop:UserId>
    //              <peop:ClientId>PEOPLEVOX_CLIENT_ID</peop:ClientId>
    //              <peop:SessionId>PEOPLEVOX_SESSION_ID</peop:SessionId>
    //           </peop:UserSessionCredentials>
    //        </soap:Header>
    //         <soap:Body>
    //           <peop:GetReportData>
    //              <peop:getReportRequest>
    //                 <peop:TemplateName>Item movement history</peop:TemplateName>
    //                 <peop:PageNo>1</peop:PageNo>
    //                 <peop:ItemsPerPage>20</peop:ItemsPerPage>
    //                 <peop:OrderBy>[Date timestamp]</peop:OrderBy>
    //                 <peop:Columns>[Item code],[Date timestamp],[From],[To],[Quantity],[Comments]</peop:Columns>
    //                 <peop:SearchClause>([Date timestamp] > DateTime(2016,01,01,09,00,00))</peop:SearchClause>
    //              </peop:getReportRequest>
    //           </peop:GetReportData>
    //        </soap:Body>
    //     </soap:Envelope>
    //

    // Notice that a UserId is needed here.  This is different than the username required for Peoplevox authentication.
    //    The UserId for the admin account is 1.
    //
    const sb_soap_xml = try chilkat.StringBuilder.init();
    defer sb_soap_xml.deinit();
    sb_soap_xml.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n") catch {};
    sb_soap_xml.append("<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:peop=\"http://www.peoplevox.net/\">\r\n") catch {};
    sb_soap_xml.append("   <soap:Header>\r\n") catch {};
    sb_soap_xml.append("      <peop:UserSessionCredentials>\r\n") catch {};
    sb_soap_xml.append("         <peop:UserId>PEOPLEVOX_USER_ID</peop:UserId>\r\n") catch {};
    sb_soap_xml.append("         <peop:ClientId>PEOPLEVOX_CLIENT_ID</peop:ClientId>\r\n") catch {};
    sb_soap_xml.append("         <peop:SessionId>PEOPLEVOX_SESSION_ID</peop:SessionId>\r\n") catch {};
    sb_soap_xml.append("      </peop:UserSessionCredentials>\r\n") catch {};
    sb_soap_xml.append("   </soap:Header>\r\n") catch {};
    sb_soap_xml.append("   <soap:Body>\r\n") catch {};
    sb_soap_xml.append("      <peop:GetReportData>\r\n") catch {};
    sb_soap_xml.append("         <peop:getReportRequest>\r\n") catch {};
    sb_soap_xml.append("            <peop:TemplateName>Item movement history</peop:TemplateName>\r\n") catch {};
    sb_soap_xml.append("            <peop:PageNo>1</peop:PageNo>\r\n") catch {};
    sb_soap_xml.append("            <peop:ItemsPerPage>20</peop:ItemsPerPage>\r\n") catch {};
    sb_soap_xml.append("            <peop:OrderBy>[Date timestamp]</peop:OrderBy>\r\n") catch {};
    sb_soap_xml.append("            <peop:Columns>[Item code],[Date timestamp],[From],[To],[Quantity],[Comments]</peop:Columns>\r\n") catch {};
    sb_soap_xml.append("            <peop:SearchClause>([Date timestamp] > DateTime(2016,01,01,09,00,00))</peop:SearchClause>\r\n") catch {};
    sb_soap_xml.append("         </peop:getReportRequest>\r\n") catch {};
    sb_soap_xml.append("      </peop:GetReportData>\r\n") catch {};
    sb_soap_xml.append("   </soap:Body>\r\n") catch {};
    sb_soap_xml.append("</soap:Envelope>") catch {};

    const req = try chilkat.HttpRequest.init();
    defer req.deinit();
    req.setHttpVerb("POST");
    req.setSendCharset(true);
    req.setCharset("utf-8");
    req.addHeader("Content-Type", "text/xml");
    req.addHeader("SOAPAction", "http://www.peoplevox.net/GetReportData");
    req.setPath("/PEOPLEVOX_CLIENT_ID/resources/integrationservicev4.asmx");
    try req.loadBodyFromString(try sb_soap_xml.getAsString(alloc), "utf-8");

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

    const resp = try chilkat.HttpResponse.init();
    defer resp.deinit();
    http.httpSReq("qac.peoplevox.net", 443, true, req, resp) catch {
        std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
        return;
    };

    // We should expect a 200 response if successful.
    if (resp.getStatusCode() != 200) {
        std.debug.print("Response StatusCode = {d}\n", .{resp.getStatusCode()});
        std.debug.print("Response StatusLine: {s}\n", .{try resp.getStatusLine(alloc)});
        std.debug.print("Response Header:\n", .{});
        std.debug.print("{s}\n", .{try resp.getHeader(alloc)});
        std.debug.print("{s}\n", .{try resp.getBodyStr(alloc)});
        return;
    }

    const xml_response = try chilkat.Xml.init();
    defer xml_response.deinit();
    try xml_response.loadXml(try resp.getBodyStr(alloc));
    std.debug.print("{s}\n", .{try xml_response.getXml(alloc)});

    const detail = try xml_response.chilkatPath(alloc, "soap:Body|GetReportDataResponse|GetReportDataResult|Detail|*");

    const csv = try chilkat.Csv.init();
    defer csv.deinit();
    csv.setHasColumnNames(true);
    csv.loadFromString(detail) catch {};

    std.debug.print("NumRows = {d}\n", .{csv.getNumRows()});
    std.debug.print("NumColumns = {d}\n", .{csv.getNumColumns()});

    // Iterate over the rows, getting the ItemCode, Name, and Barcode
    var i: i32 = 0;
    const num_rows = csv.getNumRows();
    while (i < num_rows) {
        std.debug.print("Item code: {s}\n", .{try csv.getCellByName(alloc, i, "Item code")});
        std.debug.print("Date timestamp: {s}\n", .{try csv.getCellByName(alloc, i, "Date timestamp")});
        std.debug.print("From: {s}\n", .{try csv.getCellByName(alloc, i, "From")});
        std.debug.print("To: {s}\n", .{try csv.getCellByName(alloc, i, "To")});
        std.debug.print("Quantity: {s}\n", .{try csv.getCellByName(alloc, i, "Quantity")});
        std.debug.print("Comments: {s}\n", .{try csv.getCellByName(alloc, i, "Comments")});
        std.debug.print("-\n", .{});
        i = i + 1;
    }
}