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
(Unicode C) effectconnect Product UpdateUse this call to update a product (f.e. stock or price) in EffectConnect.
#include <C_CkHttpW.h> #include <C_CkHttpRequestW.h> #include <C_CkDateTimeW.h> #include <C_CkStringBuilderW.h> #include <C_CkCrypt2W.h> #include <C_CkHttpResponseW.h> #include <C_CkXmlW.h> void ChilkatSample(void) { BOOL success; const wchar_t *uri; const wchar_t *apiVersion; HCkHttpW http; HCkHttpRequestW req; HCkDateTimeW dt; const wchar_t *timestamp; HCkStringBuilderW sbXml; HCkStringBuilderW sbStringToSign; HCkCrypt2W crypt; HCkHttpResponseW resp; HCkXmlW xmlResp; const wchar_t *tagPath; const wchar_t *RequestType; const wchar_t *RequestAction; const wchar_t *RequestVersion; const wchar_t *ProcessedAt; const wchar_t *Result; const wchar_t *ProcessID; // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. uri = L"/products"; apiVersion = L"2.0"; http = CkHttpW_Create(); req = CkHttpRequestW_Create(); // Use your effectconnect public key here... CkHttpRequestW_AddHeader(req,L"KEY",L"PUBLIC_KEY"); CkHttpRequestW_AddHeader(req,L"VERSION",apiVersion); CkHttpRequestW_AddHeader(req,L"URI",uri); CkHttpRequestW_AddHeader(req,L"RESPONSETYPE",L"XML"); CkHttpRequestW_AddHeader(req,L"RESPONSELANGUAGE",L"en"); // Get the current date/time in timestamp format. dt = CkDateTimeW_Create(); CkDateTimeW_SetFromCurrentSystemTime(dt); timestamp = CkDateTimeW_getAsTimestamp(dt,TRUE); CkHttpRequestW_AddHeader(req,L"TIME",timestamp); wprintf(L"timestamp = %s\n",timestamp); sbXml = CkStringBuilderW_Create(); success = CkStringBuilderW_LoadFile(sbXml,L"qa_data/xml/effectconnect/effconUpdate.xml",L"utf-8"); wprintf(L"length = %d\n",CkStringBuilderW_getLength(sbXml)); CkHttpRequestW_putHttpVerb(req,L"PUT"); CkHttpRequestW_putPath(req,uri); CkHttpRequestW_putContentType(req,L"multipart/form-data"); success = CkHttpRequestW_AddStringForUpload(req,L"payload",L"effconUpdate.xml",CkStringBuilderW_getAsString(sbXml),L"utf-8"); if (success == FALSE) { wprintf(L"%s\n",CkHttpRequestW_lastErrorText(req)); CkHttpW_Dispose(http); CkHttpRequestW_Dispose(req); CkDateTimeW_Dispose(dt); CkStringBuilderW_Dispose(sbXml); return; } // Build a string-to-sign and sign it using our effectconnect private key sbStringToSign = CkStringBuilderW_Create(); CkStringBuilderW_AppendInt(sbStringToSign,CkStringBuilderW_getLength(sbXml)); CkStringBuilderW_Append(sbStringToSign,L"PUT"); CkStringBuilderW_Append(sbStringToSign,uri); CkStringBuilderW_Append(sbStringToSign,apiVersion); CkStringBuilderW_Append(sbStringToSign,timestamp); crypt = CkCrypt2W_Create(); CkCrypt2W_putMacAlgorithm(crypt,L"hmac"); CkCrypt2W_putHashAlgorithm(crypt,L"sha512"); CkCrypt2W_putEncodingMode(crypt,L"base64"); // Use your effectconnect private key here: CkCrypt2W_SetMacKeyString(crypt,L"PRIVATE_KEY"); CkHttpRequestW_AddHeader(req,L"SIGNATURE",CkCrypt2W_macStringENC(crypt,CkStringBuilderW_getAsString(sbStringToSign))); resp = CkHttpW_SynchronousRequest(http,L"submit.effectconnect.com",443,TRUE,req); if (CkHttpW_getLastMethodSuccess(http) == FALSE) { wprintf(L"%s\n",CkHttpW_lastErrorText(http)); CkHttpW_Dispose(http); CkHttpRequestW_Dispose(req); CkDateTimeW_Dispose(dt); CkStringBuilderW_Dispose(sbXml); CkStringBuilderW_Dispose(sbStringToSign); CkCrypt2W_Dispose(crypt); return; } wprintf(L"response status code = %d\n",CkHttpResponseW_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 = CkXmlW_Create(); CkXmlW_LoadXml(xmlResp,CkHttpResponseW_bodyStr(resp)); CkHttpResponseW_Dispose(resp); wprintf(L"response body:\n"); wprintf(L"%s\n",CkXmlW_getXml(xmlResp)); // A sample response: // <?xml version="1.0" encoding="utf-8"?> // <ApiResponseContainer> // <Request> // <RequestType>Products</RequestType> // <RequestAction>Update</RequestAction> // <RequestVersion>2.0</RequestVersion> // <RequestIdentifier/> // <ProcessedAt>2019-04-18T15:37:32+02:00</ProcessedAt> // </Request> // <Response> // <Result>Success</Result> // <ProductsUpdateResponseContainer> // <ProcessID><![CDATA[f81ngzD2S7gooFk3]]></ProcessID> // </ProductsUpdateResponseContainer> // </Response> // </ApiResponseContainer> // RequestType = CkXmlW_getChildContent(xmlResp,L"Request|RequestType"); RequestAction = CkXmlW_getChildContent(xmlResp,L"Request|RequestAction"); RequestVersion = CkXmlW_getChildContent(xmlResp,L"Request|RequestVersion"); ProcessedAt = CkXmlW_getChildContent(xmlResp,L"Request|ProcessedAt"); Result = CkXmlW_getChildContent(xmlResp,L"Response|Result"); ProcessID = CkXmlW_getChildContent(xmlResp,L"Response|ProductsUpdateResponseContainer|ProcessID"); CkHttpW_Dispose(http); CkHttpRequestW_Dispose(req); CkDateTimeW_Dispose(dt); CkStringBuilderW_Dispose(sbXml); CkStringBuilderW_Dispose(sbStringToSign); CkCrypt2W_Dispose(crypt); CkXmlW_Dispose(xmlResp); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.