Unicode C
Unicode C
effectconnect Create or Replace Product Catalog
See more effectconnect Examples
Use this call to create or replace a product catalog in EffectConnect. This is always a purge and replace action for the entire catalog.Chilkat Unicode C Downloads
#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;
success = FALSE;
// 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/effconCreate.xml",L"utf-8");
wprintf(L"length = %d\n",CkStringBuilderW_getLength(sbXml));
CkHttpRequestW_putHttpVerb(req,L"POST");
CkHttpRequestW_putPath(req,uri);
CkHttpRequestW_putContentType(req,L"multipart/form-data");
success = CkHttpRequestW_AddStringForUpload(req,L"payload",L"effcon.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"POST");
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 = CkHttpResponseW_Create();
success = CkHttpW_HttpSReq(http,L"submit.effectconnect.com",443,TRUE,req,resp);
if (success == 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);
CkHttpResponseW_Dispose(resp);
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));
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>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 = 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|ProductsCreateResponseContainer|ProcessID");
CkHttpW_Dispose(http);
CkHttpRequestW_Dispose(req);
CkDateTimeW_Dispose(dt);
CkStringBuilderW_Dispose(sbXml);
CkStringBuilderW_Dispose(sbStringToSign);
CkCrypt2W_Dispose(crypt);
CkHttpResponseW_Dispose(resp);
CkXmlW_Dispose(xmlResp);
}