Solved

Asset API axios call example please

James_J
Shopify Partner
38 3 6

 

Hello,

 

I would like to call assets.json as described here: https://shopify.dev/api/admin-rest/2021-10/resources/asset#get-themes-theme-id-assets

 

However, I can only call "/products" endpoint with Axios. Maybe I missed something but I don't know what should I do because there is no whole code in the document. 

 

Please give me an Axios asset API call example. I use React/Node.js

Thank you.

Accepted Solution (1)

James_J
Shopify Partner
38 3 6

This is an accepted solution.

After hard googling, I found that my app needs to make a read_themes permission request to the user.


Here is my solution. https://codesandbox.io/s/exapp-eppyvq?file=/src/index.js
I've only uploaded part of the source code for security.

After requesting /theme, you can get a list of themes, and then select a specific theme (e.g. live theme currently in service) and use it.

 

Shopify is very unfriendly to app developers.

View solution in original post

Replies 2 (2)

James_J
Shopify Partner
38 3 6

This is an accepted solution.

After hard googling, I found that my app needs to make a read_themes permission request to the user.


Here is my solution. https://codesandbox.io/s/exapp-eppyvq?file=/src/index.js
I've only uploaded part of the source code for security.

After requesting /theme, you can get a list of themes, and then select a specific theme (e.g. live theme currently in service) and use it.

 

Shopify is very unfriendly to app developers.

James_J
Shopify Partner
38 3 6

Plus, you need to setup middleware server that requests to Shopify Database Server with access token.

 
For example,

 

 

  router.get("/assets", async (ctx) => {
    const session = await Shopify.Utils.loadCurrentSession(ctx.req, ctx.res);
    // Create a new client for the specified shop.
    const client = new Shopify.Clients.Rest(session.shop, session.accessToken);
    // Use `client.get` to request the specified Shopify REST API endpoint.
    const data = await client.get({
      path: 'assets',
    });

    ctx.body = data;
    ctx.status = 200;
  });