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 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.
#include <C_CkHttp.h> #include <C_CkHttpRequest.h> #include <C_CkDateTime.h> #include <C_CkStringBuilder.h> #include <C_CkCrypt2.h> #include <C_CkHttpResponse.h> #include <C_CkXml.h> void ChilkatSample(void) { BOOL success; const char *uri; const char *apiVersion; HCkHttp http; HCkHttpRequest req; HCkDateTime dt; const char *timestamp; HCkStringBuilder sbXml; HCkStringBuilder sbStringToSign; HCkCrypt2 crypt; HCkHttpResponse resp; HCkXml xmlResp; const char *tagPath; const char *RequestType; const char *RequestAction; const char *RequestVersion; const char *ProcessedAt; const char *Result; const char *ProcessID; // 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); printf("timestamp = %s\n",timestamp); sbXml = CkStringBuilder_Create(); success = CkStringBuilder_LoadFile(sbXml,"qa_data/xml/effectconnect/effconCreate.xml","utf-8"); printf("length = %d\n",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) { printf("%s\n",CkHttpRequest_lastErrorText(req)); CkHttp_Dispose(http); CkHttpRequest_Dispose(req); CkDateTime_Dispose(dt); CkStringBuilder_Dispose(sbXml); return; } // 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) { printf("%s\n",CkHttp_lastErrorText(http)); CkHttp_Dispose(http); CkHttpRequest_Dispose(req); CkDateTime_Dispose(dt); 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)); // 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); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.