TypeError: Cannot read properties of undefined (reading 'Rest')

Topic summary

Issue: Creating a one-time ApplicationCharge via Shopify Admin REST throws a TypeError: “Cannot read properties of undefined (reading ‘Rest’)”. The goal is to initiate a charge using @shopify/shopify-api per Shopify’s documentation.

Implementation: Code initializes a REST client with new shopify.clients.Rest({ session }) and posts to path ‘application_charges’ with payload including name, price, return_url, and test: true. Data type is set to DataType.JSON.

Error details: The promise rejects with a stack trace pointing to top-up.jsx and a React click handler path, indicating the ‘Rest’ property is being accessed on an undefined object. Exact message: “Uncaught (in promise) TypeError: Cannot read properties of undefined (reading ‘Rest’)”.

Status: No resolution or suggested fixes yet. The post requests assistance. The embedded code snippet and the linked Shopify docs are central to understanding the issue. The discussion remains open with the key question of why the REST client reference is undefined.

Summarized with AI on December 18. AI used: gpt-5.

Hello,

When I trigger the following code to create an application charge, (a one-time payment that can be found in the documentation here https://shopify.dev/docs/api/admin-rest/2024-10/resources/applicationcharge#post-application-charges) :

import { DataType } from '@shopify/shopify-api';

const goToCheckout = async () => {
    const client = new shopify.clients.Rest({session});
      const data = await client.post({
      path: 'application_charges',
      data: {"application_charge":{
        "name":"Super Duper Expensive action",
        "price":100.0,
        "return_url":"http://super-duper.shopifyapps.com",
        "test":true}},
      type: DataType.JSON,
    });
  };

I get the following error:

“Uncaught (in promise) TypeError: Cannot read properties of undefined (reading ‘Rest’) at goToCheckout (top-up.jsx:13:43) at onClick (top-up.jsx:179:32) at HTMLUnknownElement.callCallback2 (chunk-GZD7INZN.js?v=4c7f3d14:3674:22) at Object.invokeGuardedCallbackDev (chunk-GZD7INZN.js?v=4c7f3d14:3699:24) at invokeGuardedCallback (chunk-GZD7INZN.js?v=4c7f3d14:3733:39) at invokeGuardedCallbackAndCatchFirstError (chunk-GZD7INZN.js?v=4c7f3d14:3736:33) at executeDispatch (chunk-GZD7INZN.js?v=4c7f3d14:7014:11) at processDispatchQueueItemsInOrder (chunk-GZD7INZN.js?v=4c7f3d14:7034:15) at processDispatchQueue (chunk-GZD7INZN.js?v=4c7f3d14:7043:13) at dispatchEventsForPlugins (chunk-GZD7INZN.js?v=4c7f3d14:7051:11)”.

Thanks in advance.