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

Peoplevox SaveData

See more Peoplevox Examples

Demonstrates how to call the Peoplevox SaveData SOAP method. This example adds a new carrier (DHL) to the system.

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/SaveData
    //     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:SaveData>
    //              <peop:saveRequest>
    //                 <peop:TemplateName>Carriers</peop:TemplateName>
    //                 <peop:CsvData>CSV_DATA</peop:CsvData>
    //                 <peop:Action>0</peop:Action>
    //              </peop:saveRequest>
    //           </peop:SaveData>
    //        </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:SaveData>\r\n") catch {};
    sb_soap_xml.append("         <peop:saveRequest>\r\n") catch {};
    sb_soap_xml.append("            <peop:TemplateName>Carriers</peop:TemplateName>\r\n") catch {};
    sb_soap_xml.append("            <peop:CsvData>CSV_DATA</peop:CsvData>\r\n") catch {};
    sb_soap_xml.append("            <peop:Action>0</peop:Action>\r\n") catch {};
    sb_soap_xml.append("         </peop:saveRequest>\r\n") catch {};
    sb_soap_xml.append("      </peop:SaveData>\r\n") catch {};
    sb_soap_xml.append("   </soap:Body>\r\n") catch {};
    sb_soap_xml.append("</soap:Envelope>") catch {};

    const sb_csv_data = try chilkat.StringBuilder.init();
    defer sb_csv_data.deinit();
    sb_csv_data.append("Name,Reference\r\n") catch {};
    sb_csv_data.append("DHL,D0001") catch {};
    _ = sb_soap_xml.replace("CSV_DATA", try sb_csv_data.getAsString(alloc));

    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/SaveData");
    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)});

    // A successful response is shown below.
    // To parse a successful response:
    const reference = try xml_response.chilkatPath(alloc, "soap:Body|SaveDataResponse|SaveDataResult|Statuses|IntegrationStatusResponse|Reference|*");
    std.debug.print("Reference = {s}\n", .{reference});
    const status = try xml_response.chilkatPath(alloc, "soap:Body|SaveDataResponse|SaveDataResult|Statuses|IntegrationStatusResponse|Status|*");
    std.debug.print("Status = {s}\n", .{status});

    // <?xml version="1.0" encoding="utf-8" ?>
    // <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    //     <soap:Body>
    //         <SaveDataResponse xmlns="http://www.peoplevox.net/">
    //             <SaveDataResult>
    //                 <ResponseId>0</ResponseId>
    //                 <TotalCount>1</TotalCount>
    //                 <Detail />
    //                 <Statuses>
    //                     <IntegrationStatusResponse>
    //                         <Reference>D0001</Reference>
    //                         <Status>Success</Status>
    //                         <LineNo>0</LineNo>
    //                     </IntegrationStatusResponse>
    //                 </Statuses>
    //                 <ImportingQueueId>0</ImportingQueueId>
    //                 <SalesOrdersToDespatchIds />
    //             </SaveDataResult>
    //         </SaveDataResponse>
    //     </soap:Body>
    // </soap:Envelope>
}