Script Is Not Working/Compiling on VSCode. Mistake - Please Help!

Topic summary

A user is attempting to create a Python script to bulk update inventory quantities to 100 (or another specified amount) for all products in their Shopify store, but the script fails to compile or execute in VSCode.

Key Issues Observed:

  • The code contains multiple SSL certificate configuration attempts that may conflict with each other
  • Hardcoded credentials (API keys and passwords) are partially visible in the shared code
  • The shop URL appears malformed (contains ‘/adimn’ instead of ‘/admin’)
  • Large portions of the code are written backwards/reversed (likely a copy-paste error), making it unreadable and non-functional

Current Status:

  • Another user (michael-helium) responded by suggesting a Shopify Community forum post about bulk updates via GraphQL API, though the link itself also appears corrupted/reversed
  • The discussion remains unresolved with no working solution provided yet
  • The original poster needs to fix the reversed code sections and correct the store URL before the script can function
Summarized with AI on November 16. AI used: claude-sonnet-4-5-20250929.

#I need a script to update all inventory to 100 or some quantity. 
#the script is not working. can someone help me please? 

# update_inventory.py
from urllib.parse import urlparse
import os
os.environ['REQUESTS_CA_BUNDLE'] = ''
import ssl
ssl._create_default_https_context = ssl._create_unverified_context

from urllib.error import URLError
import certifi
import ssl

ssl.create_default_context(cafile=certifi.where())
import os
import certifi

# Set the CA bundle path for SSL certificate verification
os.environ['REQUESTS_CA_BUNDLE'] = certifi.where()

# Now you can make your HTTPS requests
# ...

import os
os.environ['REQUESTS_CA_BUNDLE'] = ''

# Shopify Store Name
SHOP_NAME = 'https://f0b8c8-2.myshopify.com/adimn'  # Replace with your actual Shopify store name

# Shopify API Key
API_KEY = '***' # Replace with your Shopify API key

# Shopify API Password (not the same as your login password)
API_PASSWORD = '***'  # Replace with your Shopify API password

  
import certifi
import os
import shopify
import ssl

def main():
    # Authenticate with the Shopify store
    shopify.ShopifyResource.set_site('https://f0b8c8-2.myshopify.com/admin')
    shopify.ShopifyResource.set_user('***')
    shopify.ShopifyResource.set_password('****')

    # Fetch all products from the store
    products = shopify.Product.find()

    # Update inventory quantity for each product
    for product in products:
        update_product_inventory(product)

def update_product_inventory(product):
    try:
        # Specify the new inventory quantity (e.g., 1000)
        new_inventory_quantity = 1000

        # Update the inventory quantity for the product variant(s)
        for variant in product.variants:
            variant.inventory_quantity = new_inventory_quantity
            variant.save()

        print(f"Updated inventory for product: {product.title}")
    except Exception as e:
        print(f"Failed to update inventory for product {product.title}. Error: {str(e)}")

try:
  products = shopify.Product.find()
except URLError as e:
  print("Error: ", e)

# Import the GUI module
import gui

# Your main inventory updating code
def update_inventory():
    # Your inventory update logic here
    pass

if __name__ == "__main__":
    main()
1 Like

Does this forum post solve your problem? https://community.shopify.com/c/graphql-basics-and/how-to-make-bulk-updates-on-prices-and-quantities-via-api-on/td-p/1881271