Xbase++
Xbase++
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 Xbase++ Downloads
LOCAL nSuccess
LOCAL cUri
LOCAL cApiVersion
LOCAL oHttp
LOCAL oReq
LOCAL oDt
LOCAL cTimestamp
LOCAL oSbXml
LOCAL oSbStringToSign
LOCAL oCrypt
LOCAL oResp
LOCAL oXmlResp
LOCAL cTagPath
LOCAL cRequestType
LOCAL cRequestAction
LOCAL cRequestVersion
LOCAL cProcessedAt
LOCAL cResult
LOCAL cProcessID
nSuccess := 0
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
cUri := "/products"
cApiVersion := "2.0"
oHttp := CreateObject("Chilkat.Http")
oReq := CreateObject("Chilkat.HttpRequest")
// Use your effectconnect public key here...
oReq:AddHeader("KEY", "PUBLIC_KEY")
oReq:AddHeader("VERSION", cApiVersion)
oReq:AddHeader("URI", cUri)
oReq:AddHeader("RESPONSETYPE", "XML")
oReq:AddHeader("RESPONSELANGUAGE", "en")
// Get the current date/time in timestamp format.
oDt := CreateObject("Chilkat.CkDateTime")
oDt:SetFromCurrentSystemTime()
cTimestamp := oDt:GetAsTimestamp(1)
oReq:AddHeader("TIME", cTimestamp)
? "timestamp = " + cTimestamp
oSbXml := CreateObject("Chilkat.StringBuilder")
nSuccess := oSbXml:LoadFile("qa_data/xml/effectconnect/effconCreate.xml", "utf-8")
? "length = " + Str(oSbXml:Length)
oReq:HttpVerb := "POST"
oReq:Path := cUri
oReq:ContentType := "multipart/form-data"
nSuccess := oReq:AddStringForUpload("payload", "effcon.xml", oSbXml:GetAsString(), "utf-8")
IF (nSuccess == 0)
? oReq:LastErrorText
oHttp:destroy()
oReq:destroy()
oDt:destroy()
oSbXml:destroy()
RETURN
ENDIF
// Build a string-to-sign and sign it using our effectconnect private key
oSbStringToSign := CreateObject("Chilkat.StringBuilder")
oSbStringToSign:AppendInt(oSbXml:Length)
oSbStringToSign:Append("POST")
oSbStringToSign:Append(cUri)
oSbStringToSign:Append(cApiVersion)
oSbStringToSign:Append(cTimestamp)
oCrypt := CreateObject("Chilkat.Crypt2")
oCrypt:MacAlgorithm := "hmac"
oCrypt:HashAlgorithm := "sha512"
oCrypt:EncodingMode := "base64"
// Use your effectconnect private key here:
oCrypt:SetMacKeyString("PRIVATE_KEY")
oReq:AddHeader("SIGNATURE", oCrypt:MacStringENC(oSbStringToSign:GetAsString()))
oResp := CreateObject("Chilkat.HttpResponse")
nSuccess := oHttp:HttpSReq("submit.effectconnect.com", 443, 1, oReq, oResp)
IF (nSuccess == 0)
? oHttp:LastErrorText
oHttp:destroy()
oReq:destroy()
oDt:destroy()
oSbXml:destroy()
oSbStringToSign:destroy()
oCrypt:destroy()
oResp:destroy()
RETURN
ENDIF
? "response status code = " + Str(oResp: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.
oXmlResp := CreateObject("Chilkat.Xml")
oXmlResp:LoadXml(oResp:BodyStr)
? "response body:"
? oXmlResp:GetXml()
// 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...
cRequestType := oXmlResp:GetChildContent("Request|RequestType")
cRequestAction := oXmlResp:GetChildContent("Request|RequestAction")
cRequestVersion := oXmlResp:GetChildContent("Request|RequestVersion")
cProcessedAt := oXmlResp:GetChildContent("Request|ProcessedAt")
cResult := oXmlResp:GetChildContent("Response|Result")
cProcessID := oXmlResp:GetChildContent("Response|ProductsCreateResponseContainer|ProcessID")
oHttp:destroy()
oReq:destroy()
oDt:destroy()
oSbXml:destroy()
oSbStringToSign:destroy()
oCrypt:destroy()
oResp:destroy()
oXmlResp:destroy()