Bulk Timesheet errors

Hi there,

My first implementation of Keypay and I’m a bit stuck. I’m trying to do a bulk timesheet but getting a 400 “request.timesheets.xxxxxxx.employeeId”: [ “An error has occurred.” ] with the end message “request.Timesheets”: [ “‘Timesheets’ should not be empty.” ]

Here’s the json I’m sending via cURL (with the appropriate content-type), any guidance would be much appreciated…

    {
"fromDate":"2019-03-18T00:00:00",
"toDate":"2019-03-31T23:59:59",
"approved":"false",
"employeeIdType":"standard",
"locationIdType":"standard",
"replaceExisting":"false",
"workTypeIdType":"standard",
"timesheets":{
"1379566":{
"employeeId":"1379566",
"startTime":"2019-03-23T16:30:00",
"endTime":"2019-03-23T00:00:00",
"locationId":"340461",
"units":7.5,
"attachmentId":null,
"classification":null,
"classificationId":null,
"comments":null,
"externalId":null,
"rate":null,
"workTypeId":null,
"payCategoryId":null,
"leaveCategoryId":null
},
"1379397":{
"employeeId":"1379397",
"startTime":"2019-03-23T14:30:00",
"endTime":"2019-03-24T00:30:00",
"locationId":"340461",
"units":10,
"attachmentId":null,
"classification":null,
"classificationId":null,
"comments":null,
"externalId":null,
"rate":null,
"workTypeId":null,
"payCategoryId":null,
"leaveCategoryId":null
},
"1379368":{
"employeeId":"1379368",
"startTime":"2019-03-23T18:15:00",
"endTime":"2019-03-23T00:00:00",
"locationId":"340461",
"units":5.75,
"attachmentId":null,
"classification":null,
"classificationId":null,
"comments":null,
"externalId":null,
"rate":null,
"workTypeId":null,
"payCategoryId":null,
"leaveCategoryId":null
},
"1730255":{
"employeeId":"1730255",
"startTime":"2019-03-23T17:00:00",
"endTime":"2019-03-23T00:00:00",
"locationId":"340461",
"units":7,
"attachmentId":null,
"classification":null,
"classificationId":null,
"comments":null,
"externalId":null,
"rate":null,
"workTypeId":null,
"payCategoryId":null,
"leaveCategoryId":null
},
"1379352":{
"employeeId":"1379352",
"startTime":"2019-03-23T16:45:00",
"endTime":"2019-03-23T00:00:00",
"locationId":"340461",
"units":7.25,
"attachmentId":null,
"classification":null,
"classificationId":null,
"comments":null,
"externalId":null,
"rate":null,
"workTypeId":null,
"payCategoryId":null,
"leaveCategoryId":null
},
"1379591":{
"employeeId":"1379591",
"startTime":"2019-03-23T16:00:00",
"endTime":"2019-03-23T00:00:00",
"locationId":"340461",
"units":8,
"attachmentId":null,
"classification":null,
"classificationId":null,
"comments":null,
"externalId":null,
"rate":null,
"workTypeId":null,
"payCategoryId":null,
"leaveCategoryId":null
},
"1379576":{
"employeeId":"1379576",
"startTime":"2019-03-23T14:00:00",
"endTime":"2019-03-23T00:00:00",
"locationId":"340461",
"units":10,
"attachmentId":null,
"classification":null,
"classificationId":null,
"comments":null,
"externalId":null,
"rate":null,
"workTypeId":null,
"payCategoryId":null,
"leaveCategoryId":null
},
"1379593":{
"employeeId":"1379593",
"startTime":"2019-03-23T13:00:00",
"endTime":"2019-03-23T00:00:00",
"locationId":"340461",
"units":11,
"attachmentId":null,
"classification":null,
"classificationId":null,
"comments":null,
"externalId":null,
"rate":null,
"workTypeId":null,
"payCategoryId":null,
"leaveCategoryId":null
},
"1379383":{
"employeeId":"1379383",
"startTime":"2019-03-23T17:00:00",
"endTime":"2019-03-23T00:00:00",
"locationId":"340461",
"units":7,
"attachmentId":null,
"classification":null,
"classificationId":null,
"comments":null,
"externalId":null,
"rate":null,
"workTypeId":null,
"payCategoryId":null,
"leaveCategoryId":null
},
"1379602":{
"employeeId":"1379602",
"startTime":"2019-03-23T16:30:00",
"endTime":"2019-03-23T00:00:00",
"locationId":"340461",
"units":7.5,
"attachmentId":null,
"classification":null,
"classificationId":null,
"comments":null,
"externalId":null,
"rate":null,
"workTypeId":null,
"payCategoryId":null,
"leaveCategoryId":null
},
"1379595":{
"employeeId":"1379595",
"startTime":"2019-03-23T17:00:00",
"endTime":"2019-03-23T00:00:00",
"locationId":"340461",
"units":7,
"attachmentId":null,
"classification":null,
"classificationId":null,
"comments":null,
"externalId":null,
"rate":null,
"workTypeId":null,
"payCategoryId":null,
"leaveCategoryId":null
},
"1379418":{
"employeeId":"1379418",
"startTime":"2019-03-23T19:15:00",
"endTime":"2019-03-23T00:00:00",
"locationId":"340461",
"units":4.75,
"attachmentId":null,
"classification":null,
"classificationId":null,
"comments":null,
"externalId":null,
"rate":null,
"workTypeId":null,
"payCategoryId":null,
"leaveCategoryId":null
}
}
}

