#szy_api-authentication
1 messages ¡ Page 1 of 1 (latest)
đ Welcome to your new thread!
â˛ď¸ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
âąď¸ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
đ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1240249391848230934
đ Have more to share? Add more details, code, screenshots, videos, etc. below.
const apiKey = process.env.STRIPE_SECRET_KEY
url is: https://api.stripe.com/v1/plans
Before, when i had apiKey set to NEXT_PUBLISHABLE_STRIPE_KEY I was getting GET log in my stripe dashboard but when changed to secret (what stripe told me to) it doesnt receive anything anymore.
Can you share the ID (req_xxx) of the API request? https://support.stripe.com/questions/finding-the-id-for-an-api-request
Find help and support for Stripe. Our support site 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.
Hmm, probably isn't a log actually
I'd say based on the error your process.env.STRIPE_SECRET_KEY is not what you expect it to be. Can you log it out to confirm?
szy_api-authentication
true, it's returning undefined. hmm i wonder why
Check your .env file and ensure it's set and the variable is named correctly
yes yes, i checked. i call it the same in other files.
Not sure I'm afraid. Hard to say with the context you've shared but suggests some kind of config issue in your Next.js app
true, need to figure it out first. thanks
In reality you shouldn't make making API requests from your client compoents with effects as it'll expose your secret key
You likely need a Next.js server action/route handler
yes, i just figured it out. the key is not accessible to browser. it was working with NEXT_PUBLISHABLE_STRIPE_KEY because this one is available to the browser. im trying with the route now,
I'm calling stripe api successfully but in response im not getting anything back.
export async function POST(request: NextRequest) {
try {
const { url } = await request.json()
const response = await fetch(url, {
headers: {
Authorization: `Bearer ${process.env.STRIPE_SECRET_KEY}`
}
})
const data = await response.json()
return NextResponse.json(data)
} catch (error) {
return NextResponse.json(
{ error: 'Error fetching data from Stripe' },
{ status: 500 }
)
}
}
OK, can you share the req_xxx ID of the request?
Find help and support for Stripe. Our support site 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.
req_IqtOAUzTvNEj0I
Related, why are you using Plans?
They're deprecated mostly, Prices are what you should be using: https://docs.stripe.com/api/prices
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
I want to assign posts to plans i have in stripe: for example some posts available for plan Basic, some for Premium.
in Sanity CMS
to have the data synced
And how are you creating the Plans in Stripe?
In product catalog
oh wait, i should be calling v1/products
right?
i changed the url but still not getting anything back.
req_OgfRzG1egDuFz1
Hmm, hard for my to validate that as we don't log JSON responses for GET requests like that. Can you add some logging to your code to validate that we return nothing?
also do you have an example of a product ID prod_xxx that you're expecting to get back?
i logged the response:
_Response [Response] {
[Symbol(realm)]: null,
[Symbol(state)]: {
aborted: false,
rangeRequested: false,
timingAllowPassed: true,
requestIncludesCredentials: true,
type: 'default',
status: 200,
timingInfo: {
startTime: 13070552.116292,
redirectStartTime: 0,
redirectEndTime: 0,
postRedirectStartTime: 13070552.116292,
finalServiceWorkerStartTime: 0,
finalNetworkResponseStartTime: 0,
finalNetworkRequestStartTime: 0,
endTime: 0,
encodedBodySize: 4571,
decodedBodySize: 4571,
finalConnectionTimingInfo: null
},
cacheState: '',
statusText: 'OK',
headersList: _HeadersList {
cookies: null,
[Symbol(headers map)]: [Map],
[Symbol(headers map sorted)]: null
},
urlList: [ URL {} ],
body: { stream: undefined }
},
[Symbol(headers)]: _HeadersList {
cookies: null,
[Symbol(headers map)]: Map(21) {
'server' => [Object],
'date' => [Object],
'content-type' => [Object],
'content-length' => [Object],
'connection' => [Object],
'access-control-allow-credentials' => [Object],
'access-control-allow-methods' => [Object],
'access-control-allow-origin' => [Object],
'access-control-expose-headers' => [Object],
'access-control-max-age' => [Object],
'cache-control' => [Object],
'content-security-policy' => [Object],
'cross-origin-opener-policy-report-only' => [Object],
'report-to' => [Object],
'reporting-endpoints' => [Object],
'request-id' => [Object],
'stripe-version' => [Object],
'vary' => [Object],
'x-content-type-options' => [Object],
'x-stripe-routing-context-priority-tier' => [Object],
'strict-transport-security' => [Object]
},
[Symbol(headers map sorted)]: null
}
}
is there a reason you're not using stripe-node for this? https://github.com/stripe/stripe-node?tab=readme-ov-file#documentation
No reason, i didn't think of it. i have stripe node setup in my project. let me try