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?
See comment 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