TypeError with REST client in Remix App

mikebatts
Shopify Partner
5 0 0

Hello! Apologies if this isnt the correct place to post this --

 

I'm currently developing a Shopify app using the Remix framework and have encountered an issue I can't seem to resolve. I'm experiencing a TypeError related to the Shopify REST client within my Remix app, and despite following the Shopify documentation closely, I'm stuck. I'm hoping to get some insights or suggestions from the community.

 

When running my app, I encounter the following error:

 

Application Error
TypeError: Cannot read properties of undefined (reading 'shop')
at new RestClient ...

 

 

This error appears when I try to fetch data from Shopify, such as abandoned checkouts or shop details.

 

Here's an excerpt from my shopify.server.jsx where I configure the Shopify app:

 

// shopify.server.jsx
import "@shopify/shopify-app-remix/adapters/node";
import { shopifyApp, LATEST_API_VERSION } from "@shopify/shopify-app-remix/server";
import { PrismaSessionStorage } from "@shopify/shopify-app-session-storage-prisma";
import { restResources } from "@shopify/shopify-api/rest/admin/2023-10";
import prisma from "./db.server";

const shopify = shopifyApp({
  apiKey: process.env.SHOPIFY_API_KEY,
  apiSecretKey: process.env.SHOPIFY_API_SECRET || "",
  apiVersion: LATEST_API_VERSION,
  scopes: process.env.SCOPES?.split(","),
  appUrl: process.env.SHOPIFY_APP_URL || "",
  sessionStorage: new PrismaSessionStorage(prisma),
  restResources,
  // Additional configurations...
});
export default shopify;

 

 

And here's how I'm trying to fetch abandoned checkouts:

 

// Part of shopify.server.jsx
export async function fetchAbandonedCheckouts(admin) {
  try {
    console.log("Session details:", admin.session);
    const response = await admin.rest.resources.AbandonedCheckout.checkouts({
      session: admin.session,
    });
    return response.body.checkouts;
  } catch (error) {
    console.error("Error fetching abandoned checkouts:", error);
    throw error;
  }
}

 

 
For context, the error appears in the terminal logs as follows:

 

[Terminal Output]
10:25:56 │ remix │ Session details: undefined
10:25:56 │ remix │ Shop Details: undefined
10:25:56 │ remix │ Error fetching abandoned checkouts: TypeError: Cannot read properties of undefined (reading 'shop')
...

 

 
I've tried to follow the official Shopify documentation for setting up a Remix app. as best as I can, and have simplified the data-fetching functions to ensure basic connectivity -- but still facing these issues. I'm particularly puzzled by the session details: undefined log, which suggests a problem with the session handling or authentication process. Maybe it shouldnt be reading shop in this case?
 
Has anyone experienced a similar issue or is there a potential misstep here in my setup? Are there any additional configurations I'm missing? Happy to share more code snippets for context here, to me it seems like the session is not correctly established or my REST client isnt configured properly for my context. 
 
Note: i am a novice dev and learning, any help and guidance here would be greatly appreciated!
Reply 1 (1)

Liam
Shopify Staff
2731 292 743

Hi Mikebatts,

 

Are you seeing any error codes that we can look into?

 

Hope this helps!

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog