Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Walker's avatar

Request header

Hi everyone, I'm trying to send a request to an external api to get data. The api is secured by OAuth 2.0. Via the postman, the results are returned to me correctly, but when I make a request with the application, I get a "message" => "Bad credentials" which is wrong?

The documentation provides such an example for an authorization sent in a header

curl -H 'Authorization: Token nbusr123' 'https://datahub.ekosystem.slovensko.digital/api/datahub/corporate_bodies/

$searchResults = Http::withHeaders([
        'Authorization: Token *****',
   ])->get('https://datahub.ekosystem.slovensko.digital/api/datahub/corporate_bodies/search?q=cin:' . $this->search)->json();
0 likes
4 replies
CorvS's avatar
CorvS
Best Answer
Level 27

@walker Have you tried defining your header as key/value pair?

Http::withHeaders([
    'Authorization' => 'Token *****',
])
Walker's avatar

Yes, I've tried that before

EDIT @corvs I forgot to remove the double shoe already it's ok thanks.

1 like
Friso S's avatar

@walker Did you try with

Http::withToken('Token nbusr123','Authorization')->get('https://datahub.ekosystem.slovensko.digital/api/datahub/corporate_bodies/search?q=cin:' .'blup')->json();

Please or to participate in this conversation.