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

madprabh's avatar

How to send the following in Guzzle POST HTTP request

Hey folks! I want to send the following curl request in the form of Guzzle HTTP request, I cannot figure out how to send the apikey. Any help is highly appreciated.

curl -X POST -u "apikey:*****" "https://gateway.watsonplatform.net/natural-language-understanding/api/v1/analyze?version=2018-11-16" --header "Content-Type: application/json" --data '{ "url": "https://photogallery.indiatimes.com/celebs/celeb-themes/judges-that-make-you-sweat/articleshow/46780900.cms", "features": { "sentiment": {}, "categories": {}, "concepts": {} } }'

Best, Madhu

0 likes
3 replies
h1pp1e's avatar

An option is:

$client = new GuzzleHttp\Client(['headers' => ['apikey' => '**********', 'Content-Tipe'=>'application/json']]);

Or in your request add headers

$client->request('POST', 'your-url', [
    'headers' => ['apikey' => '**********', 'Content-Tipe'=>'application/json']
]);
madprabh's avatar

Thanks a lot for the response. I get the "unauthorized" message from IBM cloud NLP when I use it this way. Researching a bit more on this.

SunnyBoy's avatar

@MADHUKAR - Looks like we are stuck in the same issue. I used cURL to get somewhat close to the issue which kind of works I am able to get the data but not able to iterate.

Please or to participate in this conversation.