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

Newman2023
Shopify Partner
15 0 2

 

 

#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()

 

 

 

Reply 1 (1)

michael-helium
Shopify Expert
356 5 176

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

Michael, COO @ Helium
- Customer Fields ✪✪✪✪✪ (346 reviews)
- Meteor Mega Menu ✪✪✪✪✪ (265 reviews)