REST API to upsert invoice line items
I need to be able to upsert line items in a NetSuite invoice with updated information from an external system.
I’ve tried to apply an internalId and externalId to the line item so I can target for update, however it doesn’t appear to be saved against the line item when GETing it back from the API.
My invoice creation payload is
{ "tranDate": "2021-07-12", "dueDate": "2021-07-19", "externalId": "sysA_INV-34698", "amountPaid": 0, "entity": { "id": 3127 }, "item": { "items": [ { "item": { "id": 374 }, "internalId": "sysA_INV-34698_JOBID-4875398" "quantity": 1, "rate": 534.54 } ] } }
any ideas how I can update/upsert a line item, or do I have to delete all items and re add them every time?
Upsert is not an option while Working with Sublists. You need to know which line you are matching against.
Right thanks – so the flow would be (Option 1)
- Get all line items of the invoice using the endpoint at GET /record/v1/invoice/3210/item
- Query each one (endpoint: GET /record/v1/invoice/3210/item/15, 16, 17, etc) and figure out if any change needs to be applied
- Make the change using PUT on /record/v1/invoice/3210/item/15, 16, 17, etc
Or Option 2, I could just
- Delete all line items
- Recreate them
Are there any disadvantages to doing Option 2?
Removing lines is equivalent to deleting and recreating the lines in the ui, the link betweeen the parent line is lost.
You also want to look at the linked documentation closer, you dont update individual lines