Sample code for 30+ languages & platforms
AutoIt

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 AutoIt Downloads

AutoIt
Local $bSuccess = False

; This example assumes the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.

Local $sUri = "/products"
Local $sApiVersion = "2.0"

$oHttp = ObjCreate("Chilkat.Http")
$oReq = ObjCreate("Chilkat.HttpRequest")

; Use your effectconnect public key here...
$oReq.AddHeader "KEY","PUBLIC_KEY"
$oReq.AddHeader "VERSION",$sApiVersion
$oReq.AddHeader "URI",$sUri
$oReq.AddHeader "RESPONSETYPE","XML"
$oReq.AddHeader "RESPONSELANGUAGE","en"

; Get the current date/time in timestamp format.
$oDt = ObjCreate("Chilkat.CkDateTime")
$oDt.SetFromCurrentSystemTime()
Local $sTimestamp = $oDt.GetAsTimestamp(True)

$oReq.AddHeader "TIME",$sTimestamp
ConsoleWrite("timestamp = " & $sTimestamp & @CRLF)

$oSbXml = ObjCreate("Chilkat.StringBuilder")
$bSuccess = $oSbXml.LoadFile("qa_data/xml/effectconnect/effconCreate.xml","utf-8")
ConsoleWrite("length = " & $oSbXml.Length & @CRLF)

$oReq.HttpVerb = "POST"
$oReq.Path = $sUri
$oReq.ContentType = "multipart/form-data"
$bSuccess = $oReq.AddStringForUpload("payload","effcon.xml",$oSbXml.GetAsString(),"utf-8")
If ($bSuccess = False) Then
    ConsoleWrite($oReq.LastErrorText & @CRLF)
    Exit
EndIf

; Build a string-to-sign and sign it using our effectconnect private key
$oSbStringToSign = ObjCreate("Chilkat.StringBuilder")
$oSbStringToSign.AppendInt($oSbXml.Length)
$oSbStringToSign.Append("POST")
$oSbStringToSign.Append($sUri)
$oSbStringToSign.Append($sApiVersion)
$oSbStringToSign.Append($sTimestamp)

$oCrypt = ObjCreate("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 = ObjCreate("Chilkat.HttpResponse")
$bSuccess = $oHttp.HttpSReq("submit.effectconnect.com",443,True,$oReq,$oResp)
If ($bSuccess = False) Then
    ConsoleWrite($oHttp.LastErrorText & @CRLF)
    Exit
EndIf

ConsoleWrite("response status code = " & $oResp.StatusCode & @CRLF)

; 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 = ObjCreate("Chilkat.Xml")
$oXmlResp.LoadXml($oResp.BodyStr)

ConsoleWrite("response body:" & @CRLF)
ConsoleWrite($oXmlResp.GetXml() & @CRLF)

; 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...
Local $sTagPath
Local $sRequestType
Local $sRequestAction
Local $sRequestVersion
Local $sProcessedAt
Local $sResult
Local $sProcessID

$sRequestType = $oXmlResp.GetChildContent("Request|RequestType")
$sRequestAction = $oXmlResp.GetChildContent("Request|RequestAction")
$sRequestVersion = $oXmlResp.GetChildContent("Request|RequestVersion")
$sProcessedAt = $oXmlResp.GetChildContent("Request|ProcessedAt")
$sResult = $oXmlResp.GetChildContent("Response|Result")
$sProcessID = $oXmlResp.GetChildContent("Response|ProductsCreateResponseContainer|ProcessID")