Zig Requires Chilkat v11.0.0+
Zig
effectconnect Read Orderlist
See more effectconnect Examples
Get a set of orders filtered by the parameters in the XML payload.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 assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const full_uri = "https://submit.effectconnect.com/orderlist";
const uri = "/orderlist";
const api_version = "2.0";
const http = try chilkat.Http.init();
defer http.deinit();
// Use your effectconnect public key here..
http.setRequestHeader("KEY", "PUBLIC_KEY");
http.setRequestHeader("VERSION", api_version);
http.setRequestHeader("URI", uri);
http.setRequestHeader("RESPONSETYPE", "XML");
http.setRequestHeader("RESPONSELANGUAGE", "en");
// Get the current date/time in timestamp format.
const dt = try chilkat.DateTime.init();
defer dt.deinit();
dt.setFromCurrentSystemTime() catch {};
const timestamp = try dt.getAsTimestamp(alloc, true);
http.setRequestHeader("TIME", timestamp);
std.debug.print("timestamp = {s}\n", .{timestamp});
// Create the following XML request body:
// <?xml version="1.0" encoding="utf-8"?>
// <list>
// <filters>
// <fromDateFilter>
// <filterValue>2018-09-14T12:12:12+01:00</filterValue>
// </fromDateFilter>
// <toDateFilter>
// <filterValue>2019-04-13T23:59:59+01:00</filterValue>
// </toDateFilter>
// <hasStatusFilter>
// <filterValue>paid</filterValue>
// </hasStatusFilter>
// <hasTagFilter>
// <filterValue>
// <tagName>Test</tagName>
// <exclude>false</exclude>
// </filterValue>
// </hasTagFilter>
// </filters>
// </list>
// Use this online tool to generate the code from sample XML:
// Generate Code to Create XML
const xml = try chilkat.Xml.init();
defer xml.deinit();
xml.setTag("list");
xml.updateChildContent("filters|fromDateFilter|filterValue", "2018-09-14T12:12:12+01:00");
xml.updateChildContent("filters|toDateFilter|filterValue", "2019-04-13T23:59:59+01:00");
xml.updateChildContent("filters|hasStatusFilter|filterValue", "paid");
xml.updateChildContent("filters|hasTagFilter|filterValue|tagName", "Test");
xml.updateChildContent("filters|hasTagFilter|filterValue|exclude", "false");
xml.setEmitCompact(true);
const sb_xml = try chilkat.StringBuilder.init();
defer sb_xml.deinit();
xml.getXmlSb(sb_xml) catch {};
// Build a string-to-sign and sign it using our effectconnect private key
const sb_string_to_sign = try chilkat.StringBuilder.init();
defer sb_string_to_sign.deinit();
sb_string_to_sign.appendInt(sb_xml.getLength()) catch {};
sb_string_to_sign.append("POST") catch {};
sb_string_to_sign.append(uri) catch {};
sb_string_to_sign.append(api_version) catch {};
sb_string_to_sign.append(timestamp) catch {};
const crypt = try chilkat.Crypt2.init();
defer crypt.deinit();
crypt.setMacAlgorithm("hmac");
crypt.setHashAlgorithm("sha512");
crypt.setEncodingMode("base64");
// Use your effectconnect private key here:
crypt.setMacKeyString("PRIVATE_KEY") catch {};
http.setRequestHeader("SIGNATURE", try crypt.macStringENC(alloc, try sb_string_to_sign.getAsString(alloc)));
// Send the POST..
const resp = try chilkat.HttpResponse.init();
defer resp.deinit();
http.httpStr("POST", full_uri, try xml.getXml(alloc), "utf-8", "application/xml", resp) catch {
std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
return;
};
std.debug.print("response status code = {d}\n", .{resp.getStatusCode()});
// Examine the response. The response status code can be 200 for both errors and success.
// The success or error is based on the XML returned in the response body.
const xml_resp = try chilkat.Xml.init();
defer xml_resp.deinit();
xml_resp.loadXml(try resp.getBodyStr(alloc)) catch {};
std.debug.print("response body:\n", .{});
std.debug.print("{s}\n", .{try xml_resp.getXml(alloc)});
// Remove previously set headers (unless we want the same headers for the next request,
// in which case we may remove or update individual headers by calling SetRequestHeader.
http.clearHeaders();
}