Zig Requires Chilkat v11.0.0+
Zig
Peoplevox WMS Authentication
See more HTTP Examples
Provides an example of a call to the Peoplevox WMS Authenticate using SOAP 1.1.Chilkat Zig Downloads
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/Authenticate
// Content-Length: (automatically computed and added by Chilkat)
// Host: qac.peoplevox.net
//
// <?xml version="1.0" encoding="utf-8"?>
// <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:peop="http://www.peoplevox.net/">
// <soapenv:Header/>
// <soapenv:Body>
// <peop:Authenticate>
// <peop:clientId>PEOPLEVOX_CLIENT_ID</peop:clientId>
// <peop:username>PEOPLEVOX_USERNAME</peop:username>
// <peop:password>PEOPLEVOX_BASE64_PASSWORD</peop:password>
// </peop:Authenticate>
// </soapenv:Body>
// </soapenv:Envelope>
//
const sb_soap_xml = try chilkat.StringBuilder.init();
defer sb_soap_xml.deinit();
sb_soap_xml.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>") catch {};
sb_soap_xml.append("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:peop=\"http://www.peoplevox.net/\">") catch {};
sb_soap_xml.append(" <soapenv:Header/>") catch {};
sb_soap_xml.append(" <soapenv:Body>") catch {};
sb_soap_xml.append(" <peop:Authenticate>") catch {};
sb_soap_xml.append(" <peop:clientId>PEOPLEVOX_CLIENT_ID</peop:clientId>") catch {};
sb_soap_xml.append(" <peop:username>PEOPLEVOX_USERNAME</peop:username>") catch {};
sb_soap_xml.append(" <peop:password>PEOPLEVOX_BASE64_PASSWORD</peop:password>") catch {};
sb_soap_xml.append(" </peop:Authenticate>") catch {};
sb_soap_xml.append(" </soapenv:Body>") catch {};
sb_soap_xml.append("</soapenv:Envelope>") catch {};
// Base64 encode the password and update the SOAP XML.
const crypt = try chilkat.Crypt2.init();
defer crypt.deinit();
const password_base64 = try crypt.encodeString(alloc, "PEOPLEVOX_PASSWORD", "utf-8", "base64");
_ = sb_soap_xml.replace("PEOPLEVOX_BASE64_PASSWORD", password_base64);
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/Authenticate");
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)});
return;
}
// A successful response returns this XML:
// <?xml version="1.0" encoding="utf-8" ?>
// <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
// <soap:Body>
// <AuthenticateResponse xmlns="http://www.peoplevox.net/">
// <AuthenticateResult>
// <ResponseId>0</ResponseId>
// <TotalCount>1</TotalCount>
// <Detail>PEOPLEVOX_CLIENT_ID,7fe13431-c67f-4d52-bcfd-b60fbfa3b0ca</Detail>
// <Statuses />
// <ImportingQueueId>0</ImportingQueueId>
// <SalesOrdersToDespatchIds />
// </AuthenticateResult>
// </AuthenticateResponse>
// </soap:Body>
// </soap:Envelope>
//
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)});
// Show how to get the Detail, which must be the ClientId,SessionId
const detail = try xml_response.chilkatPath(alloc, "soap:Body|AuthenticateResponse|AuthenticateResult|Detail|*");
std.debug.print("Detail = {s}\n", .{detail});
}