File size: 1,048 Bytes
33f5d2c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# shopify_client.py
import shopify
import os

SHOP_URL = "https://863c42fc4fc6eb9dd18c84dacb21374e:[email protected]/admin"
API_VERSION = "2023-10"

# Configure
shopify.ShopifyResource.set_site(f"{SHOP_URL}/api/{API_VERSION}")

def create_product(title: str, body_html: str, price: str, image_url: str):
    new_product = shopify.Product()
    new_product.title = title
    new_product.body_html = body_html
    new_product.variants = [shopify.Variant({'price': price})]
    new_product.images = [shopify.Image({'src': image_url})]
    success = new_product.save()
    if not success:
        raise Exception(new_product.errors.full_messages())
    return new_product.to_dict()

if __name__ == "__main__":
    # Example usage:
    prod = create_product(
        title="AI Fitness Mirror Decal",
        body_html="<strong>AI‑powered form correction in your own mirror.</strong>",
        price="49.99",
        image_url="https://example.com/decal.jpg"
    )
    print("Created product:", prod["id"])