#Logan - Customer Portal 404
1 messages ยท Page 1 of 1 (latest)
Hmmm... can you share the request ID from the request where you tried to create this customer portal session?
Here's how you can find a request ID: https://support.stripe.com/questions/finding-the-id-for-an-api-request
Find help and support for Stripe. Our support center provides answers on all types of situations, including account information, charges and refunds, and subscriptions information. Get your questions answered and find international support for Stripe.
requestId: 'req_RQYP3lIW67al6V'
Thanks, looking
Oh,
error: {
message: "Invalid checkout.session id: cus_MAl6rV6WEAn0Q5",
type: "invalid_request_error"
}
You tried to use the Customer ID for the Session ID in the URL
Oh. Whoops.
What I am doing is,
Frontend -> userId -> Database lookup -> create portal from subscription object in my db
Thus I do not believe there is a session ID in the subscriptionData
Is there a way to create a portal without an active session?
const portalSession = await stripe.billingPortal.sessions.create({
customer: checkoutSession.customer,
return_url: returnUrl,
});
You are creating the portal session here. It should return a correctly configured URL
I'm sure I am going to feel really dumb when I understand. How can I pass the session ID into the URL?
Having trouble pinpointing exactly what is going wrong here - my return URL is just localhost
I am trying to send the portalSession.url to my frontend, but this 404 seems to be blocking me from doing that
You're basically returning this: https://stripe.com/docs/api/customer_portal/sessions/create?lang=node
Can you try logging out the entire portalSession object? Make sure it matches what the API ref doc shows here?
Sure, one moment
Using your method there, it logs everything just fine
Okay. So if you follow the link in the url property for the portalSession object you logged, do you get to an actual customer portal interface?
I cannot generate a portalSession object
With my code
There is no doubt that the URL in your example would work
Problem is, I'm passing my own cus_id from my database, and the API is kicking back a 404
saying invalid ID
But when I plugged my ID manually into your example, it worked fine. I dont get it
I'm confused. The code you shared is clearly designed to generate a portal session.
I will post a quick video
Ok. Basically, I am sending a customer ID to your API, and the API is responding with "Nah fam"
Trying to generate that portal URL
but cant
The request you sent me is not something that would work. You made a GET request to /checkout/sessions with a customer ID on the end. The only API that accepts a Customer ID is the Customer API
The error it returns is that there isn't a checkout session using that ID, which makes sense because it's a Customer ID
That makes sense.
To create a customer portal you would be making a POST request to /v1/billing_portal/sessions with both the Customer ID and the Return URL in the body of the request
Okay so the slimmed down, simplified approach got you a working customer portal?
Yup!
app.get("/api2/create-portal-session", async (req, res) => {
const userId = req.query.userId;
const userData = await User.findOne({ username: userId });
const { customer } = userData.subscriptionData.data.object
const portalSession = await stripe.billingPortal.sessions.create({
customer: customer,
return_url: "http://localhost:3000/",
});
res.send(portalSession.url);
});
I have no idea what I was doing trying to make a checkout session
๐
Great, I'm glad it's working ๐
Hey, we are calling a lot of things "sessions" so I get it
Thank you very much for your help ๐