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 Create or Replace Product CatalogUse this call to create or replace a product catalog in EffectConnect. This is always a purge and replace action for the entire catalog.
IncludeFile "CkDateTime.pb" IncludeFile "CkHttp.pb" IncludeFile "CkXml.pb" IncludeFile "CkCrypt2.pb" IncludeFile "CkHttpRequest.pb" IncludeFile "CkHttpResponse.pb" IncludeFile "CkStringBuilder.pb" Procedure ChilkatExample() ; This example assumes the Chilkat API to have been previously unlocked. ; See Global Unlock Sample for sample code. success.i uri.s = "/products" apiVersion.s = "2.0" http.i = CkHttp::ckCreate() If http.i = 0 Debug "Failed to create object." ProcedureReturn EndIf req.i = CkHttpRequest::ckCreate() If req.i = 0 Debug "Failed to create object." ProcedureReturn EndIf ; Use your effectconnect public key here... CkHttpRequest::ckAddHeader(req,"KEY","PUBLIC_KEY") CkHttpRequest::ckAddHeader(req,"VERSION",apiVersion) CkHttpRequest::ckAddHeader(req,"URI",uri) CkHttpRequest::ckAddHeader(req,"RESPONSETYPE","XML") CkHttpRequest::ckAddHeader(req,"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) CkHttpRequest::ckAddHeader(req,"TIME",timestamp) Debug "timestamp = " + timestamp sbXml.i = CkStringBuilder::ckCreate() If sbXml.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success = CkStringBuilder::ckLoadFile(sbXml,"qa_data/xml/effectconnect/effconCreate.xml","utf-8") Debug "length = " + Str(CkStringBuilder::ckLength(sbXml)) CkHttpRequest::setCkHttpVerb(req, "POST") CkHttpRequest::setCkPath(req, uri) CkHttpRequest::setCkContentType(req, "multipart/form-data") success = CkHttpRequest::ckAddStringForUpload(req,"payload","effcon.xml",CkStringBuilder::ckGetAsString(sbXml),"utf-8") If success = 0 Debug CkHttpRequest::ckLastErrorText(req) CkHttp::ckDispose(http) CkHttpRequest::ckDispose(req) CkDateTime::ckDispose(dt) CkStringBuilder::ckDispose(sbXml) ProcedureReturn EndIf ; 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") CkHttpRequest::ckAddHeader(req,"SIGNATURE",CkCrypt2::ckMacStringENC(crypt,CkStringBuilder::ckGetAsString(sbStringToSign))) resp.i = CkHttp::ckSynchronousRequest(http,"submit.effectconnect.com",443,1,req) If CkHttp::ckLastMethodSuccess(http) = 0 Debug CkHttp::ckLastErrorText(http) CkHttp::ckDispose(http) CkHttpRequest::ckDispose(req) CkDateTime::ckDispose(dt) 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) ; A sample response: ; <?xml version="1.0" encoding="utf-8"?> ; <ApiResponseContainer> ; <Request> ; <RequestType>Products</RequestType> ; <RequestAction>Create</RequestAction> ; <RequestVersion>2.0</RequestVersion> ; <RequestIdentifier/> ; <ProcessedAt>2019-04-18T15:28:55+02:00</ProcessedAt> ; </Request> ; <Response> ; <Result>Success</Result> ; <ProductsCreateResponseContainer> ; <ProcessID><![CDATA[J048hgS4OkNn0JnH]]></ProcessID> ; </ProductsCreateResponseContainer> ; </Response> ; </ApiResponseContainer> ; Parsing the response... tagPath.s RequestType.s RequestAction.s RequestVersion.s ProcessedAt.s Result.s ProcessID.s RequestType = CkXml::ckGetChildContent(xmlResp,"Request|RequestType") RequestAction = CkXml::ckGetChildContent(xmlResp,"Request|RequestAction") RequestVersion = CkXml::ckGetChildContent(xmlResp,"Request|RequestVersion") ProcessedAt = CkXml::ckGetChildContent(xmlResp,"Request|ProcessedAt") Result = CkXml::ckGetChildContent(xmlResp,"Response|Result") ProcessID = CkXml::ckGetChildContent(xmlResp,"Response|ProductsCreateResponseContainer|ProcessID") CkHttp::ckDispose(http) CkHttpRequest::ckDispose(req) CkDateTime::ckDispose(dt) CkStringBuilder::ckDispose(sbXml) CkStringBuilder::ckDispose(sbStringToSign) CkCrypt2::ckDispose(crypt) CkXml::ckDispose(xmlResp) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.