Dedicated to the Hydrogen framework, headless commerce, and building custom storefronts using the Storefront API.
Hi,
I am trying to fetch the checkout details for a checkoutId using the nodeJS libraries. I have tried using both Shopify-api and shopify-buy sdk. In both of them, I am not able to get the response.
Here is the test code snippet:
const fetch = require('node-fetch');
const ShopifyBuy = require('shopify-buy');
const ShopifyApi = require('@shopify/shopify-api');
const shop = 'xxxxxxxxxxxxxxxx';
const storefrontAccessToken = 'xxxxxxxxxxxxxxxxxxxxxx';
const shopifyBuyClient = new ShopifyBuy({
domain: shop,
storefrontAccessToken
});
/*
* Saw this on the Github page:
* https://github.com/Shopify/storefront-api-examples/blob/master/node-js-buy/src/js-buy-sdk.js
*/
global.fetch = fetch;
const apiClient = new ShopifyApi.Shopify.Clients.Storefront(shop, storefrontAccessToken);
const checkoutId =
'Z2lkOi8vc2hvcGlmeS9DaGVja291dC8xNjhkYzVkMTA0M2U0NDVhNDA2ZDkyNDVhOTZhODI4ND9rZXk9N2NhMTNiMDE5YWQxMWYxYTAxOWFiZGQ4MmJlZmUyNmY=';
const query = `
node(id: "Z2lkOi8vc2hvcGlmeS9DaGVja291dC8xNjhkYzVkMTA0M2U0NDVhNDA2ZDkyNDVhOTZhODI4ND9rZXk9N2NhMTNiMDE5YWQxMWYxYTAxOWFiZGQ4MmJlZmUyNmY=") {
id
... on Checkout {
id
webUrl
}
}
}`;
apiClient
.query({ data: query })
.then(res => {
console.log(res);
})
.catch(err => console.error(err));
shopifyBuyClient.checkout
.fetch(checkoutId)
.then(checkout => {
console.log(checkout);
})
.catch(error => {
console.log(error);
});
Fetching from shopify-buy sdk produces the error: [ { message: 'an unknown error has occurred.' } ]
Shopify-api produces the following error: