Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

86
Views
How to set a policy/flag to stop a product from selling when out of stock

I'm really new to the Shopify API, and I'm working with someone else's code. I'm uploading a product trough my Shopify store, but I want to set some sort of policy where a product can't be sold when it's out of stock, is there a way this can be done on code?

Every time I create a product on Shopify, I do it like this:

static async createProductInShopify(product) {
    const createProductsURL = SHOPIFY_URL + '/products.json';
    const latestPrice = product.prices[product.prices.length - 1];

    const requestBody = {
        product: {
            title: product.name,
            body_html: product.body,
            vendor: 'My Store',
            product_type: 'Sample Product',
            handle: product.handle,
            tags: product.categories,
            images: [
                {
                    src: product.imageURL
                }
            ],
            variants: [
                {
                    option1: product.size ? 'Big' : 'Normal',
                    price: latestPrice,
                    requires_shipping: true,
                    taxable: false,
                    inventory_quantity: product.quantity,
                    inventory_management: 'shopify',
                    inventory_policy: 'continue'
                }
            ]
        }
    };

    const response = await ShopifyController.fetch(createProductsURL, requestBody, 'POST', product);

    const shopifyJSON = await response.json();
    product.productID = `${shopifyJSON.product.id}`;
    product.productVariantID = `${shopifyJSON.product.variants[0].id}`;
    product.inventoryLevelID = `${shopifyJSON.product.variants[0].inventory_item_id}`;
    await product.save();
    return product;
}

I assume that the inventory_policy is where that flag can be set, however, I need some confirmation to see if that is true.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

yes, the inventory_policy for product variant has to be set to something. i am sharing the screenshot for the value.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!