Search code examples
phplaravel-4guzzle

GuzzleHttp\Client::request() must be of the type array, boolean given


Ok i used "guzzlehttp/guzzle": "~6.0" for laravel.

it works on the server, but it does not work on my XAMPP, i don't know what is the problem. This is the error code.

Argument 3 passed to GuzzleHttp\Client::request() must be of the type array, boolean given

This is the code:

$param_data = array(
    'api_user'  => Config::get('sendgrid.api_user'),
    'api_key'   => Config::get('sendgrid.api_key'),
    'list'      => Config::get('sendgrid.list'),
    'email'     => 'xxxxxxx@yahoo.com',
);

$client = new Client();
$client->setDefaultOption('verify', false);
$res    = $client->request(
    'GET',
    'https://api.sendgrid.com/api/newsletter/lists/email/get.json',
    [
    'query' => $param_data
    ]
);

$arr_res = json_decode($res->getBody());
print_r( $arr_res );

Solution

  • Same error I resolved it like this in my code

     $param_data = array(
            'api_user'  => Config::get('sendgrid.api_user'),
            'api_key'   => Config::get('sendgrid.api_key'),
            'list'      => Config::get('sendgrid.list'),
            'email'     => 'xxxxxxx@yahoo.com',
        );
    
        $client = new Client();
        $client->setDefaultOption('verify', false);
        $res    = $client->request(
                   array(
                          'GET', 
                          'https://api.sendgrid.com/api/newsletter/lists/email/get.json?query='.$param_data,
                       ));
    
        $arr_res = json_decode($res->getBody());
        print_r( $arr_res );
    

    Also if your using Laravel request and Guzzle Request in same page so you need to use it like.

    use Illuminate\Http\Request;
    use GuzzleHttp\Psr7\Request as GuzzleRequest;
    

    Try this hope this will work for you :)