How can i update product variants? Please help me

Topic summary

Developer seeks help updating Shopify product variants via a custom app, mentioning intent to use product update metafields but showing code that directly updates a variant’s inventory quantity.

  • Context: Using Shopify Admin REST API (resources.Product.find) within an action; authenticates admin, reads formData, fetches a product by ID, then calls product.save({ update: true }).
  • Current code: Overwrites product.variants with one entry where both variant id and inventory_quantity are set by parsing the same form field (variantValue).
  • Goal/ask: Guidance on the correct way to update product variants (and/or via metafields) and how to properly structure the update.
  • Artifacts: A code snippet is central to understanding the issue.
  • Status: No answers or resolution yet; the request remains open.
Summarized with AI on January 9. AI used: gpt-5.

I have developed a shopify app. The app feature is to update the product variables using product update metafiled
My demo code is bellow :

export const action = async ({ request }) => {

const { admin, session } = await authenticate.admin(request);
const prodiuctData = Object.fromEntries(await request.formData());

const product = await admin.rest.resources.Product.find({
session: session,
id: prodiuctData.productID,
});

product.variants = [
{
id: parseInt(prodiuctData.variantValue),
inventory_quantity: parseInt(prodiuctData.variantValue),
},
];

await product.save({
update: true,
});

console.log(product);

return json(null);
};

Can anyone please help me.