Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Get Checkout API Fails

Get Checkout API Fails

dev-t
Shopify Partner
1 0 0

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: 

HttpRequestError: Failed to make Shopify HTTP request: FetchError: invalid json response body at https://medly-pharmacy.myshopify.com/api/unstable/graphql.json reason: Unexpected end of JSON input
at HttpRequestError.ShopifyError [as constructor] (/Users/devT/shopifyTest/node_modules/@shopify/shopify-api/dist/error.js:13:28)
at new HttpRequestError (/Users/devT/shopifyTest/node_modules/@shopify/shopify-api/dist/error.js:79:42)
at /Users/devT/shopifyTest/node_modules/@shopify/shopify-api/dist/clients/http_client/http_client.js:243:35
at processTicksAndRejections (internal/process/task_queues.js:95:5)
 
On another note, how can I fetch a checkout for a customer?
Replies 0 (0)