Magento Sales Order Invoice with product quantity updation using API not working properly

Magento Sales Order Invoice with product quantity updation using API not working properly

September 25, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento Sales Order Invoice with product quantity updation using API not working properly

Title: Troubleshooting Magento Sales Order Invoice Creation via API: A Comprehensive Guide

As a seasoned developer working on a Magento application, you’ve encountered an intriguing challenge when attempting to create sales order invoices using the Magento API. Let’s dive into your predicament and explore potential solutions.

The Problem

You’re using the sales_order_invoice.create SOAP API method to generate invoices for existing orders. However, despite passing a valid $invoiceItems array containing SKUs and quantities, the created invoices remain empty—lacking any product details or specified quantities.

Here’s your current implementation:

$proxy = new SoapClient('http://myurl/api/soap?wsdl');
$sessionId = $proxy->login('apiuser', 'apikey');

// item array with sku and quantity
$invoiceItems = array(
    '002' => '1', '003' => '1', '004' => '1', '005' => '1'
);

// Create new invoice
$newInvoiceId = $proxy->call($sessionId, 'sales_order_invoice.create',
array($saleorderno, $invoiceItems, 'Invoice Created', true, true));

When you create an invoice without specifying any items ($invoiceItems = array()), the process works perfectly. This discrepancy leaves us scratching our heads.

Potential Causes and Solutions

  1. Incorrect API Method: Ensure you’re using the correct method for your specific Magento version. The sales_order_invoice.create method should work in most versions, but double-check the official Magento SOAP API documentation.

  2. API Permissions and Credentials: Verify that your API user (‘apiuser’) has sufficient permissions to create invoices. Additionally, ensure the provided ‘apikey’ is valid and hasn’t expired.

  3. Invoice Item Format: The $invoiceItems array should follow this format: array('sku1' => $quantity1, 'sku2' => $quantity2, ...). Make sure your SKUs are lowercase (as Magento is case-sensitive) and the quantities are integers.

$invoiceItems = array(
    '002' => 1, // SKU 002 with quantity 1
    '003' => 1, // SKU 003 with quantity 1
    ...
);
  1. Product Visibility and Status: Ensure that the products referenced by your SKUs are visible in the frontend and enabled in the backend.

  2. Magento API Logs: Enable Magento’s SOAP API logs to debug any potential issues during the request processing. You can find more information on Magestore’s blog.

Step-by-Step Solution

Here’s a step-by-step approach to resolve this issue:

  1. Double-check your Magento API credentials and ensure they have sufficient permissions.

  2. Verify that the referenced SKUs are valid, lowercase (if applicable), and correspond to enabled products in your catalog.

  3. Enable Magento SOAP API logs to monitor the request/response process for any clues about the issue.

  4. If everything seems correct, consider reaching out to Magento’s official support or a trusted third-party support provider for further assistance.

Conclusion

Investigating this issue requires a methodical approach that combines API debugging techniques and careful examination of your catalog setup. By following the steps outlined above, you should be able to identify and resolve the problem with invoice item quantity not being updated correctly via the Magento SOAP API.

Remember, the solution might lie in a combination of factors—API permissions, product visibility, or even subtle configuration issues. Stay patient, and don’t hesitate to consult official resources or expert support when needed.

Happy coding!

Catalog API Orders Errors

Our network