Shopify-cli node app express product.save({}) returns undefined

Hi guys im trying to create a product using nodejs shopify library and get its variant id but the return value is undefined.

import {Product} from '@shopify/shopify-api/dist/rest-resources/2022-04/index.js';
const test_session = await Shopify.Utils.loadCurrentSession(request, response);
const product = new Product({session: test_session});
product.title = "Burton Custom Freestyle 151";
product.body_html = "**Good snowboard!**";
product.vendor = "Burton";
product.product_type = "Snowboard";
product.published = false;
const outdata = await product.save({});

The product is created but outdata is undefined;

Thanks in advance for any help.

Found it! i used save and update like below

import {Product} from '@shopify/shopify-api/dist/rest-resources/2022-04/index.js';
const test_session = await Shopify.Utils.loadCurrentSession(request, response);
const product = new Product({session: test_session});
product.title = "Burton Custom Freestyle 151";
product.body_html = "**Good snowboard!**";
product.vendor = "Burton";
product.product_type = "Snowboard";
product.published = false;
await product.saveAndUpdate({});
res.status(200).send(product);
3 Likes

Hi AnthonyCy,

I have use both cases but it’s returning undefind again. Here is my Code.

const { Product } = await import(
@shopify/shopify-api/dist/rest-resources/2022-10/index.js
);

const session = await Shopify.Utils.loadCurrentSession(
req,
res,
app.get(“use-online-tokens”)
);

// console.log(“hitets”,session)
const product = new Product({ session });
product.title = “Burton Custom Freestyle 151”;
product.body_html = “Good snowboard!”;
product.vendor = “Burton”;
product.product_type = “Snowboard”;
product.tags = [
“Barnes & Noble”,
“Big Air”,
“John’s Fav”
];
// await product.save()
await product.saveAndUpdate({})
.then((rData)=>console.log(“restData”,rData))
.catch((err)=>console.log(‘err’,err));

I was facing the same issue and the promise return undefined but later I figured out that the product object itself is updated with response data. Try returning the “product” object or try console.log(product) and you will get response data.