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 Web API Examples

Primary Categories

ABN AMRO
AWS Secrets Manager
AWS Security Token Service
AWS Translate
Activix CRM
Adyen
Alibaba Cloud OSS
Amazon Cognito
Amazon DynamoDB
Amazon MWS
Amazon Pay
Amazon Rekognition
Amazon SP-API
Amazon Voice ID
Aruba Fatturazione
Azure Maps
Azure Monitor
Azure OAuth2
Azure Storage Accounts
Backblaze S3
Banco Inter
Belgian eHealth Platform
Bitfinex v2 REST
Bluzone
BrickLink
Bunny CDN
CallRail
CardConnect
Cerved
ClickBank
Clickatell
Cloudfare
Constant Contact
DocuSign
Duo Auth MFA
ETrade
Ecwid
Egypt ITIDA
Egypt eReceipt
Etsy
Facebook
Faire
Frame.io
GeoOp
GetHarvest
Global Payments
Google People
Google Search Console
Google Translate
Google Vision
Hungary NAV Invoicing
IBM Text to Speech
Ibanity
IntakeQ
JCC Cyprus
Jira
Lightspeed
MYOB
Magento
Mailgun
Malaysia MyInvois

Mastercard
MedTunnel
MercadoLibre
MessageMedia
Microsoft Calendar
Microsoft Group
Microsoft Tasks and Plans
Microsoft Teams
Moody's
Okta OAuth/OIDC
OneLogin OIDC
OneNote
OpenAI ChatGPT
PRODA
PayPal
Paynow.pl
Peoplevox
Populi
QuickBooks
Rabobank
Refinitiv
Royal Mail OBA
SCiS Schools Catalogue
SII Chile
SMSAPI
SOAP finkok.com
Salesforce
SendGrid
Shippo
Shopify
Shopware
Shopware 6
SimpleTexting
Square
Stripe
SugarCRM
TicketBAI
TikTok Shop
Trello
Twilio
Twitter API v2
Twitter v1
UPS
UniPin
VoiceBase
Vonage
WaTrend
Walmart v3
Wasabi
WhatsApp
WiX
WooCommerce
WordPress
Xero
Yahoo Mail
Yapily
Yousign
ZATCA
Zendesk
Zoom
_Miscellaneous_
eBay
effectconnect
hacienda.go.cr

 

 

 

(Tcl) palena.sii.cl getToken SOAP Request

Demonstrates how to call getToken SOAP request at palena.sii.cl

Chilkat Tcl Extension Downloads

Chilkat Tcl Extension Downloads

load ./chilkat.dll

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

# Create the XML to be signed...
set xmlToSign [new_CkXml]

CkXml_put_Tag $xmlToSign "getToken"
# This is the seed obtained from palena.sii.cl getSeed
CkXml_UpdateChildContent $xmlToSign "item|Semilla" "033878794660"

set gen [new_CkXmlDSigGen]

CkXmlDSigGen_put_SigLocation $gen "getToken"
CkXmlDSigGen_put_SigLocationMod $gen 0
CkXmlDSigGen_put_SigNamespacePrefix $gen ""
CkXmlDSigGen_put_SigNamespaceUri $gen "http://www.w3.org/2000/09/xmldsig#"
CkXmlDSigGen_put_SignedInfoCanonAlg $gen "EXCL_C14N"
CkXmlDSigGen_put_SignedInfoDigestMethod $gen "sha1"

CkXmlDSigGen_AddSameDocRef $gen "" "sha1" "" "" ""

# Provide a certificate + private key. (PFX password is test123)
set cert [new_CkCert]

set success [CkCert_LoadPfxFile $cert "qa_data/pfx/cert_test123.pfx" "test123"]
if {$success != 1} then {
    puts [CkCert_lastErrorText $cert]
    delete_CkXml $xmlToSign
    delete_CkXmlDSigGen $gen
    delete_CkCert $cert
    exit
}

CkXmlDSigGen_SetX509Cert $gen $cert 1

CkXmlDSigGen_put_KeyInfoType $gen "X509Data"
CkXmlDSigGen_put_X509Type $gen "Certificate"

# Load XML to be signed...
set sbXml [new_CkStringBuilder]

CkXml_put_EmitXmlDecl $xmlToSign 0
CkXml_GetXmlSb $xmlToSign $sbXml

CkXmlDSigGen_put_Behaviors $gen "IndentedSignature"

