Problem with Guzzle code

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
sclg
User
Posts: 149
Location: UK

Problem with Guzzle code

Post by sclg »

I have some custom code in Row_Inserting to add data to a Joomla instance using the Joomla API.

$client = new \GuzzleHttp\Client();
$body = [
	--------
];
$headers = [
        'Content-Type' => 'application/json',
	'Authorization' => 'Bearer -------'
];
$request = new Request('POST', 'https://xxxx.uk/api/index.php/v1/users', $headers, $body);
$res = $client->sendAsync($request)->wait();

This code works correctly in Postman but when I put it in Row_Inserting, I get the error
Cannot instantiate interface Psr\Http\Message\ServerRequestInterface
... on the line $request = new Request(..... above.

Any idea what I'm doing wrong?


arbei
User
Posts: 9384

Post by arbei »

You need to use the fully qualified name for Request (i.e. \GuzzleHttp\Psr7\Request) in your code.


Post Reply