Xero passing in Reference to invoice

Information on your n8n setup

  • **n8n version: 1.69.2
  • **Database (default: SQLite):SQLite
  • **n8n EXECUTIONS_PROCESS setting (default: own, main):main
  • **Running n8n via (Docker, npm, n8n cloud, desktop app):npm
  • **Operating system:Win 10

I can create & get invoices ok. I see a Reference in the created invoice. I don’t see this as a parameter in the xero node.

How do I do this please.

The input from the webhook is

[
  {
    "headers": {
      "connection": "upgrade",
      "host": "myhost.app",
      "x-real-ip": "81.1xx.xx146",
      "x-forwarded-for": "81.1xx.xx146",
      "x-forwarded-proto": "https",
      "content-length": "697",
      "content-type": "application/json",
      "user-agent": "PostmanRuntime/7.42.0",
      "accept": "*/*",
      "postman-token": "8c46793c-82f1-43d6-b48c-ee8ababe3180",
      "accept-encoding": "gzip, deflate, br"
    },
    "params": {},
    "query": {},
    "body": {
      "Type": "ACCREC",
      "Contact": {
        "ContactID": "02f7759f-211e-44ba-8d00-a38cf1112c4d"
      },
      "Date": "2024-12-03",
      "DueDate": "2024-12-31",
      "LineAmountTypes": "Exclusive",
      "LineItems": [
        {
          "ItemCode": "1001",
          "Description": "TrackingID1234567",
          "Quantity": 1,
          "UnitAmount": 110,
          "AccountCode": "202",
          "TaxType": "NONE",
          "LineAmount": 110
        },
        {
          "ItemCode": "1002",
          "Description": "newTracking No",
          "Quantity": 1,
          "UnitAmount": 21.34,
          "AccountCode": "202",
          "TaxType": "NONE",
          "LineAmount": 21.34
        }
      ],
      "CurrencyCode": "GBP",
      "Status": "DRAFT"
    },
    "webhookUrl": "http://localhost:5678/webhook/xeroCreateInvoices",
    "executionMode": "production"
  }
]

I see I can manually use ‘Add Line item’ then manually add {{ $json.body.LineItems[1].Description }}
but the number of items changes on each invoice

Is there a way to do this in code please?

Getting a step closer.

I have setup the xero explorer and got the credentials and added to an http request node.

the url is https://api.xero.com/api.xro/2.0/Invoices

If I run a get request I get the invoices so the auth is setup.

Using a code node I output


[
  {
    "Type": "ACCREC",
    "Contact": {
      "ContactID": "02f7759f-211e-44ba-8d00-a38cf1112c4d"
    },
    "Date": "2024-12-03",
    "DueDate": "2024-12-31",
    "LineAmountTypes": "Exclusive",
    "LineItems": [
      {
        "ItemCode": "1002",
        "Description": "TrackingID1234567",
        "Quantity": 1,
        "UnitAmount": 110,
        "AccountCode": "202",
        "TaxType": "NONE",
        "LineAmount": 110
      },
      {
        "ItemCode": "1002",
        "Description": "newTracking No",
        "Quantity": 1,
        "UnitAmount": 21.34,
        "AccountCode": "202",
        "TaxType": "NONE",
        "LineAmount": 21.34
      }
    ],
    "CurrencyCode": "GBP",
    "Status": "DRAFT"
  }
]


If I send a PUT with body

{{ $json.toJsonString() }}

Which gives me

{"Type":"ACCREC","Contact":{"ContactID":"02f7759f-211e-44ba-8d00-a38cf1112c4d"},"Date":"2024-12-03","DueDate":"2024-12-31","LineAmountTypes":"Exclusive","LineItems":[{"ItemCode":"1002","Description":"TrackingID1234567","Quantity":1,"UnitAmount":110,"AccountCode":"202","TaxType":"NONE","LineAmount":110},{"ItemCode":"1002","Description":"newTracking No","Quantity":1,"UnitAmount":21.34,"AccountCode":"202","TaxType":"NONE","LineAmount":21.34}],"CurrencyCode":"GBP","Status":"DRAFT"}

I get the error

{
  "errorMessage": "Bad request - please check your parameters",
  "errorDescription": "A validation exception occurred",
  "errorDetails": {
    "rawErrorMessage": [
      "400 - \"{\\r\\n  \\\"ErrorNumber\\\": 10,\\r\\n  \\\"Type\\\": \\\"ValidationException\\\",\\r\\n  \\\"Message\\\": \\\"A validation exception occurred\\\",\\r\\n  \\\"Elements\\\": [\\r\\n    {\\r\\n      \\\"InvoiceID\\\": \\\"00000000-0000-0000-0000-000000000000\\\",\\r\\n      \\\"Payments\\\": [],\\r\\n      \\\"CreditNotes\\\": [],\\r\\n      \\\"Prepayments\\\": [],\\r\\n      \\\"Overpayments\\\": [],\\r\\n      \\\"IsDiscounted\\\": false,\\r\\n      \\\"InvoiceAddresses\\\": [],\\r\\n      \\\"HasErrors\\\": true,\\r\\n      \\\"InvoicePaymentServices\\\": [],\\r\\n      \\\"Status\\\": \\\"DRAFT\\\",\\r\\n      \\\"LineItems\\\": [],\\r\\n      \\\"ValidationErrors\\\": [\\r\\n        {\\r\\n          \\\"Message\\\": \\\"Invoice Type must be specified\\\"\\r\\n        }\\r\\n      ]\\r\\n    }\\r\\n  ]\\r\\n}\""
    ],
    "httpCode": "400"
  },
  "n8nDetails": {
    "nodeName": "HTTP Request",
    "nodeType": "n8n-nodes-base.httpRequest",
    "nodeVersion": 4.2,
    "itemIndex": 0,
    "time": "05/12/2024, 00:08:09",
    "n8nVersion": "1.69.2 (Self Hosted)",
    "binaryDataMode": "default",
    "stackTrace": [
      "NodeApiError: Bad request - please check your parameters",
      "    at Object.requestWithAuthentication (C:\\Users\\sales\\AppData\\Roaming\\npm\\node_modules\\n8n\\node_modules\\n8n-core\\src\\NodeExecuteFunctions.ts:2020:10)",
      "    at processTicksAndRejections (node:internal/process/task_queues:95:5)",
      "    at Object.requestWithAuthentication (C:\\Users\\sales\\AppData\\Roaming\\npm\\node_modules\\n8n\\node_modules\\n8n-core\\src\\NodeExecuteFunctions.ts:3324:11)"
    ]
  }
}

If I paste in the json ( which is the same json that works in the explorer ) it fails.

What am I missing here please.

hi @Steve_Warburton

Sorry for the late reply on this one. Can you share more details on what you’re trying to achieve here, are you trying to update Xero with a couple of invoices? What is the exact JSON you use in the explorer that works? Can you try making a raw curl using postman or some other tool besides our HTTP node?

If that fails as well, then it’s not related to the node but to the API call itself.

Thanks!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.