Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Unicode C) effectconnect Read OrderlistGet a set of orders filtered by the parameters in the XML payload.
#include <C_CkHttpW.h> #include <C_CkDateTimeW.h> #include <C_CkXmlW.h> #include <C_CkStringBuilderW.h> #include <C_CkCrypt2W.h> #include <C_CkHttpResponseW.h> void ChilkatSample(void) { BOOL success; const wchar_t *fullUri; const wchar_t *uri; const wchar_t *apiVersion; HCkHttpW http; HCkDateTimeW dt; const wchar_t *timestamp; HCkXmlW xml; HCkStringBuilderW sbXml; HCkStringBuilderW sbStringToSign; HCkCrypt2W crypt; HCkHttpResponseW resp; HCkXmlW xmlResp; // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. fullUri = L"https://submit.effectconnect.com/orderlist"; uri = L"/orderlist"; apiVersion = L"2.0"; http = CkHttpW_Create(); // Use your effectconnect public key here.. CkHttpW_SetRequestHeader(http,L"KEY",L"PUBLIC_KEY"); CkHttpW_SetRequestHeader(http,L"VERSION",apiVersion); CkHttpW_SetRequestHeader(http,L"URI",uri); CkHttpW_SetRequestHeader(http,L"RESPONSETYPE",L"XML"); CkHttpW_SetRequestHeader(http,L"RESPONSELANGUAGE",L"en"); // Get the current date/time in timestamp format. dt = CkDateTimeW_Create(); CkDateTimeW_SetFromCurrentSystemTime(dt); timestamp = CkDateTimeW_getAsTimestamp(dt,TRUE); CkHttpW_SetRequestHeader(http,L"TIME",timestamp); wprintf(L"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 xml = CkXmlW_Create(); CkXmlW_putTag(xml,L"list"); CkXmlW_UpdateChildContent(xml,L"filters|fromDateFilter|filterValue",L"2018-09-14T12:12:12+01:00"); CkXmlW_UpdateChildContent(xml,L"filters|toDateFilter|filterValue",L"2019-04-13T23:59:59+01:00"); CkXmlW_UpdateChildContent(xml,L"filters|hasStatusFilter|filterValue",L"paid"); CkXmlW_UpdateChildContent(xml,L"filters|hasTagFilter|filterValue|tagName",L"Test"); CkXmlW_UpdateChildContent(xml,L"filters|hasTagFilter|filterValue|exclude",L"false"); CkXmlW_putEmitCompact(xml,TRUE); sbXml = CkStringBuilderW_Create(); CkXmlW_GetXmlSb(xml,sbXml); // Build a string-to-sign and sign it using our effectconnect private key sbStringToSign = CkStringBuilderW_Create(); CkStringBuilderW_AppendInt(sbStringToSign,CkStringBuilderW_getLength(sbXml)); CkStringBuilderW_Append(sbStringToSign,L"POST"); CkStringBuilderW_Append(sbStringToSign,uri); CkStringBuilderW_Append(sbStringToSign,apiVersion); CkStringBuilderW_Append(sbStringToSign,timestamp); crypt = CkCrypt2W_Create(); CkCrypt2W_putMacAlgorithm(crypt,L"hmac"); CkCrypt2W_putHashAlgorithm(crypt,L"sha512"); CkCrypt2W_putEncodingMode(crypt,L"base64"); // Use your effectconnect private key here: CkCrypt2W_SetMacKeyString(crypt,L"PRIVATE_KEY"); CkHttpW_SetRequestHeader(http,L"SIGNATURE",CkCrypt2W_macStringENC(crypt,CkStringBuilderW_getAsString(sbStringToSign))); // Send the POST.. resp = CkHttpW_PostXml(http,fullUri,CkXmlW_getXml(xml),L"utf-8"); if (CkHttpW_getLastMethodSuccess(http) == FALSE) { wprintf(L"%s\n",CkHttpW_lastErrorText(http)); CkHttpW_Dispose(http); CkDateTimeW_Dispose(dt); CkXmlW_Dispose(xml); CkStringBuilderW_Dispose(sbXml); CkStringBuilderW_Dispose(sbStringToSign); CkCrypt2W_Dispose(crypt); return; } wprintf(L"response status code = %d\n",CkHttpResponseW_getStatusCode(resp)); // 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. xmlResp = CkXmlW_Create(); CkXmlW_LoadXml(xmlResp,CkHttpResponseW_bodyStr(resp)); CkHttpResponseW_Dispose(resp); wprintf(L"response body:\n"); wprintf(L"%s\n",CkXmlW_getXml(xmlResp)); // 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. CkHttpW_ClearHeaders(http); CkHttpW_Dispose(http); CkDateTimeW_Dispose(dt); CkXmlW_Dispose(xml); CkStringBuilderW_Dispose(sbXml); CkStringBuilderW_Dispose(sbStringToSign); CkCrypt2W_Dispose(crypt); CkXmlW_Dispose(xmlResp); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.