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.