我一直在尝试使用shopify_api gem上传资源。我确保我有适当的OAuth2范围(write_themes),我没有阅读甚至销毁它们的问题。问题是我在尝试创建或更新资产时遇到404错误。
以下是宝石创建的请求:
PUT: /admin/themes/3650318/assets.json [{"Content-Type"=>"application/json", "User-Agent"=>"ShopifyAPI/3.0.3 ActiveResource/4.0.0.beta1 Ruby/2.0.0", "X-Shopify-Access-Token"=>"ommitted"}] ({"key":"templates/index.liquid","attachment":"base64 attachment omitted"})
供参考,以下是我用于发出请求的代码(当然包含在ShopifyAPI::Session
中):
ShopifyAPI::Asset.create(key: 'snippets/test.liquid', attachment: some_base64_data, theme_id: 3650318)
或者:
asset = ShopifyAPI::Asset.new(key: 'snippets/test.liquid', attachment: baset64_data, theme_id: 3650318)
asset.save
有什么想法吗?
答案 0 :(得分:1)
这对我有用......
上传到已发布的主题(未给出主题ID)
a = ShopifyAPI::Asset.new
a.key = "assets/google.png"
a.src = "https://www.google.co.uk/images/srpr/logo11w.png"
a.save
或
ShopifyAPI::Asset.create(key: 'assets/google.png', src: "https://www.google.co.uk/images/srpr/logo11w.png")
上传到特定主题
a = ShopifyAPI::Asset.new
a.key = "assets/google.png"
a.src = "https://www.google.co.uk/images/srpr/logo11w.png"
a.prefix_options[:theme_id] = "6731537"
a.save
或
ShopifyAPI::Asset.create(key: 'assets/google.png', src: "https://www.google.co.uk/images/srpr/logo11w.png", theme_id: 6731537)
答案 1 :(得分:0)
回复似乎很晚,但是我正在回答这个问题,这样可以帮助其他面临类似问题的开发人员。
如果您设置了shopify_app gem,则可以通过
访问rails上的Asset API。#This will access the asset of live theme
@assets = ShopifyAPI::Asset.find(:all)
#or if you want to access the asset of particular theme.
@assets = ShopifyAPI::Asset.find(:all, params: {"theme_id": themeid})
您可以找到详细说明here