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

Swift 3/4 Web API Examples

Primary Categories

AWS Translate
Activix CRM
Adyen
Amazon MWS
Azure Maps
Azure Monitor
Azure OAuth2
Azure Storage Accounts
Bluzone
CardConnect
ClickBank
Clickatell
Cloudfare
DocuSign
ETrade
Etsy
Facebook
GeoOp
GetHarvest
Jira
MYOB

Magento
Microsoft Calendar
Microsoft Group
Microsoft Tasks and Plans
Okta OAuth/OIDC
OneLogin OIDC
PayPal
Peoplevox
Populi
QuickBooks
SOAP finkok.com
Shippo
Shopify
Stripe
SugarCRM
Trello
Twitter
VoiceBase
Vonage
Walmart
Walmart v3
Xero
eBay
effectconnect

 

 

 

(Swift 3/4) 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 Downloads for the Swift Programming Language

MAC OS X (Cocoa) Objective-C/Swift Libs

iOS Objective-C/Swift Libs

func chilkatTest() {
    // 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.

    let rest = CkoRest()!
    var success: Bool

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

    let xml = CkoXml()!
    xml.tag = "Timesheets"
    xml.newChild2("Timesheet|EmployeeID", content: "1f606d28-0537-42af-80ce-312d449458af")
    xml.newChild2("Timesheet|StartDate", content: "2016-11-22")
    xml.newChild2("Timesheet|EndDate", content: "2016-11-28")
    xml.newChild2("Timesheet|Status", content: "Draft")
    xml.newChild2("Timesheet|TimesheetLines|TimesheetLine|EarningsRateID", content: "2c4fbb29-aa68-4a8d-bc05-3f6366f75227")
    var tagPath: String? = "Timesheet|TimesheetLines|TimesheetLine|NumberOfUnits|NumberOfUnit"
    xml.newChild2(tagPath, content: "8.00")
    xml.newChild2(tagPath, content: "8.00")
    xml.newChild2(tagPath, content: "8.00")
    xml.newChild2(tagPath, content: "8.00")
    xml.newChild2(tagPath, content: "8.00")
    xml.newChild2(tagPath, content: "0.00")
    xml.newChild2(tagPath, content: "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"?>
    xml.emitXmlDecl = false
    print("\(xml.getXml()!)")
    print("--")

    xml.emitCompact = true

    rest.addQueryParam("xml", value: xml.getXml())

    var responseXml: String? = rest.fullRequestFormUrlEncoded("POST", uriPath: "/payroll.xro/1.0/Timesheets")
    if rest.lastMethodSuccess != true {
        print("\(rest.lastErrorText!)")
        return
    }

    // A 200 response is expected for actual success.
    if rest.responseStatusCode.intValue != 200 {
        print("\(responseXml!!)")
        return
    }

    // Examine the XML response
    xml.load(responseXml)
    print("\(xml.getXml()!)")

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

}

 

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