Quantcast
Channel: Joomla! Forum - community, help and support
Viewing all articles
Browse latest Browse all 1754

General Questions/New to Joomla! 4.x • Using GuzzleHttp to access the API

$
0
0
I'm having problems with Guzzle access to the API.
I can access the API with Postman with no problems.
If I create a simple test program, I can access the API using Postman's suggested cURL code no problem.
The problem arises if I try to use Guzzle...

Code:

require_once "vendor/autoload.php";$client = new \GuzzleHttp\Client();$headers = [  'Content-Type' => 'application/json',  'Authorization' => 'Bearer c2xxxxxxx'  ];$body = [  "block"=> "0",  "email"=> "dum2@dum.com",  "groups"=> ["2"],  "id"=> "0",  "lastResetTime"=> "",  "lastvisitDate"=> "",  "name"=> "Alan Aardvark",  "params"=> [    "admin_language"=> "",    "admin_style"=> "",    "editor"=> "",    "helpsite"=> "",    "language"=> "",    "timezone"=> ""  ],  "password"=> "klhkjh3465$%^",  "password2"=> "klhkjh3465$%^",  "registerDate"=> "",  "requireReset"=> "0",  "resetCount"=> "0",  "sendEmail"=> "0",  "username"=> "dum2@dum.com"];$response = $client->post('https://xxx.uk/api/index.php/v1/users', ['headers' => $headers, 'json' => $body]);
This results in a 406 'Could not match accept header' error and I can't see why.

I've tried other Guzzle approaches such as...

Code:

$request = new  \GuzzleHttp\Psr7\Request('POST', 'https://xxx.uk/api/index.php/v1/users', $headers, $body);$res = $client->sendAsync($request)->wait();
... and even a simple GET...

Code:

$request = new \GuzzleHttp\Psr7\Request('GET', 'https://lsrpc.uk/api/index.php/v1/users', $headers);$res = $client->sendAsync($request)->wait();echo $res->getBody();  
... but they all give the same 'Could not match accept header' error.
As I say, it all works fine in Postman or with straight cURL.
What am I missing??

Statistics: Posted by sclg — Thu Feb 22, 2024 11:12 am



Viewing all articles
Browse latest Browse all 1754

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>