【问题标题】:create theme on shopify using api使用 api 在 shopify 上创建主题
【发布时间】:2020-02-22 00:35:45
【问题描述】:

我正在尝试创建一个应用程序,并且用户可以在应用程序内安装一个主题,但是,我似乎无法弄清楚为什么没有创建主题。它不断将已安装在我的商店中的主题拉到控制台,我的代码似乎没有创建会显示在我的 shopify 商店中的主题。

server.js

    router.post('/api/theme', async (ctx) => {

    try {

      const results = await fetch("https://" + ctx.cookies.get('shopOrigin') + "/admin/themes.json", {
        headers: {
          'X-Shopify-Access-Token': ctx.cookies.get('accessToken')
        },

      })
        .then(response => response.json())
        .then(json => {
          console.log("https://" + ctx.cookies.get('shopOrigin') + "/admin/api/2020-01/themes.json", json);
        });


      ctx.body = { 
          data: results
      };


    } catch (err) {
      console.log(err)
    }
  });

前端 .js 文件

 async function getUser() {
        var url = `/api/theme`;
        var method = 'post';
        const theme = {
            theme: {
                name: "Lemongrass",
                src: "https://codeload.github.com/Shopify/skeleton-theme/zip/master"
                }
        };
      const data = JSON.stringify(theme);
      fetch(url, { method: method, body: data})
    }

【问题讨论】:

    标签: node.js reactjs api shopify shopify-app


    【解决方案1】:

    为了创建一个主题,您需要一个您喜欢创建的主题的 zip 存档。

    终点应该是/admin/api/2020-01/themes.json,正文应该是这样的:

    {
      "theme": {
        "name": "Theme name",
        "src": "http://themes.shopify.com/theme.zip",
        "role": "unpublished"
      }
    }
    

    更多信息请参考https://shopify.dev/docs/admin-api/rest/reference/online-store/theme#create-2020-01

    目前,从您的代码中,我既没有看到正确的 POST 请求,也没有看到存档文件。

    【讨论】:

    • 感谢您回复我,我已使用前端文件中的代码更新了我的问题。当我运行代码时,它会在我的控制台上打印出themes.json 文件,但是,我似乎无法得到它,所以我的主题被添加到了themes.json。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-11-18
    • 2017-11-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-04
    相关资源
    最近更新 更多