Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3/4TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

SQL Server Examples

ASN.1
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Base64
Bounced Email
Box
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
ECC
Email Object
Encryption
FTP
Facebook
FileAccess
Firebase
GMail REST API
GeoOp
Google APIs
Google Calendar
Google Cloud Storage
Google Drive
Google Sheets
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)
Jira
MHT / HTML Email
MIME
Microsoft Graph
NTLM
OAuth1
OAuth2
OneDrive
OpenSSL
Outlook
PEM
PFX/P12
POP3
PRNG
PayPal
Peoplevox
QuickBooks
REST
REST Misc
RSA Encryption
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
SharePoint
Shopify
Socket/SSL/TLS
Spider
Stream
Stripe
SugarCRM
Tar Archive
Twitter
Upload
VoiceBase
Walmart
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Xero
Zip
curl
eBay

 

 

 

(SQL Server) Xero Add a Payroll Timesheet with Lines

Demonstrates how to POST a timesheet with lines (for Xero Payroll).

Note: This example requires Chilkat v9.5.0.64 or greater.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    DECLARE @sTmp0 nvarchar(4000)
    --  Note: Requires Chilkat v9.5.0.64 or greater.

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

    DECLARE @rest int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.Rest', @rest OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

    --  Before sending REST API calls, the REST object needs to be
    --  initialized for OAuth1.
    --  See Xero 2-Legged OAuth1 Setup for sample code.

    --  Assuming the REST object's OAuth1 authenticator is setup, and the initial
    --  connection was made, we may now send REST HTTP requests..

    --  --------------------------------------------------------------
    --  Build the following XML:

    --  	<Timesheets>
    --  	  <Timesheet>
    --  	    <EmployeeID>1f606d28-0537-42af-80ce-312d449458af</EmployeeID>
    --  	    <StartDate>2016-11-22</StartDate>
    --  	    <EndDate>2016-11-28</EndDate>
    --  	    <Status>Draft</Status>
    --  	    <TimesheetLines>
    --  	        <TimesheetLine>
    --  	            <EarningsRateID>2c4fbb29-aa68-4a8d-bc05-3f6366f75227</EarningsRateID>
    --  	            <NumberOfUnits>
    --  	                <NumberOfUnit>8.00</NumberOfUnit>
    --  	                <NumberOfUnit>8.00</NumberOfUnit>
    --  	                <NumberOfUnit>8.00</NumberOfUnit>
    --  	                <NumberOfUnit>8.00</NumberOfUnit>
    --  	                <NumberOfUnit>8.00</NumberOfUnit>
    --  	                <NumberOfUnit>0.00</NumberOfUnit>
    --  	                <NumberOfUnit>0.00</NumberOfUnit>
    --  	            </NumberOfUnits>
    --  	        </TimesheetLine>
    --  	    </TimesheetLines>
    --  	  </Timesheet>
    --  	</Timesheets>

    DECLARE @xml int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.Xml', @xml OUT

    EXEC sp_OASetProperty @xml, 'Tag', 'Timesheets'
    EXEC sp_OAMethod @xml, 'NewChild2', NULL, 'Timesheet|EmployeeID', '1f606d28-0537-42af-80ce-312d449458af'
    EXEC sp_OAMethod @xml, 'NewChild2', NULL, 'Timesheet|StartDate', '2016-11-22'
    EXEC sp_OAMethod @xml, 'NewChild2', NULL, 'Timesheet|EndDate', '2016-11-28'
    EXEC sp_OAMethod @xml, 'NewChild2', NULL, 'Timesheet|Status', 'Draft'
    EXEC sp_OAMethod @xml, 'NewChild2', NULL, 'Timesheet|TimesheetLines|TimesheetLine|EarningsRateID', '2c4fbb29-aa68-4a8d-bc05-3f6366f75227'
    DECLARE @tagPath nvarchar(4000)
    SELECT @tagPath = 'Timesheet|TimesheetLines|TimesheetLine|NumberOfUnits|NumberOfUnit'
    EXEC sp_OAMethod @xml, 'NewChild2', NULL, @tagPath, '8.00'
    EXEC sp_OAMethod @xml, 'NewChild2', NULL, @tagPath, '8.00'
    EXEC sp_OAMethod @xml, 'NewChild2', NULL, @tagPath, '8.00'
    EXEC sp_OAMethod @xml, 'NewChild2', NULL, @tagPath, '8.00'
    EXEC sp_OAMethod @xml, 'NewChild2', NULL, @tagPath, '8.00'
    EXEC sp_OAMethod @xml, 'NewChild2', NULL, @tagPath, '0.00'
    EXEC sp_OAMethod @xml, 'NewChild2', NULL, @tagPath, '0.00'

    --  Do not emit the XML declarator. Xero does not accept the XML if it
    --  has the initial line: <?xml version="1.0" encoding="utf-8"?>
    EXEC sp_OASetProperty @xml, 'EmitXmlDecl', 0
    EXEC sp_OAMethod @xml, 'GetXml', @sTmp0 OUT
    PRINT @sTmp0

    PRINT '--'

    EXEC sp_OASetProperty @xml, 'EmitCompact', 1

    EXEC sp_OAMethod @xml, 'GetXml', @sTmp0 OUT
    EXEC sp_OAMethod @rest, 'AddQueryParam', @success OUT, 'xml', @sTmp0

    DECLARE @responseXml nvarchar(4000)
    EXEC sp_OAMethod @rest, 'FullRequestFormUrlEncoded', @responseXml OUT, 'POST', '/payroll.xro/1.0/Timesheets'
    EXEC sp_OAGetProperty @rest, 'LastMethodSuccess', @iTmp0 OUT
    IF @iTmp0 <> 1
      BEGIN
        EXEC sp_OAGetProperty @rest, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @xml
        RETURN
      END

    --  A 200 response is expected for actual success.
    EXEC sp_OAGetProperty @rest, 'ResponseStatusCode', @iTmp0 OUT
    IF @iTmp0 <> 200
      BEGIN

        PRINT @responseXml
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @xml
        RETURN
      END

    --  Examine the XML response
    EXEC sp_OAMethod @xml, 'LoadXml', @success OUT, @responseXml
    EXEC sp_OAMethod @xml, 'GetXml', @sTmp0 OUT
    PRINT @sTmp0

    --  A successful XML response is as follows:

    --  	<Response xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
    --  	    <Id>f213ed01-5a70-4adf-b11f-1aa0c74b96ac</Id>
    --  	    <Status>OK</Status>
    --  	    <ProviderName>ChilkatAU</ProviderName>
    --  	    <DateTimeUTC>2016-11-11T22:39:10.2293174Z</DateTimeUTC>
    --  	    <Timesheets>
    --  	        <Timesheet>
    --  	            <TimesheetID>f62b4437-62b8-4d21-b0c6-791999652712</TimesheetID>
    --  	            <EmployeeID>1f606d28-0537-42af-80ce-312d449458af</EmployeeID>
    --  	            <StartDate>2016-11-22T00:00:00</StartDate>
    --  	            <EndDate>2016-11-28T00:00:00</EndDate>
    --  	            <Status>DRAFT</Status>
    --  	            <Hours>40.00</Hours>
    --  	            <TimesheetLines>
    --  	                <TimesheetLine>
    --  	                    <EarningsRateID>2c4fbb29-aa68-4a8d-bc05-3f6366f75227</EarningsRateID>
    --  	                    <NumberOfUnits>
    --  	                        <NumberOfUnit>8.00</NumberOfUnit>
    --  	                        <NumberOfUnit>8.00</NumberOfUnit>
    --  	                        <NumberOfUnit>8.00</NumberOfUnit>
    --  	                        <NumberOfUnit>8.00</NumberOfUnit>
    --  	                        <NumberOfUnit>8.00</NumberOfUnit>
    --  	                        <NumberOfUnit>0.00</NumberOfUnit>
    --  	                        <NumberOfUnit>0.00</NumberOfUnit>
    --  	                    </NumberOfUnits>
    --  	                    <UpdatedDateUTC>2016-11-11T22:39:10.1824429</UpdatedDateUTC>
    --  	                </TimesheetLine>
    --  	            </TimesheetLines>
    --  	            <UpdatedDateUTC>2016-11-11T22:39:10.1824429</UpdatedDateUTC>
    --  	        </Timesheet>
    --  	    </Timesheets>
    --  	</Response>

    EXEC @hr = sp_OADestroy @rest
    EXEC @hr = sp_OADestroy @xml


END
GO

 

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