FROM CACHE - en_header

how to get shop logo to use it into shopify app

Solved
janekbordo
Shopify Partner
2 0 2

Hi, 

 

I'm looking for some location where i could find client's shop logo to put it into my app in the future. Any ideas where to find it?

Regards

Accepted Solution (1)

Accepted Solutions
KarlOffenberger
Shopify Partner
1873 184 874

This is an accepted solution.

You can use the Assets API to fetch the store's current config

 

GET https://<STORE_NAME>.myshopify.com/admin/themes/<THEME_ID>/assets.json?asset[key]=config/settings_data.json

The logo setting, if defined, would be in 

 

{
  "current": {
    "sections": {
      "header": {
        "type": "header",
        "settings": {
          "logo": "shopify:\/\/shop_images\/a403eac45598213843f12eb307dce365.jpg"
        }
    }
  }
}

Which you can then use to reference with the Shopify CDN.

 

Hope this helps!

Liked this post? You might also like our fantastic upsell apps Candy Rack, Last Upsell post-purchase and Candy Cart or offer free gifts with Gift Box. All made with ❤️  and care by Digismoothie

View solution in original post

Replies 8 (8)
KarlOffenberger
Shopify Partner
1873 184 874

This is an accepted solution.

You can use the Assets API to fetch the store's current config

 

GET https://<STORE_NAME>.myshopify.com/admin/themes/<THEME_ID>/assets.json?asset[key]=config/settings_data.json

The logo setting, if defined, would be in 

 

{
  "current": {
    "sections": {
      "header": {
        "type": "header",
        "settings": {
          "logo": "shopify:\/\/shop_images\/a403eac45598213843f12eb307dce365.jpg"
        }
    }
  }
}

Which you can then use to reference with the Shopify CDN.

 

Hope this helps!

Liked this post? You might also like our fantastic upsell apps Candy Rack, Last Upsell post-purchase and Candy Cart or offer free gifts with Gift Box. All made with ❤️  and care by Digismoothie
janekbordo
Shopify Partner
2 0 2

Thanks a lot. Issue closed 🙂

Blkc
Tourist
9 1 5

Question related, how do I reference that logo string with shopify cdn?

 

I see that the src being used in my theme is https://cdn.shopify.com/s/files/1/0048/5113/8624/files/green-orange-and-yellow-ink_300x300.jpg

while the value I am seeing within assets.json is 

shopify:\\\/\\\/shop_images\\\/green-orange-and-yellow-ink.jpg\

 What is the url that allows me to actually get the image based on the above string?

 

Thanks in advance.

benjamin_bonnet
Shopify Partner
4 0 2

See here; It might require another api call to get the public url

silintzir
Shopify Partner
3 0 12

Did you ever manage to the real url from the CDN?

tim-a17
Tourist
5 0 4

I am also trying this out and have been unable to get the real URL from the CDN.

 

GET /admin/api/2020-04/themes/#{theme_id}/assets.json   <-- gives a list of assets, but not the logo file

 

If I go to https://{shop}.myshopify.com/admin/settings/files <-- gets the UI with list of images AND public URL

 

but as far as I can tell, there's no API to access the files, and https://{shop}.myshopify.com/admin/themes/{theme_id}/assets.json?asset[key]=config/settings_data.json  doesn't give you a public URL as indicated in this thread already.

 

Any suggestions?  How do we translate shopify:// into a public URL?  Thanks!

adroll-dev
Shopify Partner
1 0 0

To everyone asking "How can you reference the settings logo path with the Shopify CDN?" Here's how I did it:

1. As mentioned above, first get the almost entirely useless shopify path (e.x.) 

"shopify:\/\/shop_images\/MY_LOGO.jpg"

 - This has the name of the file (MY_LOGO.jpg), which we will use to find the full path of the file

2. Using paginated graph ql queries, fetch all the MediaImage files

  - In psuedo code this will look like this:

  

- initialize hasNextPage as True
- initialize cursor as False (because first query won't need a cursor)

- while hasNextPage is True:
- construct graphQl query
- if we have a cursor include it in our query
- else dont include cursor in query
- parse query results
- for each result, parse the file name
- if the file name matches the file name from our settings we found the logo
- return file path of matching file name
- if we have no matches after iterating over results
- set cursor value from query results
- set hasNextPage from query results

- if we reach outside while loop then we have no matches, return "no logo for user"

 

  - Your first query will not need a cursor, so it should look roughly like this:

{
files (first: 250 ) {
edges {
node {
createdAt
alt
... on MediaImage {
id
image {
id
originalSrc:
url
width
height
}
}
}
cursor
}
pageInfo {
hasNextPage
}
}
}

- Every query after that will use the after FileConnection argument (cursor) so we can pick up where we left off. E.x.

 

{
files (first: 250 after: "eyJsYXN0X2lkIjoyMjU0OTc4MTkwNTU0NCwibGFzdF92YWx1ZSI6IjIyNTQ5NzgxOTA1NTQ0In0=" ) {
edges {
node {
createdAt
alt
... on MediaImage {
id
image {
id
originalSrc:
url
width
height
}
}
}
cursor
}
pageInfo {
hasNextPage
}
}
}

- you will need to format your query correctly with each iteration of the while loop so it includes the previous queries cursor being provided as the value to after:

 

3. For each page of query results, see if we found a match (we check after each query because we don't want to query shopify if we don't have too)

  - iterate over each file in our list of files, if the name of the file matches the name of the file we found in our settings.... boom we found the logo

JohnFoxtrot
Shopify Partner
3 0 0

As of the 2022-10 release, the logo will be accessible via the Brand object. Please refer here:

https://shopify.dev/api/storefront/2022-10/objects/Brand