MONEI / Shopify-api-node

Node Shopify connector sponsored by MONEI
https://monei.com/shopify-payment-gateway/
MIT License
946 stars 277 forks source link

Asset - GET/PUT Config Settings Data #281

Closed Bek81 closed 5 years ago

Bek81 commented 5 years ago

Hi,

testing the native shopify API to get the "config/settings_data.json" file, the data returns correctly.

I used: https://SITENAME.myshopify.com/admin/themes/THEMEID/assets.json?asset[key]=config/settings_data.json

When i try to get that data using this Node Api (connected to the same store):

let params = {
    key: "config/settings_data.json"
}

shopify.asset.get(THEMEID, params)
.then(
    asset => {
        console.log('asset', asset);
        callback(null, asset);
    }
)
.catch(
    err => {
        console.log(err);
        callback(err);
    }
);

I get an "undefined".

Can you help me, please?

Moreover, is it possible to upload the same JSON in another store?

Thanks a lot.

lpinca commented 5 years ago

See https://github.com/MONEI/Shopify-api-node/issues/174#issuecomment-377222096 it seems the same.

Bek81 commented 5 years ago

"Great Scott!"...It works!

Thanks a lot @lpinca .

Now all I have to do is try to load the file in another store and find a way to manage the images uploaded via the section widget ("image": "shopify: / shop_images / flagship_miami_01.jpg").

Bek81 commented 5 years ago

with ttt = JSON string and shopify.asset.update(ANOTHERTHEMEIDOFANOTHERSTORE, params)

let params = {
            asset: {
                key: "config/settings_data.json",
                value: ttt
            }
        }

return statusCode: 406, statusMessage: "Not Acceptable"

params = {
            key: "config/settings_data.json",
            value: ttt
        }

return statusCode: 422, statusMessage: "Unprocessable Entity"

lpinca commented 5 years ago

I don't think you can change the theme of another store from the same Shopify instance. You probably have to create another Shopify instance for that store and use it.

Bek81 commented 5 years ago

Yes....I'm using another instance of API (connected to another store).

another_shopify_instance.asset.update(ANOTHERTHEMEIDOFANOTHERSTORE, params)

lpinca commented 5 years ago

Try to read the error message if there is one.

try {
  await shopify.asset.update(id, { key: '...', src: '...' });
} catch (err) {
  console.log(err.response.body)
}
Bek81 commented 5 years ago

await shopify.asset.update(38248185907, params) SyntaxError: await is only valid in async function

{ key: '...', src: '...' } I set "value" for JSON. Like for working example:

key: 'templates/collection.beky.liquid',
value: "{% section 'beky' %}"

the errors are already written above:

return statusCode: 406, statusMessage: "Not Acceptable"

or

return statusCode: 422, statusMessage: "Unprocessable Entity"

Thanks

lpinca commented 5 years ago

yes, 422 means one of the parameter is invalid, you should get more info by reading the error message.

shopify.asset.update(id, { key: '...', /* ... */ })
  .then(console.log)
  .catch((err) => console.error(err.response.body));
Bek81 commented 5 years ago

ok, I found.

The right version is

params = {
            key: "config/settings_data.json",
            value: ttt
        }

now err.response.body is:

{ errors:
   { asset:
      [ 'Invalid type value for block \'1552992990111\'. Type must be defined in schema',
        'Invalid type value for block \'footer-1\'. Type must be defined in schema',
        'Invalid type value for block \'1558012537942\'. Type must be defined in schema',
        'Invalid type value for block \'1558012487774\'. Type must be defined in schema',
        'Invalid type value for block \'1558013871932\'. Type must be defined in schema',
        'Invalid type value for block \'1558013914337\'. Type must be defined in schema',
        'Invalid type value for block \'collection-0\'. Type must be defined in schema',
        'Invalid type value for block \'collection-1\'. Type must be defined in schema',
        'Invalid type value for block \'collection-2\'. Type must be defined in schema',
        'Invalid type value for block \'1553170432378-0\'. Type must be defined in schema',
        'Preset \'Allure\' Invalid type value for block \'footer-1\'. Type must be defined in schema',
        'Preset \'Allure\' Invalid type value for block \'collection-0\'. Type must be defined in schema',
        'Preset \'Allure\' Invalid type value for block \'collection-1\'. Type must be defined in schema',
        'Preset \'Allure\' Invalid type value for block \'collection-2\'. Type must be defined in schema',
        'Preset \'Couture\' Invalid type value for block \'footer-1\'. Type must be defined in schema',
        'Preset \'Couture\' Invalid type value for block \'collection-0\'. Type must be defined in schema',
        'Preset \'Couture\' Invalid type value for block \'collection-1\'. Type must be defined in schema',
        'Preset \'Couture\' Invalid type value for block \'collection-2\'. Type must be defined in schema',
        'Preset \'Vogue\' Invalid type value for block \'footer-1\'. Type must be defined in schema',
        'Preset \'Vogue\' Invalid type value for block \'collection-0\'. Type must be defined in schema',
        'Preset \'Vogue\' Invalid type value for block \'collection-1\'. Type must be defined in schema',
        'Preset \'Vogue\' Invalid type value for block \'collection-2\'. Type must be defined in schema' ] } }

But i import a zip with whole theme from the first store. I think this is a big problem to do what I try to do.

Benedetto

lpinca commented 5 years ago

I don't know but it isn't an issue in the library.

Bek81 commented 5 years ago

I'm afraid not. But I wish I had an answer from the developers.

Anyway, thanks a lot @lpinca .

lpinca commented 5 years ago

Closing as there is nothing actionable to do on our side.