使用 python FASTAPI 在 Xero 中添加新联系人

Add new contact in Xero using python FASTAPI

我正在尝试使用 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_tokenxero_tenant_id 是正确的,因为我将它们用于其他方法并且它们工作正常。

谢谢

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

Because

data for dict When not specified content-type, The default is application/x-www-form-urlencoded,