0

I am trying to create an Invoice in Xero accounting using one of the Xero provided rest api, i used a Python requests library to access the certain Invoice rest api but unable to create an invoice. It raise following error

{'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.'}

Here is my my python code,

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)

Whats wrong i did here?

Md. Tanvir Raihan
  • 4,075
  • 9
  • 37
  • 70

2 Answers2

0

You need to give data like this as per the API documentation

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"
                }
              ]
            }
        ]
    }
    
Rahul K P
  • 15,740
  • 4
  • 35
  • 52
0

Try shortening your description. I just had the same error, which was odd as the exact same code was working on other invoices, then I noticed the description on one was longer than the other. I shortened it, and the error disappeared and the invoice was created.

Stuart
  • 146
  • 4