Lua Requires Chilkat v11.0.0+
Lua
effectconnect Read Orderlist
See more effectconnect Examples
Get a set of orders filtered by the parameters in the XML payload.Chilkat Lua Downloads
local chilkat = require("chilkat")
-- This example assumes the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
local fullUri = "https://submit.effectconnect.com/orderlist"
local uri = "/orderlist"
local apiVersion = "2.0"
local http = chilkat.Http.new()
-- Use your effectconnect public key here..
http:set_request_header("KEY", "PUBLIC_KEY")
http:set_request_header("VERSION", apiVersion)
http:set_request_header("URI", uri)
http:set_request_header("RESPONSETYPE", "XML")
http:set_request_header("RESPONSELANGUAGE", "en")
-- Get the current date/time in timestamp format.
local dt = chilkat.DateTime.new()
dt:set_from_current_system_time()
local timestamp = dt:get_as_timestamp(true)
http:set_request_header("TIME", timestamp)
print("timestamp = " .. 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
local xml = chilkat.Xml.new()
xml.tag = "list"
xml:update_child_content("filters|fromDateFilter|filterValue", "2018-09-14T12:12:12+01:00")
xml:update_child_content("filters|toDateFilter|filterValue", "2019-04-13T23:59:59+01:00")
xml:update_child_content("filters|hasStatusFilter|filterValue", "paid")
xml:update_child_content("filters|hasTagFilter|filterValue|tagName", "Test")
xml:update_child_content("filters|hasTagFilter|filterValue|exclude", "false")
xml.emit_compact = true
local sbXml = chilkat.StringBuilder.new()
xml:get_xml_sb(sbXml)
-- Build a string-to-sign and sign it using our effectconnect private key
local sbStringToSign = chilkat.StringBuilder.new()
sbStringToSign:append_int(sbXml.length)
sbStringToSign:append("POST")
sbStringToSign:append(uri)
sbStringToSign:append(apiVersion)
sbStringToSign:append(timestamp)
local crypt = chilkat.Crypt2.new()
crypt.mac_algorithm = "hmac"
crypt.hash_algorithm = "sha512"
crypt.encoding_mode = "base64"
-- Use your effectconnect private key here:
crypt:set_mac_key_string("PRIVATE_KEY")
http:set_request_header("SIGNATURE", crypt:mac_string_enc(sbStringToSign:get_as_string()))
-- Send the POST..
local resp = chilkat.HttpResponse.new()
local success = http:http_str("POST", fullUri, xml:get_xml(), "utf-8", "application/xml", resp)
if not success then
print(http.last_error_text)
return
end
print("response status code = " .. resp.status_code)
-- 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.
local xmlResp = chilkat.Xml.new()
xmlResp:load_xml(resp.body_str)
print("response body:")
print(xmlResp:get_xml())
-- 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:clear_headers()