'Retrieve data from external api with Laravel

`I'm trying to retrieve some data from external api with laravel : this is my controller

use Illuminate\Http\Request; use Illuminate\Support\Facades\Http;

public function netvigie()  
    {
        $response = Http::get('https://extranet.netvigie.com/fr/api/{token}/availability/{id}/getAnomaliesCount?format=json');
        $data = json_decode($response->body(), true);
        dd($data);
        return view('ControlmAPI.netvigie');
    }

But i have curl error 28 while it works in Postman. We have only 2 parameters which are token and product id that we enter directly in the url.

Someone can help me please ?


Solution 1:[1]

Can you write the complete error?

With Guzzle try:

$client->request('GET', 'example.com/example', ['connect_timeout' => 3.14]);//3.14 is seconds, try to increase it 

if it still gives you problems try to increase

  1. read_timeout
  2. timeout

which are always request options of Guzzle

Solution 2:[2]

Have you tried to set a timeout for your call?

Http::timeout(3)->get(...);

You can read more here https://laravel.com/docs/8.x/http-client#timeout

Solution 3:[3]

That's what i have when i try to dd :

public function netvigie()
       {
        return Http::dd()->get('https://extranet.netvigie.com/fr/api/{token}/availability/id/getStatusDetails?format=json');
       }

response : response

It work with postman but with laravel i have "cURL error 28: Failed to connect to extranet.netvigie.com port 443: Timed out ". I tried to increase the time limit but it did not work.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Joseph
Solution 2 Agung Gunawan
Solution 3 Mdi Adel