[英]404 error when writing to a Shopify asset
我一直在尝试使用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
中):
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
有任何想法吗?
这对我有用...
上传到已发布的主题(未提供主题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)
答复似乎很晚了,但我正在回答这个问题,这样将有助于其他面临类似问题的开发人员。
如果您设置了shopify_app gem,则可以通过以下方式访问资产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})
您可以在这里找到详细说明
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.