We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

Private Shopify API APP in Python

Private Shopify API APP in Python

andreb
Shopify Partner
3 0 0

Hello guys,

 

is there a problem, when I didn't use the Shopify Api like this:

 

  1. First create a new application in either the partners admin or your store admin. For a private App you’ll need the API_KEY and the PASSWORD otherwise you’ll need the API_KEY and SHARED_SECRET.

  2. For a private App you just need to set the base site url as follows:

    python
    shop_url = "https://%s:%s@SHOP_NAME.myshopify.com/admin" % (API_KEY, PASSWORD)
    shopify.ShopifyResource.set_site(shop_url)

    That’s it you’re done, skip to step 6 and start using the API! For a partner App you will need to supply two parameters to the Session class before you instantiate it:

    python
    shopify.Session.setup(api_key=API_KEY, secret=SHARED_SECRET)

 

  1. Now you’re ready to make authorized API requests to your shop! Data is returned as ActiveResource instances:

    python
    shop = shopify.Shop.current
    
    # Get a specific product
    product = shopify.Product.find(179761209)
    
    # Create a new product
    new_product = shopify.Product()
    new_product.title = "Burton Custom Freestyle 151"
    new_product.product_type = "Snowboard"
    new_product.vendor = "Burton"
    success = new_product.save() #returns false if the record is invalid
    # or
    if new_product.errors:
        #something went wrong, see new_product.errors.full_messages() for example
    
    # Update a product
    product.handle = "burton-snowboard"
    product.save()

    Alternatively, you can use temp to initialize a Session and execute a command which also handles temporarily setting ActiveResource::Base.site:

    python
    with shopify.Session.temp("SHOP_NAME.myshopify.com", token):
       product = shopify.Product.find()

 like they write it in the doc?

 

Now I use the API KEY with requests, like this:

 

 
api_endpoint = f"https://{api_key}:{password}@{shopname}.myshopify.com/admin/api/2024-01/orders.json"
response = requests.get(api_endpoint)
 
Is there a problem? Where is the difference?
Replies 0 (0)