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 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.
uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Http, CkDateTime, HttpRequest, HttpResponse, StringBuilder, Xml, Crypt2; ... procedure TForm1.Button1Click(Sender: TObject); var success: Boolean; uri: PWideChar; apiVersion: PWideChar; http: HCkHttp; req: HCkHttpRequest; dt: HCkDateTime; timestamp: PWideChar; sbXml: HCkStringBuilder; sbStringToSign: HCkStringBuilder; crypt: HCkCrypt2; resp: HCkHttpResponse; xmlResp: HCkXml; tagPath: PWideChar; RequestType: PWideChar; RequestAction: PWideChar; RequestVersion: PWideChar; ProcessedAt: PWideChar; Result: PWideChar; ProcessID: PWideChar; begin // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. uri := '/products'; apiVersion := '2.0'; http := CkHttp_Create(); req := CkHttpRequest_Create(); // Use your effectconnect public key here... CkHttpRequest_AddHeader(req,'KEY','PUBLIC_KEY'); CkHttpRequest_AddHeader(req,'VERSION',apiVersion); CkHttpRequest_AddHeader(req,'URI',uri); CkHttpRequest_AddHeader(req,'RESPONSETYPE','XML'); CkHttpRequest_AddHeader(req,'RESPONSELANGUAGE','en'); // Get the current date/time in timestamp format. dt := CkDateTime_Create(); CkDateTime_SetFromCurrentSystemTime(dt); timestamp := CkDateTime__getAsTimestamp(dt,True); CkHttpRequest_AddHeader(req,'TIME',timestamp); Memo1.Lines.Add('timestamp = ' + timestamp); sbXml := CkStringBuilder_Create(); success := CkStringBuilder_LoadFile(sbXml,'qa_data/xml/effectconnect/effconCreate.xml','utf-8'); Memo1.Lines.Add('length = ' + IntToStr(CkStringBuilder_getLength(sbXml))); CkHttpRequest_putHttpVerb(req,'POST'); CkHttpRequest_putPath(req,uri); CkHttpRequest_putContentType(req,'multipart/form-data'); success := CkHttpRequest_AddStringForUpload(req,'payload','effcon.xml',CkStringBuilder__getAsString(sbXml),'utf-8'); if (success = False) then begin Memo1.Lines.Add(CkHttpRequest__lastErrorText(req)); Exit; end; // 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'); CkHttpRequest_AddHeader(req,'SIGNATURE',CkCrypt2__macStringENC(crypt,CkStringBuilder__getAsString(sbStringToSign))); resp := CkHttp_SynchronousRequest(http,'submit.effectconnect.com',443,True,req); 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)); // 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... RequestType := CkXml__getChildContent(xmlResp,'Request|RequestType'); RequestAction := CkXml__getChildContent(xmlResp,'Request|RequestAction'); RequestVersion := CkXml__getChildContent(xmlResp,'Request|RequestVersion'); ProcessedAt := CkXml__getChildContent(xmlResp,'Request|ProcessedAt'); Result := CkXml__getChildContent(xmlResp,'Response|Result'); ProcessID := CkXml__getChildContent(xmlResp,'Response|ProductsCreateResponseContainer|ProcessID'); CkHttp_Dispose(http); CkHttpRequest_Dispose(req); CkDateTime_Dispose(dt); CkStringBuilder_Dispose(sbXml); CkStringBuilder_Dispose(sbStringToSign); CkCrypt2_Dispose(crypt); CkXml_Dispose(xmlResp); end; |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.