0

library = pyxero 0.9.1

Hey there,

I'm trying to automate the uploading of timesheets to Xero using Python but have hit a stumbling block. I have no issue retrieving information using API but when I try to POST a new timesheet I get a 405 response code. I've tried to simplify my JSON data to the bare minimum Xero allows, but the error still persists. Sample code below

from xero import Xero
import configs
import datetime
from xero.auth import PrivateCredentials
credentials = PrivateCredentials(configss.key, configss.RSAstr)
xero = Xero(credentials)

employees = xero.payrollAPI.employees.all()

timesheets = {'timesheets': {'timesheet': {'EmployeeID': employees[0]["EmployeeID"],
              'StartDate': datetime.datetime(2018,8,15),
              'EndDate': datetime.datetime(2018,8,21),
              'Status': 'Draft'}}}

xero.payrollAPI.timesheets.put(timesheets)

Please note that I can post new contacts and invoices without a problem. Looking at my API call history from the app.xero.com site I see a message with

Request Message =

    <Timesheets><Timesheet><EmployeeID>38fcaf73-e35c-4f38-9ebe-642ef6d5b7c7</EmployeeID> 
<StartDate>2018-09-15</StartDate><EndDate>2018-09-21</EndDate> 
<Status>DRAFT</Status></Timesheet></Timesheets>

Response 405 - Method not allowed

Dara O h
  • 89
  • 8

1 Answers1

1

Your description says POST but your code says 'put' - the docs - https://developer.xero.com/documentation/payroll-api/timesheets - suggest that the method to use is POST.

If you switch your code to be 'post', does it have the desired effect?

rustyskates
  • 856
  • 4
  • 10
  • You legend!! I was banging my head here and can't believe I missed that. xero.payrollAPI.timesheets.save(timesheets) did the trick!! – Dara O h Sep 24 '18 at 22:24