Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

Tcl Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text
HTTP

HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
MS Storage Providers
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl

 

 

 

(Tcl) effectconnect Product Update

Use this call to update a product (f.e. stock or price) in EffectConnect.

Chilkat Tcl Extension Downloads

Chilkat Tcl Extension Downloads

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.