Jump to content

Weird 422 errors when POST'ing sales_invoices


 Share

Recommended Posts

So I am having huge issues with the creation of sales invoices.

It seems to me, that especially the fields 'invoice_number_prefix' and  'invoice_number' are highly problematic.
It is nowhere documented, how these 2 values should look like and I wasted hours playing around with these 2 values, until the API would eventually accept my requests.
But now I am still running into 422 errors all the time, which is highly frustrating for our customers! This is a huge issue for us and I have no way to debug this due to the very poor error reporting of the sage API.

I attached 2 different JSON bodies I sent to the endpoint - one worked, one didn't ... and I don't understand why at all!

Can someone help? What is going on with the 2 attributes I talked about? What are the limitations on these? How can I finally solve this weird issue?

Thank you, best,
Patrick

 

----

Worked:

worked.thumb.png.64ff6546244a41be646beaec3807ff26.png

 

Error:

error.thumb.png.d63916d67c7e0a26506f73fb4c39d1b2.png

Edited by Patrick Schubert
Link to comment
Share on other sites

And yes, the "error JSON" indeed actually contained a lot more 'invoice_lines', but I checked all of them and I think, all contain correct sage products with IDs and everything. ONE difference is, that the error JSON contained a mixture of products with different 'leadger_account_id's and different 'tax_rate_id's - could this be a problem?

Again: PLEASE improve your error logging - with a huge JSON body like this request, just getting a "422 error" is highly infuriating, unprofessional und frustrating, as debugging this becomes pure hell!

Link to comment
Share on other sites

Hi Patrick,

Thank you for your question. The API reference generated from the swagger is something we're hoping to improve over the coming months. Ideally the changes will provide a greater insight about the individual parameters.

The prefix would generally be setup by the business who is using your integration through the UI's settings > business settings > Document preferences and would not be passed in the sales_invoice POST request. I've attached an image for your information.

The idea is that you create an invoice and the invoice will be created with the prefix in the settings. Are you needing to change the prefix on a regular basis?
API access to this setting is available in the invoice_settings API.


Thanks

Mark

 

Screenshot 2023-02-02 at 09.19.49.png

Link to comment
Share on other sites

Hello,

Thank you for your reply Mark! This makes sense!

But this still does not explain to me, why some of the sales_invoices I create via the API do get through, and others are not accepted and return a 422 error.

The problem I have is the following:

I need a separate prefix compared to all the other sales invoices, because the suppliers we are working with are creating sales invoices also manually because not ALL the sales is done via our platform.

This means, that a supplier might already have an invoice with the number 2300057 in his system, because he created an invoice manually. When I now try to POST a sales invoice with the same number via the API, I would run into an error because the invoice number already exists. This is why I thought I could define my own prefix ("OL" = Orderlion, the name of our platform) to avoid this issue altogether.

Should I just remove both 'invoice_number_prefix' AND 'invoice_number' from my API requests to force Sage to create its own invoice number? Would this work?
If yes, is there any other nice way to basically flag the invoice as an "Orderlion invoice", so our supplier have some way of separating all their "normal" invoices from the Orderlion ones?

Thank you, best, Patrick

Edited by Patrick Schubert
Link to comment
Share on other sites

Hi Patrick,

To clarify, you have suppliers who are raising sales invoices on your behalf using a prefix associated with themselves and then sending you both the sales_invoice and their supplier/vendor purchase_invoice?

Your idea of removing the invoice_number AND prefix should resolve the 422 you're seeing. In order to keep a level of traceability you'll need to ideally add the suppliers sales_invoice in the reference field of the sales_invoice you're posting or if this is in use for another purpose you could add details of the transaction in the notes field.

If the reference was used, a user of SBCA would then be able to filter the invoice list for those relating to the supplier by editing the configurable columns and selecting the reference field as per the images.

Let me know if i've missed the mark with the requirements here.

Thanks

Mark

 

Screenshot 2023-02-03 at 08.45.52.png

Screenshot 2023-02-03 at 08.45.03.png

Screenshot 2023-02-03 at 08.43.35.png

Screenshot 2023-02-03 at 08.43.04.png

  • Like 1
Link to comment
Share on other sites

Hello Mark,

I removed the 'invoice_number_prefix' and the 'invoice_number' completely now ... the API is still completely random and throwing 422 errors at will!!

We are losing customers to this, the supplier in question quit our service now because we can't get the damn Sage API to work. Please help!!

Here is another error body:
error-2.thumb.png.9774f942502817b91c873c07cdfd7b8d.png

 

What is going on? I am freaking out here! 😞 It is totally random, another JSON body couple minutes earlier worked just fine!!

Worked:

worked-2.thumb.png.2fab3fc7e29643805da2ee6bf0e520ab.png

 

Again, please help!

best, Patrick

Link to comment
Share on other sites

Okay now I cross checked even the invoice_lines of the 2 orders again. Of course there are different products in there, but I just for the life of me can't find any errors. 

I made sure the 'ledger_account_id's are correct, the 'tax_rate_id's, ... and I ALWAYS set 'tax_amount' to 0. I really don't understand this, this API, in my mind, has completely random behavior.

I really hope someone can help me, I am completely lost ...

Link to comment
Share on other sites

Is there any other restriction built into Sage, which could prevent me creating a sales_invoice for a certain customer (contact_id) via the API which would result in a 422 error? I can't think of anything ...

Is it a problem, if I set 'date' and 'due_date' to the same date? does this date have to be in the future, could it be today, ... are there any other restrictions I don't see?!

we have 5 developers on the team who already invested hours into this and we didn't make any progress at all ...

Edited by Patrick Schubert
Link to comment
Share on other sites

Hi Patrick,

Could you send me a direct message with your client_id and either the business_id or the email address of the business returning the 422 error response.
Could you also provide me with the registered location of the business please.

There's no problem using a due_date which is the same as that of the invoice date. The only rule with a due_date is that it is not earlier than the invoice_date. 

Thanks

Mark

  • Like 1
Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...