I am trying to create a Fixed Asset in Xero using the API, not any SDK in particular. Everything but the Depreciation Start Date seems to work properly.
The request body I send to Xero API:
{
assetName: 'Asset name',
assetNumber: 'CA-46987',
serialNumber: '',
purchasePrice: 432,
purchaseDate: '2024-03-06T15:04:30.373',
bookDepreciationSetting: {
depreciationMethod: "StraightLine",
averagingMethod: "FullMonth",
effectiveLifeYears: 5,
depreciationCalculationMethod: "Life"
},
bookDepreciationDetail: {
depreciationStartDate: '2024-03-07'
}
};
The response I get back from Xero looks like this:
{
...
bookDepreciationSetting: {
depreciableObjectId: '0965dc9e-3a5a-46f0-aac9-d7b7f0a466a5',
depreciableObjectType: 'Asset',
bookEffectiveDateOfChangeId: '98108fe1-9eaa-4145-b660-4f36ca2a5418',
depreciationMethod: 'StraightLine',
averagingMethod: 'FullMonth',
effectiveLifeYears: 5,
depreciationCalculationMethod: 'None'
},
bookDepreciationDetail: {
depreciationStartDate: '2024-03-07T00:00:00',
priorAccumDepreciationAmount: 0,
currentAccumDepreciationAmount: 0,
currentCapitalGain: 0,
currentGainLoss: 0
},
taxDepreciationSettings: [],
taxDepreciationDetails: [],
canRollback: true,
accountingBookValue: 432,
taxValues: [],
isDeleteEnabledForDate: true
}
As you can see, it responds with depreciationStartDate properly set to '2024-03-07T00:00:00'. Please note I only send the date component ('2024-03-07'), so this response suggests it's not a simple echo and that the date was processed.
Despite that, when I inspect the newly created Fixed Asset through Xero UI, the Depreciation Start Date is empty. All the other information are properly filled in. Is this a bug, or maybe I am missing some data?
I've tried playing with the date format:
- '2024-03-07'
- '2024-03-07T00:00:00'
- '2024-03-07T00:00:00.000'
- full ISO date
None of it worked.
Edit:
When I send the date in "\/Date(1709769600)\/" format, the response I get back suggests it was ignored:
...
bookDepreciationDetail: {
priorAccumDepreciationAmount: 0,
currentAccumDepreciationAmount: 0,
currentCapitalGain: 0,
currentGainLoss: 0
},
...
From what I can find, because of its .NET framework, Xero docs explicitly state the use of Unix epoch formatting for dates and timestamps when dealing with JSON.
So, for your request to work, you'll need to convert the date or
'2024-03-07'to either one of the following:Epoch timestamp (UTC):
"\/Date(1709769600)\/"Epoch timestamp in milliseconds:
"\/Date(1709769600000+0000)\/"