# Sign the XML...
set success [CkXmlDSigGen_CreateXmlDSigSb $gen $sbXml]
if {$success != 1} then {
    puts [CkXmlDSigGen_lastErrorText $gen]
    delete_CkXml $xmlToSign
    delete_CkXmlDSigGen $gen
    delete_CkCert $cert
    delete_CkStringBuilder $sbXml
    exit
}

# -----------------------------------------------

set http [new_CkHttp]

CkHttp_put_UncommonOptions $http "AllowEmptyHeaders"
CkHttp_SetRequestHeader $http "SOAPAction" ""

CkHttp_SetRequestHeader $http "Content-Type" "text/xml; charset=utf-8"

# The endpoint for this soap service is:
set endPoint "https://palena.sii.cl/DTEWS/GetTokenFromSeed.jws"

# Send the following SOAP XML

# <soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:def="http://DefaultNamespace">
#    <soapenv:Header/>
#    <soapenv:Body>
#       <def:getToken soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
#          <pszXml>SIGNED_XML_GOES_HERE</pszXml>
#       </def:getToken>
#    </soapenv:Body>
# </soapenv:Envelope>

set xml [new_CkXml]

CkXml_put_Tag $xml "soapenv:Envelope"
CkXml_AddAttribute $xml "xmlns:xsi" "http://www.w3.org/2001/XMLSchema-instance"
CkXml_AddAttribute $xml "xmlns:xsd" "http://www.w3.org/2001/XMLSchema"
CkXml_AddAttribute $xml "xmlns:soapenv" "http://schemas.xmlsoap.org/soap/envelope/"
CkXml_AddAttribute $xml "xmlns:def" "http://DefaultNamespace"
CkXml_UpdateChildContent $xml "soapenv:Header" ""
CkXml_UpdateAttrAt $xml "soapenv:Body|def:getToken" 1 "soapenv:encodingStyle" "http://schemas.xmlsoap.org/soap/encoding/"
CkXml_UpdateChildContent $xml "soapenv:Body|def:getToken|pszXml" "SIGNED_XML_GOES_HERE"

# We must replace the "SIGNED_XML_GOES_HERE" with the exact contents of the signed XML to ensure the signed XML is not modified in any way.
set sbSoapXml [new_CkStringBuilder]

CkStringBuilder_Append $sbSoapXml [CkXml_getXml $xml]
set numReplaced [CkStringBuilder_Replace $sbXml "&" "&amp;"]
set numReplaced [CkStringBuilder_Replace $sbXml ">" "&gt;"]
set numReplaced [CkStringBuilder_Replace $sbXml "<" "&lt;"]
set numReplaced [CkStringBuilder_Replace $sbXml "\"" "&quot;"]
set numReplaced [CkStringBuilder_Replace $sbSoapXml "SIGNED_XML_GOES_HERE" [CkStringBuilder_getAsString $sbXml]]

# resp is a CkHttpResponse
set resp [CkHttp_PostXml $http $endPoint [CkStringBuilder_getAsString $sbSoapXml] "utf-8"]
if {[CkHttp_get_LastMethodSuccess $http] != 1} then {
    puts [CkHttp_lastErrorText $http]
    puts "LastHeader:"
    puts [CkHttp_lastHeader $http]
    delete_CkXml $xmlToSign
    delete_CkXmlDSigGen $gen
    delete_CkCert $cert
    delete_CkStringBuilder $sbXml
    delete_CkHttp $http
    delete_CkXml $xml
    delete_CkStringBuilder $sbSoapXml
    exit
}

set responseStatusCode [CkHttpResponse_get_StatusCode $resp]

puts "Response Status Code: $responseStatusCode"

# You may examine the exact HTTP header sent with the POST like this:
puts "LastHeader:"
puts [CkHttp_lastHeader $http]

# Examine the XML returned by the web service:
puts "XML Response:"
set xmlResp [new_CkXml]

CkXml_LoadXml $xmlResp [CkHttpResponse_bodyStr $resp]
puts [CkXml_getXml $xmlResp]

# Use this online tool to generate parsing code from response XML: 
# Generate Parsing Code from XML

delete_CkHttpResponse $resp


delete_CkXml $xmlToSign
delete_CkXmlDSigGen $gen
delete_CkCert $cert
delete_CkStringBuilder $sbXml
delete_CkHttp $http
delete_CkXml $xml
delete_CkStringBuilder $sbSoapXml
delete_CkXml $xmlResp

 

© 2000-2024 Chilkat Software, Inc. All Rights Reserved.