2

我一直在尝试使用 shopify_api gem 上传资产。我确保我有适当的 OAuth2 范围(write_themes),并且阅读甚至销毁它们都没有问题。问题是我在尝试创建或更新资产时收到 404 错误。

这是 gem 正在创建的请求:

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当然,包装在 a 中):

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

有任何想法吗?

4

2 回答 2

4

这对我有用...

上传到已发布的主题(未提供主题 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)
于 2014-02-25T18:03:15.423 回答
0

回复似乎很晚,但我正在回答这个问题,以便帮助其他面临类似问题的开发人员。

如果您设置了 shopify_app gem,那么您可以通过以下方式访问 rails 上的资产 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})

您可以在此处找到详细说明

于 2018-07-13T08:01:39.310 回答