Xero - beautiful accounting software

Xero Developer Help Center

Xero Developer Community

Community > Wrapper libraries >

Contact Validation Error Creating Invoice

Started by Steve N -   in Wrapper libraries

I'm having a strange issue using Xero Oauth on Laravel to create invoices. It only seems to be affect some invoices though but there doesn't seem to be a pattern.

So my connectiont to Xero and the correct tenant is fine and I can read the contact successfully and the contact record looks fine. I then create an invoice object using that contact and if I dump the invoice it shows all the correct contact data so it all looks good.

I then create the invoice in Xero and get a 200 response back but with a validation error of 'The Contact must contain at least 1 of the following elements to identify the contact: Name, ContactID, ContactNumber'

Looking at the response I get back the contact data is all null (other than a contact ID of 00000000-0000-0000-0000-000000000000) so the invoice isn't created and also has an ID of 00000000-0000-0000-0000-00000000000.

So I'm not sure where it's going wrong. I'm retrieving the correct contact from Xero, creating an invoice using that contact and the invoice object looks fine. In the developer portal I can see the history and getting the contact and creating the invoice are both showing with a status of 200 but somewhere the contact seems to be being lost when I create the invoice. Here's the code (I've omitted the $lineItems code but they seem fine)

This code is provided by the developer community - Xero does not warrant it in any way


So most invoices work but some don't and the ones that don't look like they are just losing the contact at the point I run createInvoices()

Any ideas?

Thanks
Most every function enables the batch creation of objects.. You are still getting a 200 even though the invoice is not created due to the summarizeErrors option.

This is so you could theoretically post 50 invoices where 49 succeeded and 1 failed and still write that data in. If you want the entire payload to fail you can set the summarize option to true.

If you do:

?summarizeErrors=false

This ensures that every entity is returned back to you, each having their own status attribute and the whole call will be a 200 OK regardless if the POST succeeded.

https://developer.xero.com/documentation/api/requests-and-responses#format-switch-placeholder:~:text=Creating%20many%20resources

If you have a validation error in any of your objects you will receive a HTTP 200 status code (rather than HTTP 400) if you are using the summarizeErrors parameter
 

Christopher Knight (Xero Staff)  

Thanks Christopher.

That makes perfect sense now. I guess the API call can be successful even if the transactions are not.

I think my main problem was it looked like I was passing a contact to my invoice object but actually I was passing a collection or array of contacts even though it only contained one contact.

Thanks again!
 

Steve N  

Yes of course! Also want to call out that there is a 'history' tab for every api app int he myapps dashboard.

This is really helpful to see API logs that are going through an SDK and being able to see raw JSON responses while debugging.

https://developer.xero.com/app/apphistory/app-uuid
 

Christopher Knight (Xero Staff)