FROM CACHE - en_header

Fetch public URL to store logo using Shopify Python API

devdude
Excursionist
23 1 19

 

Hello!

 

I am almost succeeding in fetching the public URL of the store logo using Python API. I do the following:

 

import shopify

# [...] I authenticate and prepare session. I also have the correct permissions (scopes)


def get_asset(self, path):
    shopify_schema_prefix="shopify://"
    if path.startswith(shopify_schema_prefix):
        path=path[len(shopify_schema_prefix):]
        logger.warn(f"naked path is {path}")
    raw=shopify.Asset.find(path, fields="value").to_dict()
    value=raw.get("value", {})
    asset=json.loads(value)
    return asset

def get_logo(self):
    settings_path="config/settings_data.json"
    asset=get_asset(self, settings_path)
    logo_local=asset.get("current", {}).get("sections", {}).get("header", {}).get("settings", {}).get("logo")
    if not logo_local:
        logger.warn("no logo_local found")
    # Now logo_local contains the url of the logo in shopify form (shopify://shop_images/my_logo.jpeg)
    # THE NEXT STEP FAILS:
    public_logo=get_asset(self, logo_local)
    return public_logo

 

Callling get_logo() fails with the following error:

Not Found: https://my-shop.myshopify.com/admin/api/2021-04/assets.json?asset%5Bkey%5D=shop_images%2Fmy_logo.jpeg&fields=value 

at the marked line in get_logo()

 

My observations so far;

  1. The logo is clearly set in header. Before setting a logo image in the theme, the current->sections->header->settings->logo entry is empty
  2. I get the local shopify:// url of the logo successfully. The returned value in my case is "shopify://shop_images/my_logo.jpeg"
  3. The local shopify:// url of the logo is not a valid key to fetch an asset

Given "shopify://shop_images/my_logo.jpeg", how can I proceed to get the public URL of the store logo resource?

 

Any help is welcome!

 

https://www.merchbot.net
Replies 0 (0)