admin 管理员组文章数量: 1086019
I'm using froatsnook:shopify trying to modify a custom collection's metafields.
Server JS
/**
* Modify Shopify Custom Collection Metafields
* @request PUT /admin/custom_collections/#{id}.json
*
* @param {Number} collection_id
* @param {Object} collection_data
* @param {Function} callback
*/
modifyShopifyCustomCollectionMetafields: function(collection_id, collection_data, callback) {
var meta = ShopifyAPI.modifyCustomCollection({
id: collection_id,
custom_collection : JSON.stringify( collection_data )
})
if ( AdminConfig.debug.server ) console.log( 'modifyShopifyCustomCollectionMetafields', meta )
if ( callback ) callback( meta )
return meta;
},
Client JS
Meteor.call('modifyShopifyCustomCollectionMetafields', collection_id, {
'id': collection_id,
'metafields' : [
{
'key' : 'color_primary',
'value' : design_settings.colors.primary,
'value_type' : 'string',
'namespace' : 'store',
},
{
'key' : 'color_dark',
'value' : design_settings.colors.primary_dark,
'value_type' : 'string',
'namespace' : 'store',
},
{
'key' : 'color_light',
'value' : design_settings.colors.primary_light,
'value_type' : 'string',
'namespace' : 'store',
},
]
}, function (data) {
console.log( 'Clientside callback', data )
})
All looks fine to be, but then I get this in the (server) console:
PUT https://<MY_STORE_NAME>.myshopify/admin/custom_collections/42393729.json?custom_collection={"id":"42393729","metafields":[{"key":"color_primary","value":"#5c28a4","value_type":"string","namespace":"store"},{"key":"color_dark","value":"#401a74","value_type":"string","namespace":"store"},{"key":"color_light","value":"#a42da8","value_type":"string","namespace":"store"}]}
Exception while invoking method 'modifyShopifyCustomCollectionMetafields' Error: failed [400] {"errors":{"custom_collection":"expected String to be a Hash"}}
Note that if I remove JSON.stringify(...)
from the serverside JS, it will try to send [Object object]
in the request URI.
Any ideas?
I'm using froatsnook:shopify trying to modify a custom collection's metafields.
Server JS
/**
* Modify Shopify Custom Collection Metafields
* @request PUT /admin/custom_collections/#{id}.json
*
* @param {Number} collection_id
* @param {Object} collection_data
* @param {Function} callback
*/
modifyShopifyCustomCollectionMetafields: function(collection_id, collection_data, callback) {
var meta = ShopifyAPI.modifyCustomCollection({
id: collection_id,
custom_collection : JSON.stringify( collection_data )
})
if ( AdminConfig.debug.server ) console.log( 'modifyShopifyCustomCollectionMetafields', meta )
if ( callback ) callback( meta )
return meta;
},
Client JS
Meteor.call('modifyShopifyCustomCollectionMetafields', collection_id, {
'id': collection_id,
'metafields' : [
{
'key' : 'color_primary',
'value' : design_settings.colors.primary,
'value_type' : 'string',
'namespace' : 'store',
},
{
'key' : 'color_dark',
'value' : design_settings.colors.primary_dark,
'value_type' : 'string',
'namespace' : 'store',
},
{
'key' : 'color_light',
'value' : design_settings.colors.primary_light,
'value_type' : 'string',
'namespace' : 'store',
},
]
}, function (data) {
console.log( 'Clientside callback', data )
})
All looks fine to be, but then I get this in the (server) console:
PUT https://<MY_STORE_NAME>.myshopify./admin/custom_collections/42393729.json?custom_collection={"id":"42393729","metafields":[{"key":"color_primary","value":"#5c28a4","value_type":"string","namespace":"store"},{"key":"color_dark","value":"#401a74","value_type":"string","namespace":"store"},{"key":"color_light","value":"#a42da8","value_type":"string","namespace":"store"}]}
Exception while invoking method 'modifyShopifyCustomCollectionMetafields' Error: failed [400] {"errors":{"custom_collection":"expected String to be a Hash"}}
Note that if I remove JSON.stringify(...)
from the serverside JS, it will try to send [Object object]
in the request URI.
Any ideas?
Share Improve this question asked Jun 10, 2015 at 21:22 elzielzi 5,7027 gold badges39 silver badges62 bronze badges2 Answers
Reset to default 5 +25I think there may be a bug in the package. Have you successfully used the API to POST before? I'm not sure if the issue is in scope for all POST requests, or for only some (using the awesome froatsnook package).
I've made an issue where I too, faced a POST request that returned "string expects to be a hash".
I'm temporarily sidestepping this issue by using plain old HTTP.Post and passing in an object with what the Shopify API specifically asks for:
var options = {
data: params,
headers: {
'X-Shopify-Access-Token': Meteor.user().profile.shopifyAccessToken
}
};
var newScript = HTTP.post("https://" + Meteor.user().profile.shopName + ".myshopify./admin/script_tags.json" , options);
See ment on @ilrein question for details.
Appears to be an issue with package itself.
Here is a simple client API (for private apps with basic auth) I made to circumvent the issue: Github gist
本文标签: javascriptmeteorshopifyexpected String to be a HashStack Overflow
版权声明:本文标题:javascript - meteor-shopify : expected String to be a Hash - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744020734a2519690.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论