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
(C) effectconnect Read OrderlistGet a set of orders filtered by the parameters in the XML payload.
#include <C_CkHttp.h> #include <C_CkDateTime.h> #include <C_CkXml.h> #include <C_CkStringBuilder.h> #include <C_CkCrypt2.h> #include <C_CkHttpResponse.h> void ChilkatSample(void) { BOOL success; const char *fullUri; const char *uri; const char *apiVersion; HCkHttp http; HCkDateTime dt; const char *timestamp; HCkXml xml; HCkStringBuilder sbXml; HCkStringBuilder sbStringToSign; HCkCrypt2 crypt; HCkHttpResponse resp; HCkXml xmlResp; // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. fullUri = "https://submit.effectconnect.com/orderlist"; uri = "/orderlist"; apiVersion = "2.0"; http = CkHttp_Create(); // Use your effectconnect public key here.. CkHttp_SetRequestHeader(http,"KEY","PUBLIC_KEY"); CkHttp_SetRequestHeader(http,"VERSION",apiVersion); CkHttp_SetRequestHeader(http,"URI",uri); CkHttp_SetRequestHeader(http,"RESPONSETYPE","XML"); CkHttp_SetRequestHeader(http,"RESPONSELANGUAGE","en"); // Get the current date/time in timestamp format. dt = CkDateTime_Create(); CkDateTime_SetFromCurrentSystemTime(dt); timestamp = CkDateTime_getAsTimestamp(dt,TRUE); CkHttp_SetRequestHeader(http,"TIME",timestamp); printf("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 = CkXml_Create(); CkXml_putTag(xml,"list"); CkXml_UpdateChildContent(xml,"filters|fromDateFilter|filterValue","2018-09-14T12:12:12+01:00"); CkXml_UpdateChildContent(xml,"filters|toDateFilter|filterValue","2019-04-13T23:59:59+01:00"); CkXml_UpdateChildContent(xml,"filters|hasStatusFilter|filterValue","paid"); CkXml_UpdateChildContent(xml,"filters|hasTagFilter|filterValue|tagName","Test"); CkXml_UpdateChildContent(xml,"filters|hasTagFilter|filterValue|exclude","false"); CkXml_putEmitCompact(xml,TRUE); sbXml = CkStringBuilder_Create(); CkXml_GetXmlSb(xml,sbXml); // Build a string-to-sign and sign it using our effectconnect private key sbStringToSign = CkStringBuilder_Create(); CkStringBuilder_AppendInt(sbStringToSign,CkStringBuilder_getLength(sbXml)); CkStringBuilder_Append(sbStringToSign,"POST"); CkStringBuilder_Append(sbStringToSign,uri); CkStringBuilder_Append(sbStringToSign,apiVersion); CkStringBuilder_Append(sbStringToSign,timestamp); crypt = CkCrypt2_Create(); CkCrypt2_putMacAlgorithm(crypt,"hmac"); CkCrypt2_putHashAlgorithm(crypt,"sha512"); CkCrypt2_putEncodingMode(crypt,"base64"); // Use your effectconnect private key here: CkCrypt2_SetMacKeyString(crypt,"PRIVATE_KEY"); CkHttp_SetRequestHeader(http,"SIGNATURE",CkCrypt2_macStringENC(crypt,CkStringBuilder_getAsString(sbStringToSign))); // Send the POST.. resp = CkHttp_PostXml(http,fullUri,CkXml_getXml(xml),"utf-8"); if (CkHttp_getLastMethodSuccess(http) == FALSE) { printf("%s\n",CkHttp_lastErrorText(http)); CkHttp_Dispose(http); CkDateTime_Dispose(dt); CkXml_Dispose(xml); CkStringBuilder_Dispose(sbXml); CkStringBuilder_Dispose(sbStringToSign); CkCrypt2_Dispose(crypt); return; } printf("response status code = %d\n",CkHttpResponse_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 = CkXml_Create(); CkXml_LoadXml(xmlResp,CkHttpResponse_bodyStr(resp)); CkHttpResponse_Dispose(resp); printf("response body:\n"); printf("%s\n",CkXml_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. CkHttp_ClearHeaders(http); CkHttp_Dispose(http); CkDateTime_Dispose(dt); CkXml_Dispose(xml); CkStringBuilder_Dispose(sbXml); CkStringBuilder_Dispose(sbStringToSign); CkCrypt2_Dispose(crypt); CkXml_Dispose(xmlResp); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.