Why can't I cancel an order using API?

Topic summary

A developer is encountering a TypeError when attempting to cancel an order via the Shopify API using the @shopify/shopify-api JavaScript package.

Error Details:

  • The error message states: “Order is not a constructor”
  • Occurs when trying to instantiate new shopify.rest.Order({session})

Code Context:

  • Following the official Shopify API JS guide from GitHub
  • Using @shopify/shopify-api package with REST API approach
  • Configuration includes standard authentication parameters (API key, secret, hostname, scopes)

Current Status:

  • The issue remains unresolved with no responses yet
  • The root cause appears to be improper instantiation or import of the Order resource class
Summarized with AI on November 13. AI used: claude-sonnet-4-5-20250929.

I used this guide, https://github.com/Shopify/shopify-api-js/tree/main/packages/shopify-api

My code:

const { shopifyApi, adminApiClient, LATEST_API_VERSION } = require(“@shopify/shopify-api”);
const shopify = shopifyApi({
apiKey: process.env.CLIENT_ID,
apiSecretKey: process.env.CLIENT_KEY,
scopes: [‘read_products’],
hostName: process.env.HOST_NAME
});

const order = new shopify.rest.Order({ session })
res.send(order)

I got this error:
TypeError: shopify.rest.Order is not a constructor