最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - meteor-shopify : expected String to be a Hash - Stack Overflow

programmeradmin6浏览0评论

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 badges
Add a ment  | 

2 Answers 2

Reset to default 5 +25

I 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

发布评论

评论列表(0)

  1. 暂无评论