Home > Software engineering >  Retrieve data from external api with Laravel
Retrieve data from external api with Laravel

Time:01-26

`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 ?

CodePudding user response:

It looks like your parameters do not have a value. Does it work when you replace the parameters in the url with actual values?

CodePudding user response:

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

CodePudding user response:

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

  •  Tags:  
  • Related