使用 python 创建 Xero 发票 请求提高"No data has been processed for this endpoint. This endpoint is expecting I



我正试图使用Xero提供的一个rest api在Xero会计中创建Invoice,我使用Python请求库访问特定的Invoice rest api,但无法创建发票。它引发以下错误

{'ErrorNumber': 17, 'Type': 'NoDataProcessedException', 'Message': 'No data has been processed for this endpoint. This endpoint is expecting Invoice data to be specifed in the request body.'}

这是我的python代码

def XeroRequests():
new_tokens = XeroRefreshToken('*****************************')
xero_tenant_id = XeroTenants(new_tokens[0])

get_url = 'https://api.xero.com/api.xro/2.0/Invoices'
response = requests.post(get_url,
headers = {
'Authorization': 'Bearer ' + new_tokens[0],
'Xero-tenant-id': xero_tenant_id,
'Accept': 'application/json'
},
data = {
"Type": "ACCREC",
"Contact": {
"ContactID": "eaa28f49-6028-4b6e-bb12-d8f6278073fc"
},
"Date": "/Date(1518685950940+0000)/",
"DueDate": "/Date(1518685950940+0000)/",
"DateString": "2009-05-27T00:00:00",
"DueDateString": "2009-06-06T00:00:00",
"LineAmountTypes": "Exclusive",
"LineItems": [
{
"Description": "Consulting services as agreed (20% off standard rate)",
"Quantity": "10",
"UnitAmount": "100.00",
"AccountCode": "200",
"DiscountRate": "20"
}
]
})

json_response = response.json()
print("POST response ", json_response)

我在这里做错了什么?

您需要根据API文档提供这样的数据

data = {
"Invoices": [{
"Type": "ACCREC",
"Contact": {
"ContactID": "eaa28f49-6028-4b6e-bb12-d8f6278073fc"
},
"Date": "/Date(1518685950940+0000)/",
"DueDate": "/Date(1518685950940+0000)/",
"DateString": "2009-05-27T00:00:00",
"DueDateString": "2009-06-06T00:00:00",
"LineAmountTypes": "Exclusive",
"LineItems": [
{
"Description": "Consulting services as agreed (20% off standard rate)",
"Quantity": "10",
"UnitAmount": "100.00",
"AccountCode": "200",
"DiscountRate": "20"
}
]
}
]
}

试着缩短你的描述。我只是遇到了同样的错误,这很奇怪,因为其他发票上的代码完全相同,然后我注意到其中一张发票上的描述比另一张长。我缩短了它,错误消失了,发票也创建了。

相关内容

最新更新