【发布时间】:2015-06-10 21:22:59
【问题描述】:
我正在使用froatsnook:shopify 尝试修改自定义集合的元字段。
服务器 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;
},
客户端 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 )
})
一切看起来都很好,但是我在(服务器)控制台中得到了这个:
PUT https://<MY_STORE_NAME>.myshopify.com/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"}]}
调用方法 'modifyShopifyCustomCollectionMetafields' 时出现异常错误:失败 [400] {"errors":{"custom_collection":"expected String to be a Hash"}}
请注意,如果我从服务器端 JS 中删除 JSON.stringify(...),它将尝试在请求 URI 中发送 [Object object]。
有什么想法吗?
【问题讨论】:
标签: javascript meteor shopify