skip to Main Content

It’s throwing me an error

PHP Error:  Cannot instantiate interface GuzzleHttp\ClientInterface in vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php on line 111, referer: http://127.0.0.1/local_m2/admin/admin/system_config/edit/section/active_campaign/key/6a9ce672c9414c57acd889eb50fb82020e13e651b74cf3a81b9cd8b30da45306/ here

I have already run all Magento required commands Like Setup: upgrade, di:compile and deploy but still it’s throwing me this error.

I have already checked GuzzleHttp in the vendor folder, it’s already installed in Magento 2.2.9

I have tried the composer require guzzlehttp/guzzle:^6.0 to reinstall the library but having no luck.

2

Answers


  1. import this library:

    use GuzzleHttpClient;
    use GuzzleHttpClientFactory;
    use GuzzleHttpExceptionRequestException;
    

    on __construct use:

    $this->client = new Client([
                "base_uri" => url_base,
                "timeout" => 2,
            ]);
    

    and then call:

    $response = $this->client->get(
                        url_base . "/" . url_api_point,
                        ['headers' =>
                            [
                                'Authorization' => "Bearer {$this->token}" /* if have */
                            ]
                        ]
                    );
                    return json_decode($response->getBody()->getContents(), true, 512, JSON_THROW_ON_ERROR);
    
    Login or Signup to reply.
  2. try this way to create an instance of GuzzleClient, im currently using a similar in a magento 2.4.4 and works fine, you donĀ“t have to inyect that on __construct()

    /**
     * @return GuzzleHttpClient
     */
    public function getClient()
    {
        $client = new GuzzleHttpClient(["base_uri" => "your url", "verify" => false]);
        return $client;
    }
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search