Magento Product Create via API not working

Magento Product Create via API not working

August 31, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento Product Create via API not working

Magento API Product Creation: Debugging SOAP Faults

Are you facing challenges when trying to create new products via the Magento SOAP API? You’re not alone. The Magento SOAP API can be quirky and sometimes throws misleading errors that don’t immediately point you in the right direction. Let’s dive into a common issue - the “Invalid data given” error.

Understanding the Error Message

When you see an “Invalid data given” message, it typically means one of two things:

  1. Missing required fields: The API expects certain fields to be present for product creation, and if they’re missing or incorrectly formatted, it will throw this generic error.
  2. Incorrect data types: Even though the documentation might not explicitly specify a field’s data type, the API is often strict about what it accepts.

Analyzing Your Code

Let’s break down your provided code snippet to see where the issue might lie:

// product creation
$client->call($session, 'product.create', array('simple', $set['set_id'], $ItemNmbr, $newProductData));

The product.create method expects an array of arguments in this specific order:

  • Product type (e.g., ‘simple’)
  • Attribute set ID
  • SKU
  • Product data

It seems like you’re passing the correct parameters in your array. However, let’s look at $newProductData:

$newProductData = array(
    'name'              => 'Test product',
    'websites'          => array(1),
    'short_description' => 'This is the short desc',
    'description'       => 'This is the long desc',
    'price'             => 150.00,
    'status'            => 1,
    'tax_class_id'      => 0,
    'visibility'        => 4
);

Common Issues and Solutions

Issue: Missing Required Fields

The product.create method requires a few fields that aren’t included in your $newProductData array, such as:

  • sku: You’ve used $ItemNmbr, but the API expects this field to be part of the product data.
  • stock_data: Magento 2 requires stock-related information for new products.

Issue: Incorrect Data Types

  • websites: Make sure this is an array of website IDs, not just a single integer. You can use array_keys($this->websiteCollection) to fetch the array.
  • status and visibility: These fields are integers that map to specific Magento constants (e.g., Mage_Catalog_Model_Product_Status::STATUS_ENABLED for status 1).

Solution: Fill in Missing Fields

Let’s update your $newProductData array:

$websiteIds = array_keys($this->websiteCollection); // Fetch website IDs

$newProductData = array(
    'sku'               => $ItemNmbr,
    'name'              => 'Test product',
    'websites'          => $websiteIds, // Use the fetched website IDs here
    'short_description' => 'This is the short desc',
    'description'       => 'This is the long desc',
    'price'             => 150.00,
    'status'            => Mage_Catalog_Model_Product_Status::STATUS_ENABLED,
    'tax_class_id'      => 0,
    'visibility'        => Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH,
    'stock_data'        => array(
        'is_in_stock'   => true,
        'qty'           => 100
    )
);

Solution: Use Correct Data Types

Ensure you’re using the correct data types for each field. You can refer to the official Magento documentation for a comprehensive list.

Conclusion

When dealing with “Invalid data given” errors in the Magento SOAP API, remember:

  1. Check required fields: Ensure all mandatory fields are present and correctly formatted.
  2. Use correct data types: Stick to the expected data types (e.g., integers, arrays).
  3. Fetch IDs properly: Use the appropriate methods to fetch website or attribute set IDs.

If you’re still stumped, consider exploring our in-depth guides on Magento API development for more detailed examples and best practices. Happy coding!

Catalog API Orders Errors

Our network