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
(PureBasic) effectconnect Read OrderlistGet a set of orders filtered by the parameters in the XML payload.
IncludeFile "CkDateTime.pb" IncludeFile "CkHttp.pb" IncludeFile "CkXml.pb" IncludeFile "CkCrypt2.pb" IncludeFile "CkStringBuilder.pb" IncludeFile "CkHttpResponse.pb" Procedure ChilkatExample() ; This example assumes the Chilkat API to have been previously unlocked. ; See Global Unlock Sample for sample code. success.i fullUri.s = "https://submit.effectconnect.com/orderlist" uri.s = "/orderlist" apiVersion.s = "2.0" http.i = CkHttp::ckCreate() If http.i = 0 Debug "Failed to create object." ProcedureReturn EndIf ; Use your effectconnect public key here.. CkHttp::ckSetRequestHeader(http,"KEY","PUBLIC_KEY") CkHttp::ckSetRequestHeader(http,"VERSION",apiVersion) CkHttp::ckSetRequestHeader(http,"URI",uri) CkHttp::ckSetRequestHeader(http,"RESPONSETYPE","XML") CkHttp::ckSetRequestHeader(http,"RESPONSELANGUAGE","en") ; Get the current date/time in timestamp format. dt.i = CkDateTime::ckCreate() If dt.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkDateTime::ckSetFromCurrentSystemTime(dt) timestamp.s = CkDateTime::ckGetAsTimestamp(dt,1) CkHttp::ckSetRequestHeader(http,"TIME",timestamp) Debug "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.i = CkXml::ckCreate() If xml.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkXml::setCkTag(xml, "list") CkXml::ckUpdateChildContent(xml,"filters|fromDateFilter|filterValue","2018-09-14T12:12:12+01:00") CkXml::ckUpdateChildContent(xml,"filters|toDateFilter|filterValue","2019-04-13T23:59:59+01:00") CkXml::ckUpdateChildContent(xml,"filters|hasStatusFilter|filterValue","paid") CkXml::ckUpdateChildContent(xml,"filters|hasTagFilter|filterValue|tagName","Test") CkXml::ckUpdateChildContent(xml,"filters|hasTagFilter|filterValue|exclude","false") CkXml::setCkEmitCompact(xml, 1) sbXml.i = CkStringBuilder::ckCreate() If sbXml.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkXml::ckGetXmlSb(xml,sbXml) ; Build a string-to-sign and sign it using our effectconnect private key sbStringToSign.i = CkStringBuilder::ckCreate() If sbStringToSign.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkStringBuilder::ckAppendInt(sbStringToSign,CkStringBuilder::ckLength(sbXml)) CkStringBuilder::ckAppend(sbStringToSign,"POST") CkStringBuilder::ckAppend(sbStringToSign,uri) CkStringBuilder::ckAppend(sbStringToSign,apiVersion) CkStringBuilder::ckAppend(sbStringToSign,timestamp) crypt.i = CkCrypt2::ckCreate() If crypt.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkCrypt2::setCkMacAlgorithm(crypt, "hmac") CkCrypt2::setCkHashAlgorithm(crypt, "sha512") CkCrypt2::setCkEncodingMode(crypt, "base64") ; Use your effectconnect private key here: CkCrypt2::ckSetMacKeyString(crypt,"PRIVATE_KEY") CkHttp::ckSetRequestHeader(http,"SIGNATURE",CkCrypt2::ckMacStringENC(crypt,CkStringBuilder::ckGetAsString(sbStringToSign))) ; Send the POST.. resp.i = CkHttp::ckPostXml(http,fullUri,CkXml::ckGetXml(xml),"utf-8") If CkHttp::ckLastMethodSuccess(http) = 0 Debug CkHttp::ckLastErrorText(http) CkHttp::ckDispose(http) CkDateTime::ckDispose(dt) CkXml::ckDispose(xml) CkStringBuilder::ckDispose(sbXml) CkStringBuilder::ckDispose(sbStringToSign) CkCrypt2::ckDispose(crypt) ProcedureReturn EndIf Debug "response status code = " + Str(CkHttpResponse::ckStatusCode(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.i = CkXml::ckCreate() If xmlResp.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkXml::ckLoadXml(xmlResp,CkHttpResponse::ckBodyStr(resp)) CkHttpResponse::ckDispose(resp) Debug "response body:" Debug CkXml::ckGetXml(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::ckClearHeaders(http) CkHttp::ckDispose(http) CkDateTime::ckDispose(dt) CkXml::ckDispose(xml) CkStringBuilder::ckDispose(sbXml) CkStringBuilder::ckDispose(sbStringToSign) CkCrypt2::ckDispose(crypt) CkXml::ckDispose(xmlResp) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.