erpnext.stock.stock_ledger.NegativeStockError when adding sales invoice via API

When I check update_stock and submit a sales invoice it works fine. But when I do the same with the API it gives me a negative stock error

Same here