stripe.subscriptions.retrieve not working - Stripe Nodejs

Viewed 11

When trying to retrieve a Stripe subscription I get

Logged Error: Cannot read properties of undefined (reading 'retrieve')

Here's how I'm trying to retrieve a subscription:

const stripeSubscription = await stripe.subscriptions.retrieve(
    subId
  );

console.log(stripeSubscription);

Reference: Retrieve subscription Stripe docs

I was using version: "stripe": "^8.222.0"

Then upgraded to version "stripe": "^10.10.0"

Still not working. What am I missing or doing anything wrong?

Any help or guide is appreciated. Thanks.

1 Answers

It looks like you're not fully initializing the client as it looks like a secret key is not being provided to it.

Where you currently have:
const stripe = require("stripe")

can you try updating that line to include your secret key as shown in line 1 of the snippet within the documentation that you referenced, so that it looks like this, but with your actual secret key:
const stripe = require("stripe")("sk_test_XXX")

Related