Why is the SKU missing when creating a product in my custom app?

Topic summary

A developer is building a custom Shopify app integrated with Moodle and encountering an issue where products are created successfully via the Shopify API, but the SKU field remains missing.

Root Cause Identified:
The SKU field belongs to the variant object, not the product object directly. The same applies to the price field.

Recommended Solution:

  • Create a default variant nested inside the product object
  • Specify the SKU and price within the variant array
  • The variant “title” field can be omitted

Current Status:
Despite implementing the suggested code structure with variants array containing SKU and price fields, the developer reports the product is still created without SKU or price, and no error messages are returned. The helper suggested catching error messages to debug further and requested additional details about the app being developed to provide more targeted assistance.

The issue remains unresolved with troubleshooting ongoing.

Summarized with AI on November 23. AI used: claude-sonnet-4-5-20250929.

I am creating a Shopify custom app while trying to create the product using the Shopify APP the product is created but SKU is missing.

How Can I add a product with the SKU, Please help?

$addProduct = array(‘title’ => $title, ‘body_html’ => $body_html, “sku” => $SKU);
$params = array(‘product’ => $addProduct);
$products = $shopify->call($token, $shop, “/admin/products.json”, $params, ‘POST’);

$product_response = json_decode($products[‘response’], TRUE);

hi @pankaj04 !

The SKU field belongs to the variant object, which is nested inside the product!

So you just have to create the default variant inside the product and specify the sku for it, also you would like to create a default variant for your new product in order to put a price on it as well, since the price field is still into the variant object and not into the product, like

$addProduct = array(
	"title" => $title,
	"body_html" => $body_html,
	"variants" => [
		[
			"title" => "Default Title",
			"sku" => $sku,
			"price" => $price
		]
	]
);

Hi @francesco_gs ,

Thank you for your response.

I use the same as you suggested but still, the SKU and price is missing from the product.

Hi @pankaj04 then you should try to catch any error message you may receive, cause the call is technically correct

you can also omit the “title” field in the “variant” object.

In order to give you some additional help you should share some details on the app you’re developing.

hi @francesco_gs

Actually, I am not getting any errors. The API created the product but the SKU is missing.

The APP I am creating is to integrate moodle and Shopify app.