#oranges13 - laravel API key initialization
1 messages · Page 1 of 1 (latest)
Can you try this format?
$stripe = new Stripe\StripeClient(<insert secret key here>);
Sure, I have tried several ways
We are using laravel, so it's in a config key, but I have also tried hard coding it:
$stripe = new \Stripe\StripeClient(config('services.stripe.secret'));
return $stripe->invoices->retrieve($invoiceId);
//return Invoice::retrieve($invoiceId, ['api_key' => config('services.stripe.secret')]);
exactly as is in the documentation
and I get an AuthenticationException
other requests are working but Invoice::retrieve is failing
this seems very unexpected
Is the working code in the same block/flow as the invoice retrieval?
Or elsewhere?
I suspect there might be some differences happening in initialization to explain this
oranges13 - laravel API key initialization
I have tried hard coding the api key into this file to avoid any environmental issues and still have the same error. I am using Laravel - I tried the same code in tinker and it works. I am stumped. EXACT same code
Well I'm not sure what that might be. Are there environment differences? PHP or Stripe PHP versions?
Tinker is in-built into Laravel and should behave the same as the application itself
Sure, but I'm not familiar with the details of tinker/laravel functionality, i'd suggest reaching out to the laravel community to understand why there might be differences in the way your code runs
That's the stupid thing, we are using Stripe throughout our code base and it's just this ONE endpoint request
There must be some difference between the endpoints
If you put a similar request in another of your endpoints, does it work?
ie, is it the endpoint, or the invoice retrieval?
It's the invoice retrieval - we are using the stripe command directly
$stripe->invoices->retrieve() and we get an API Key error
But like, all other API activities are working, and we are using the SAME api key and the SAME syntax
Sure but i mean, does the same line elsewhere in your code work as expected
It's only used in 2 places and this is blocking the other from executing, but that is a thought
I confirmed by looking at the headers that an Auth header is being set with the correct bearer token
I am at a loss here
Do you get a request ID back in the response headers?
You're seeing the API in the outbound request headers? That's very unexpected, then
If you're inspecting the outbound request and see a valid-looking API key in the auth headers, but we're responding saying there is no API key then something isn't quite as it seems
I've seen some similar shaped issues with zero-width control characters getting into the start/end of the clipboard with API key and not being able to spot that
Can you try pasting into some plain text editor, re-copying the API key leaving off the first/last character?
ie, if your clipboard pastes sk_test_123...678 then just copy k_test_123...67
then paste again and manually type the first & last char, the goal being to drop any hidden zero-width characters
I am back to a universal api key so it should be using the same one in all cases yet only this request is failing
This is the entirety of the response we are receiving
{
"params": [],
"response": {
"error": {
"message": "You did not provide an API key. You need to provide your API key in the Authorization header, using Bearer auth (e.g. 'Authorization: Bearer YOUR_SECRET_KEY'). See https://stripe.com/docs/api#authentication for details, or we can help at https://support.stripe.com/.",
"type": "invalid_request_error"
}
},
"responseCode": 401
}
You're certain that the API key is set within the same scope where the retrieve API call is happening? I saw the 2 lines of code you included above, but I'm still not sure what else is going on within the file that they're contained within
Apologies if this has been covered already. I'm still catching up
I have tried both at the global app scope (in the AppServiceProvider) for laravel, as well as in the file directly via config() and also hard coded into the file itself