meteor-shopify : expected String to be a Hash
NickName:elzi Ask DateTime:2015-06-11T05:22:59

meteor-shopify : expected String to be a Hash

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.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"}]}

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?

Copyright Notice:Content Author:「elzi」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/30767554/meteor-shopify-expected-string-to-be-a-hash

Answers
ilrein 2015-06-18T23:44:07

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).\n\nI've made an issue where I too, faced a POST request that returned \"string expects to be a hash\".\n\nI'm temporarily sidestepping this issue by using plain old HTTP.Post and passing in an object with what the Shopify API specifically asks for:\n\nvar options = {\n data: params,\n headers: {\n 'X-Shopify-Access-Token': Meteor.user().profile.shopifyAccessToken\n }\n};\n\nvar newScript = HTTP.post(\"https://\" + Meteor.user().profile.shopName + \".myshopify.com/admin/script_tags.json\" , options);\n",


More about “meteor-shopify : expected String to be a Hash” related questions

meteor-shopify : expected String to be a Hash

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 ...

Show Detail

expected String to be a Hash: properties SHOPIFY

trying to add a custom text box field for customers to write text on product in Shopify Keep getting this error message when trying to add the item to cart expected String to be a Hash: properties ...

Show Detail

Unit testing in perl, Receiving hash ref as return expected to return a string from a key in a hash

I am trying to test the output of the following method: package ASC::Builder::Error; sub new { my ($package, $first_param) = (shift, shift); if (ref $first_param eq 'HASH') { my %

Show Detail

How can either convert a string into a hash or add it into a hash

So in basic Ruby I am trying to figure out how to either convert a string into a hash or put a string into a hash. I want the pokemon item as the key and a integer for the value. Something like th...

Show Detail

Is there a way to lower the complexity of string hash

I noticed that many hash functions for strings need to go through the whole string. I can understand that because the information of a string is stored in the whole string. However, given a string of

Show Detail

Freemarker expected extended hash error

I've added an objectwrapper in freemarker that wraps a type of object as a templateHashModel. I don't seem to be able to iterate over it - if I try to iterate as a hash, (ie &lt;#list blah as x,y...

Show Detail

Shopify help? - expected String to be a Hash: properties

I am trying to add a text box for a product on Shopify for customers to enter their own name or text, I am very new to all this and followed this Youtube video exactly step for step. https://www.yo...

Show Detail

Freemarker "Expected a hash, but this evaluated to a string"

I'm using Freemarker as an addition with OpenOffice, to process documents with variables. Therefore, in this case, I want an adress with either a contact person (if there is one) or just the normal

Show Detail

How Hash of a String Literal in String Literal Pool Computed?

I was seeing the implementation of String class in Java, and the constructor of this goes like this public String(String var1) { this.value = var1.value; this.hash = var1.hash; ...

Show Detail

Error running template Expected a hash, but this has evaluated to a string (wrapper: f.t.SimpleScalar):

When tried reading a hash using Freemarker, it is reading the string variable having same name as that of hash prior to that, even though the string variable exists at different sub-level. The JSON

Show Detail