Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Delphi DLL) Xero Add a Payroll Timesheet with LinesDemonstrates how to POST a timesheet with lines (for Xero Payroll). Note: This example requires Chilkat v9.5.0.64 or greater.
uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Rest, Xml; ... procedure TForm1.Button1Click(Sender: TObject); var rest: HCkRest; success: Boolean; xml: HCkXml; tagPath: PWideChar; responseXml: PWideChar; begin // 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. rest := CkRest_Create(); // 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> xml := CkXml_Create(); CkXml_putTag(xml,'Timesheets'); CkXml_NewChild2(xml,'Timesheet|EmployeeID','1f606d28-0537-42af-80ce-312d449458af'); CkXml_NewChild2(xml,'Timesheet|StartDate','2016-11-22'); CkXml_NewChild2(xml,'Timesheet|EndDate','2016-11-28'); CkXml_NewChild2(xml,'Timesheet|Status','Draft'); CkXml_NewChild2(xml,'Timesheet|TimesheetLines|TimesheetLine|EarningsRateID','2c4fbb29-aa68-4a8d-bc05-3f6366f75227'); tagPath := 'Timesheet|TimesheetLines|TimesheetLine|NumberOfUnits|NumberOfUnit'; CkXml_NewChild2(xml,tagPath,'8.00'); CkXml_NewChild2(xml,tagPath,'8.00'); CkXml_NewChild2(xml,tagPath,'8.00'); CkXml_NewChild2(xml,tagPath,'8.00'); CkXml_NewChild2(xml,tagPath,'8.00'); CkXml_NewChild2(xml,tagPath,'0.00'); CkXml_NewChild2(xml,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"?> CkXml_putEmitXmlDecl(xml,False); Memo1.Lines.Add(CkXml__getXml(xml)); Memo1.Lines.Add('--'); CkXml_putEmitCompact(xml,True); CkRest_AddQueryParam(rest,'xml',CkXml__getXml(xml)); responseXml := CkRest__fullRequestFormUrlEncoded(rest,'POST','/payroll.xro/1.0/Timesheets'); if (CkRest_getLastMethodSuccess(rest) <> True) then begin Memo1.Lines.Add(CkRest__lastErrorText(rest)); Exit; end; // A 200 response is expected for actual success. if (CkRest_getResponseStatusCode(rest) <> 200) then begin Memo1.Lines.Add(responseXml); Exit; end; // Examine the XML response CkXml_LoadXml(xml,responseXml); Memo1.Lines.Add(CkXml__getXml(xml)); // 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 CkRest_Dispose(rest); CkXml_Dispose(xml); end; |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.