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
(Tcl) effectconnect Product UpdateUse this call to update a product (f.e. stock or price) in EffectConnect.
load ./chilkat.dll # This example assumes the Chilkat API to have been previously unlocked. # See Global Unlock Sample for sample code. set uri "/products" set apiVersion "2.0" set http [new_CkHttp] set req [new_CkHttpRequest] # Use your effectconnect public key here... CkHttpRequest_AddHeader $req "KEY" "PUBLIC_KEY" CkHttpRequest_AddHeader $req "VERSION" $apiVersion CkHttpRequest_AddHeader $req "URI" $uri CkHttpRequest_AddHeader $req "RESPONSETYPE" "XML" CkHttpRequest_AddHeader $req "RESPONSELANGUAGE" "en" # Get the current date/time in timestamp format. set dt [new_CkDateTime] CkDateTime_SetFromCurrentSystemTime $dt set timestamp [CkDateTime_getAsTimestamp $dt 1] CkHttpRequest_AddHeader $req "TIME" $timestamp puts "timestamp = $timestamp" set sbXml [new_CkStringBuilder] set success [CkStringBuilder_LoadFile $sbXml "qa_data/xml/effectconnect/effconUpdate.xml" "utf-8"] puts "length = [CkStringBuilder_get_Length $sbXml]" CkHttpRequest_put_HttpVerb $req "PUT" CkHttpRequest_put_Path $req $uri CkHttpRequest_put_ContentType $req "multipart/form-data" set success [CkHttpRequest_AddStringForUpload $req "payload" "effconUpdate.xml" [CkStringBuilder_getAsString $sbXml] "utf-8"] if {$success == 0} then { puts [CkHttpRequest_lastErrorText $req] delete_CkHttp $http delete_CkHttpRequest $req delete_CkDateTime $dt delete_CkStringBuilder $sbXml exit } # Build a string-to-sign and sign it using our effectconnect private key set sbStringToSign [new_CkStringBuilder] CkStringBuilder_AppendInt $sbStringToSign [CkStringBuilder_get_Length $sbXml] CkStringBuilder_Append $sbStringToSign "PUT" CkStringBuilder_Append $sbStringToSign $uri CkStringBuilder_Append $sbStringToSign $apiVersion CkStringBuilder_Append $sbStringToSign $timestamp set crypt [new_CkCrypt2] CkCrypt2_put_MacAlgorithm $crypt "hmac" CkCrypt2_put_HashAlgorithm $crypt "sha512" CkCrypt2_put_EncodingMode $crypt "base64" # Use your effectconnect private key here: CkCrypt2_SetMacKeyString $crypt "PRIVATE_KEY" CkHttpRequest_AddHeader $req "SIGNATURE" [CkCrypt2_macStringENC $crypt [CkStringBuilder_getAsString $sbStringToSign]] # resp is a CkHttpResponse set resp [CkHttp_SynchronousRequest $http "submit.effectconnect.com" 443 1 $req] if {[CkHttp_get_LastMethodSuccess $http] == 0} then { puts [CkHttp_lastErrorText $http] delete_CkHttp $http delete_CkHttpRequest $req delete_CkDateTime $dt delete_CkStringBuilder $sbXml delete_CkStringBuilder $sbStringToSign delete_CkCrypt2 $crypt exit } puts "response status code = [CkHttpResponse_get_StatusCode $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. set xmlResp [new_CkXml] CkXml_LoadXml $xmlResp [CkHttpResponse_bodyStr $resp] delete_CkHttpResponse $resp puts "response body:" puts [CkXml_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> # set RequestType [CkXml_getChildContent $xmlResp "Request|RequestType"] set RequestAction [CkXml_getChildContent $xmlResp "Request|RequestAction"] set RequestVersion [CkXml_getChildContent $xmlResp "Request|RequestVersion"] set ProcessedAt [CkXml_getChildContent $xmlResp "Request|ProcessedAt"] set Result [CkXml_getChildContent $xmlResp "Response|Result"] set ProcessID [CkXml_getChildContent $xmlResp "Response|ProductsUpdateResponseContainer|ProcessID"] delete_CkHttp $http delete_CkHttpRequest $req delete_CkDateTime $dt delete_CkStringBuilder $sbXml delete_CkStringBuilder $sbStringToSign delete_CkCrypt2 $crypt delete_CkXml $xmlResp |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.