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

jmacdiarmid's avatar

POST Request works with Postman but not Guzzle 7

Can someone help me with this? I've researched this and tried a lot of examples on SO and other sites, still no success. What it's supposed to do is create an organization (client org) on the simpli.fi ad publishing server.

Today, I decided to test with Postman and got it to work. When using Guzzle, I get various errors but this is the one it lands on the most:

curl_setopt_array(): cannot represent a stream of type Output as a STDIO FILE*

Creating the Client:

 $client = new Client([
         'debug' => true,
         'base_uri' => self::$baseUrl,
         'headers' => [
                'csrf-token' => csrf_token(),
                'x-app-key'   => self::$appKey,
                'x-user-key'  => self::$userKey,
                'Content-Type' => 'application/json',
                'Accept' => 'application/json',
         ]
 ]);

JSON data:

 $data = json_encode([
            'organization' => [
                'name' => "Pete's Pet Pagoda",
                'parent_id' => self::$parentId,
            ]
 ]);

Create the POST Request

  $endpoint = '/organizations';

  $response = $client->request('POST', $endpoint, [
         'timeout' => 30,
         'json' => $data,
  ]);

0 likes
4 replies
jlrdw's avatar

I wonder if this line is working:

'csrf-token' => csrf_token(),

Try setting in header.

jmacdiarmid's avatar

Yes. It's working.

array:5 [▼
  "csrf-token" => "6KDX4FNss9msp9xiL4DnVF4BpvHaTAb0N0mkRq1E"
  "x-app-key" => "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
  "x-user-key" => "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
  "Content-Type" => "application/json"
  "Accept" => "application/json"
]
jmacdiarmid's avatar

Thank you. I just looking at this about an hour ago and fixed the issue using the suggestion mentioned on that page. Changed the debug option to [debug' => fopen('php://stderr', 'w') ] PHPStorm recommended changing the 'w' to 'wb' to make it binary safe.

Please or to participate in this conversation.