0

我正在尝试使用 python FASTAPI 在 Xero 中添加一个新联系人:

定义一个新的联系人

    contact = {
                "Contacts": [
                    {
                        "Name": "24 locks",
                        "FirstName": "Ben",
                        "LastName": "Bowden",
                        "EmailAddress": "ben.bowden@24locks.com",
                        "ContactPersons": [
                            {
                            "FirstName": "John",
                            "LastName": "Smith",
                            "EmailAddress": "john.smith@24locks.com",
                            "IncludeInEmails": "true"
                            }
                        ]
                    }
                ]
            }

调用 xero API

    get_url = 'https://api.xero.com/api.xro/2.0/Contacts'

    response = requests.post(get_url,
                           headers = {
                               'Authorization': 'Bearer ' + access_token,
                               'Xero-tenant-id': xero_tenant_id,
                               'Accept': 'application/json'
                           },
                           data = contact
                )

    json_response = response.json()

我收到以下错误:

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

有人可以帮忙吗?

您可以假设access_token并且xero_tenant_id是正确的,因为我将它们用于其他方法并且它们工作正常。

谢谢

4

1 回答 1

0

尝试使用json = contact代替data = contact或设置标题'Content-Type': 'application/json'

因为

data对于dict未指定content-type时,默认为application/x-www-form-urlencoded

于 2022-02-09T04:20:48.723 回答