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
(Delphi DLL) effectconnect Read OrderlistGet a set of orders filtered by the parameters in the XML payload.
uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Http, CkDateTime, HttpResponse, StringBuilder, Xml, Crypt2; ... procedure TForm1.Button1Click(Sender: TObject); var success: Boolean; fullUri: PWideChar; uri: PWideChar; apiVersion: PWideChar; http: HCkHttp; dt: HCkDateTime; timestamp: PWideChar; xml: HCkXml; sbXml: HCkStringBuilder; sbStringToSign: HCkStringBuilder; crypt: HCkCrypt2; resp: HCkHttpResponse; xmlResp: HCkXml; begin // 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); Memo1.Lines.Add('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 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) then begin Memo1.Lines.Add(CkHttp__lastErrorText(http)); Exit; end; Memo1.Lines.Add('response status code = ' + IntToStr(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); Memo1.Lines.Add('response body:'); Memo1.Lines.Add(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); end; |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.