Ilya Trianggela
Ilya Trianggela

Reputation: 307

How to set Authorization HTTP header in Guzzle?

I want to use API from Publons. They mentioned "Any other requests should include a token in the Authorization HTTP header and prefixed with 'Token'. So, i try to set the Token in headers. This is my code


$client = new Client([
            'base_uri' => "https://publons.com/api/v2/academic/",
            'headers' => [
                'Token' => "MyToken"
            ]
        ]);

The result is {"detail":"Authentication credentials were not provided."}. I make sure the token is correct, beacause I've try it on Talend API Tester and works. Can anyone help me? Where is the mistake?

Upvotes: 0

Views: 595

Answers (1)

cssBlaster21895
cssBlaster21895

Reputation: 3710

Just guessing, there's not much in their docs but I suppose it would look like that:

$client = new Client([
            'base_uri' => "https://publons.com/api/v2/academic/",
            'headers' => [
                'Authorization' => "Token{Your api token here}"
            ]
]);

They want authorization header and token prefixed with "Token"...

Also this question would give you more ideas how to deal with your case.

Upvotes: 1

Related Questions