#oranges13 - laravel API key initialization

1 messages · Page 1 of 1 (latest)

blazing pilotBOT
late stag
#

Can you try this format?

$stripe = new Stripe\StripeClient(<insert secret key here>);

formal plover
#

I did that! Same issue

#

$stripe->invoices->retrieve('invoice_id'); same error

late stag
#

Can you post the full code here?

#

Obviously with the API key omitted

formal plover
#

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

void mulch
#

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

formal plover
#

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

void mulch
#

Well I'm not sure what that might be. Are there environment differences? PHP or Stripe PHP versions?

formal plover
#

Tinker is in-built into Laravel and should behave the same as the application itself

void mulch
#

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

formal plover
#

That's the stupid thing, we are using Stripe throughout our code base and it's just this ONE endpoint request

void mulch
#

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?

formal plover
#

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

void mulch
#

Sure but i mean, does the same line elsewhere in your code work as expected

formal plover
#

It's only used in 2 places and this is blocking the other from executing, but that is a thought

formal plover
#

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

void mulch
#

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

formal plover
#

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
}
late stag
#

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

formal plover
#

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