Hi Craig,

The timesheets object you’re sending needs to be a dictionary with the key is the employeeId and the value is the an array of timesheets what you’re sending is a dictionary with the employeeId as the key, but the value is a single timesheet object.

You need to change it to be (note the square brackets):

"1379566":[{
"employeeId":"1379566",
"startTime":"2019-03-23T16:30:00",
"endTime":"2019-03-23T00:00:00",
"locationId":"340461",
"units":7.5,
"attachmentId":null,
"classification":null,
"classificationId":null,
"comments":null,
"externalId":null,
"rate":null,
"workTypeId":null,
"payCategoryId":null,
"leaveCategoryId":null
}],

Thanks lomaxx, I’ll have a look at my array construct.

Hi lomaxx (or anyone else who cares to take a peek), here’s the revised data I’m sending over, but still getting ‘timesheets should not be empty’. Note that I’ve simplified the number of fields being sent and just generating one in the interests of seeing how I can get it to work.

I’ve looked at your example and pored over the docs and I just can’t see where I’m going wrong. Very much appreciate any guidance.

{
  "fromDate": "2019-03-18T00:00:00",
  "approved": "false",
  "employeeIdType": "standard",
  "locationIdType": "standard",
  "replaceExisting": "false",
  "timesheets": {
    "1379397": [
      {
        "employeeId": "1379397",
        "startTime": "2019-03-23T14:30:00",
        "endTime": "2019-03-24T00:30:00",
        "locationId": "340461",
        "units": 10
      }
    ]
  },
  "toDate": "2019-03-31T23:59:59",
  "workTypeIdType": "standard"
}

Hi Craig

Your JSON object looks fine in the latest example so thats good…

I have run it against one of my test businesses locally using the following syntax (which is for cURL on Windows Linux Subsystem):

curl -X POST -i -H 'Content-Type: application/json' -u '{your api key here}:' "https://api.yourpayroll.com.au/api/v2/business/{business Id here}/timesheet/bulk" -d '@Timesheets.json'

Note: JSON request payload saved to Timesheets.json and you will need to substitute in your API Key and Business ID as appropriate…

Hope this helps!!

Thanks Brett, it did indeed. Also my first time doing something like this out of PHP so you gave me the clues I needed for the win… Timesheets successfully sent.

Appreciate the help from you and lomaxx.