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

SQL Server 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
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Cloud Signature CSC
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
uncategorized

 

 

 

(SQL Server) effectconnect Product Update

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

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    -- Important: Do not use nvarchar(max).  See the warning about using nvarchar(max).
    DECLARE @sTmp0 nvarchar(4000)
    DECLARE @sTmp1 nvarchar(4000)
    -- This example assumes the Chilkat API to have been previously unlocked.
    -- See Global Unlock Sample for sample code.

    DECLARE @success int

    DECLARE @uri nvarchar(4000)
    SELECT @uri = '/products'
    DECLARE @apiVersion nvarchar(4000)
    SELECT @apiVersion = '2.0'

    DECLARE @http int
    -- Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @req int
    -- Use "Chilkat_9_5_0.HttpRequest" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.HttpRequest', @req OUT

    -- Use your effectconnect public key here...
    EXEC sp_OAMethod @req, 'AddHeader', NULL, 'KEY', 'PUBLIC_KEY'
    EXEC sp_OAMethod @req, 'AddHeader', NULL, 'VERSION', @apiVersion
    EXEC sp_OAMethod @req, 'AddHeader', NULL, 'URI', @uri
    EXEC sp_OAMethod @req, 'AddHeader', NULL, 'RESPONSETYPE', 'XML'
    EXEC sp_OAMethod @req, 'AddHeader', NULL, 'RESPONSELANGUAGE', 'en'

    -- Get the current date/time in timestamp format.
    DECLARE @dt int
    -- Use "Chilkat_9_5_0.CkDateTime" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.CkDateTime', @dt OUT

    EXEC sp_OAMethod @dt, 'SetFromCurrentSystemTime', @success OUT
    DECLARE @timestamp nvarchar(4000)
    EXEC sp_OAMethod @dt, 'GetAsTimestamp', @timestamp OUT, 1

    EXEC sp_OAMethod @req, 'AddHeader', NULL, 'TIME', @timestamp

    PRINT 'timestamp = ' + @timestamp

    DECLARE @sbXml int
    -- Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbXml OUT

    EXEC sp_OAMethod @sbXml, 'LoadFile', @success OUT, 'qa_data/xml/effectconnect/effconUpdate.xml', 'utf-8'

    EXEC sp_OAGetProperty @sbXml, 'Length', @iTmp0 OUT
    PRINT 'length = ' + @iTmp0

    EXEC sp_OASetProperty @req, 'HttpVerb', 'PUT'
    EXEC sp_OASetProperty @req, 'Path', @uri
    EXEC sp_OASetProperty @req, 'ContentType', 'multipart/form-data'
    EXEC sp_OAMethod @sbXml, 'GetAsString', @sTmp0 OUT
    EXEC sp_OAMethod @req, 'AddStringForUpload', @success OUT, 'payload', 'effconUpdate.xml', @sTmp0, 'utf-8'
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @req, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @req
        EXEC @hr = sp_OADestroy @dt
        EXEC @hr = sp_OADestroy @sbXml
        RETURN
      END

    -- Build a string-to-sign and sign it using our effectconnect private key
    DECLARE @sbStringToSign int
    -- Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbStringToSign OUT

    EXEC sp_OAGetProperty @sbXml, 'Length', @iTmp0 OUT
    EXEC sp_OAMethod @sbStringToSign, 'AppendInt', @success OUT, @iTmp0
    EXEC sp_OAMethod @sbStringToSign, 'Append', @success OUT, 'PUT'
    EXEC sp_OAMethod @sbStringToSign, 'Append', @success OUT, @uri
    EXEC sp_OAMethod @sbStringToSign, 'Append', @success OUT, @apiVersion
    EXEC sp_OAMethod @sbStringToSign, 'Append', @success OUT, @timestamp

    DECLARE @crypt int
    -- Use "Chilkat_9_5_0.Crypt2" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.Crypt2', @crypt OUT

    EXEC sp_OASetProperty @crypt, 'MacAlgorithm', 'hmac'
    EXEC sp_OASetProperty @crypt, 'HashAlgorithm', 'sha512'
    EXEC sp_OASetProperty @crypt, 'EncodingMode', 'base64'
    -- Use your effectconnect private key here:
    EXEC sp_OAMethod @crypt, 'SetMacKeyString', @success OUT, 'PRIVATE_KEY'
    EXEC sp_OAMethod @sbStringToSign, 'GetAsString', @sTmp1 OUT
    EXEC sp_OAMethod @crypt, 'MacStringENC', @sTmp0 OUT, @sTmp1
    EXEC sp_OAMethod @req, 'AddHeader', NULL, 'SIGNATURE', @sTmp0

    DECLARE @resp int
    EXEC sp_OAMethod @http, 'SynchronousRequest', @resp OUT, 'submit.effectconnect.com', 443, 1, @req
    EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT
    IF @iTmp0 = 0
      BEGIN
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @req
        EXEC @hr = sp_OADestroy @dt
        EXEC @hr = sp_OADestroy @sbXml
        EXEC @hr = sp_OADestroy @sbStringToSign
        EXEC @hr = sp_OADestroy @crypt
        RETURN
      END


    EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
    PRINT 'response status code = ' + @iTmp0

    -- 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.
    DECLARE @xmlResp int
    -- Use "Chilkat_9_5_0.Xml" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.Xml', @xmlResp OUT

    EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT
    EXEC sp_OAMethod @xmlResp, 'LoadXml', @success OUT, @sTmp0
    EXEC @hr = sp_OADestroy @resp


    PRINT 'response body:'
    EXEC sp_OAMethod @xmlResp, 'GetXml', @sTmp0 OUT
    PRINT @sTmp0

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

    DECLARE @tagPath nvarchar(4000)

    DECLARE @RequestType nvarchar(4000)

    DECLARE @RequestAction nvarchar(4000)

    DECLARE @RequestVersion nvarchar(4000)

    DECLARE @ProcessedAt nvarchar(4000)

    DECLARE @Result nvarchar(4000)

    DECLARE @ProcessID nvarchar(4000)

    EXEC sp_OAMethod @xmlResp, 'GetChildContent', @RequestType OUT, 'Request|RequestType'
    EXEC sp_OAMethod @xmlResp, 'GetChildContent', @RequestAction OUT, 'Request|RequestAction'
    EXEC sp_OAMethod @xmlResp, 'GetChildContent', @RequestVersion OUT, 'Request|RequestVersion'
    EXEC sp_OAMethod @xmlResp, 'GetChildContent', @ProcessedAt OUT, 'Request|ProcessedAt'
    EXEC sp_OAMethod @xmlResp, 'GetChildContent', @Result OUT, 'Response|Result'
    EXEC sp_OAMethod @xmlResp, 'GetChildContent', @ProcessID OUT, 'Response|ProductsUpdateResponseContainer|ProcessID'

    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @req
    EXEC @hr = sp_OADestroy @dt
    EXEC @hr = sp_OADestroy @sbXml
    EXEC @hr = sp_OADestroy @sbStringToSign
    EXEC @hr = sp_OADestroy @crypt
    EXEC @hr = sp_OADestroy @xmlResp


END
GO

 

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