Unicode C++
Unicode C++
effectconnect Product Update
See more effectconnect Examples
Use this call to update a product (f.e. stock or price) in EffectConnect.Chilkat Unicode C++ Downloads
#include <CkHttpW.h>
#include <CkHttpRequestW.h>
#include <CkDateTimeW.h>
#include <CkStringBuilderW.h>
#include <CkCrypt2W.h>
#include <CkHttpResponseW.h>
#include <CkXmlW.h>
void ChilkatSample(void)
{
bool success = false;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const wchar_t *uri = L"/products";
const wchar_t *apiVersion = L"2.0";
CkHttpW http;
CkHttpRequestW req;
// Use your effectconnect public key here...
req.AddHeader(L"KEY",L"PUBLIC_KEY");
req.AddHeader(L"VERSION",apiVersion);
req.AddHeader(L"URI",uri);
req.AddHeader(L"RESPONSETYPE",L"XML");
req.AddHeader(L"RESPONSELANGUAGE",L"en");
// Get the current date/time in timestamp format.
CkDateTimeW dt;
dt.SetFromCurrentSystemTime();
const wchar_t *timestamp = dt.getAsTimestamp(true);
req.AddHeader(L"TIME",timestamp);
wprintf(L"timestamp = %s\n",timestamp);
CkStringBuilderW sbXml;
success = sbXml.LoadFile(L"qa_data/xml/effectconnect/effconUpdate.xml",L"utf-8");
wprintf(L"length = %d\n",sbXml.get_Length());
req.put_HttpVerb(L"PUT");
req.put_Path(uri);
req.put_ContentType(L"multipart/form-data");
success = req.AddStringForUpload(L"payload",L"effconUpdate.xml",sbXml.getAsString(),L"utf-8");
if (success == false) {
wprintf(L"%s\n",req.lastErrorText());
return;
}
// Build a string-to-sign and sign it using our effectconnect private key
CkStringBuilderW sbStringToSign;
sbStringToSign.AppendInt(sbXml.get_Length());
sbStringToSign.Append(L"PUT");
sbStringToSign.Append(uri);
sbStringToSign.Append(apiVersion);
sbStringToSign.Append(timestamp);
CkCrypt2W crypt;
crypt.put_MacAlgorithm(L"hmac");
crypt.put_HashAlgorithm(L"sha512");
crypt.put_EncodingMode(L"base64");
// Use your effectconnect private key here:
crypt.SetMacKeyString(L"PRIVATE_KEY");
req.AddHeader(L"SIGNATURE",crypt.macStringENC(sbStringToSign.getAsString()));
CkHttpResponseW resp;
success = http.HttpSReq(L"submit.effectconnect.com",443,true,req,resp);
if (success == false) {
wprintf(L"%s\n",http.lastErrorText());
return;
}
wprintf(L"response status code = %d\n",resp.get_StatusCode());
// 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.
CkXmlW xmlResp;
xmlResp.LoadXml(resp.bodyStr());
wprintf(L"response body:\n");
wprintf(L"%s\n",xmlResp.getXml());
// 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>
//
const wchar_t *tagPath = 0;
const wchar_t *RequestType = 0;
const wchar_t *RequestAction = 0;
const wchar_t *RequestVersion = 0;
const wchar_t *ProcessedAt = 0;
const wchar_t *Result = 0;
const wchar_t *ProcessID = 0;
RequestType = xmlResp.getChildContent(L"Request|RequestType");
RequestAction = xmlResp.getChildContent(L"Request|RequestAction");
RequestVersion = xmlResp.getChildContent(L"Request|RequestVersion");
ProcessedAt = xmlResp.getChildContent(L"Request|ProcessedAt");
Result = xmlResp.getChildContent(L"Response|Result");
ProcessID = xmlResp.getChildContent(L"Response|ProductsUpdateResponseContainer|ProcessID");
}