1

So here's my problem : I use the EOD Financial api to get data on a stock, on a Laravel/Vue.js project. On a Vue Component, I use axios to make a get Request like this :

const response1 = await axios.get("/getHistoricalDataNAME/"+String(self.stock.code)+'.'+String(self.stock.exchange)) 
                .then((response) => {

with the function getHistoricalDataNAME being :

    public function getHistoricalDataISIN(String $ISIN) {
        
        $response = Http::get('https://eodhistoricaldata.com/api/eod/'.$ISIN.'?api_token='TOKEN');

        return $response->body();

    }

and it works perfectly. The result is an array, when I console.log() it, I have this : Console.log result

Now, I'm trying to the exact same thing in a Laravel Command. So I made this command :

public function handle(EODController $EODController, Client $client)
    {
        $client = new Client(['verify' => false]);

        $stock = Stock::find(8);

        $stockEODname = strval($stock->code).'.'.strval($stock->exchange);

        $EOD = $client->get('https://eodhistoricaldata.com/api/eod/'.$stockEODname.'?api_token=TOKEN');

        var_dump(json_decode($EOD->getBody()->getContents()));
    }

and it doesnt work. The var_dump just return NULL. The name of the stock is good, the $EOD variable is valid, everything seems fine but I don't know how to get an array like with the Axios method. What am I doing wrong ? Thank you !

  • I would suggest debugging the code in your laravel command. $url = https://eodhistoricaldata.com/api/eod/'.$stockEODname.'?api_token=TOKEN' and var_dump($url) that before passing it to the client for the request – Andreas Sep 17 '21 at 17:56
  • use try catch and catch the RquestException from guzzle error and log it to database, then you can know the exact error, take [this answer](https://stackoverflow.com/a/64603614/9471283) as reference – bhucho Sep 17 '21 at 18:32
  • i would suggest you to check for the headers that you're sending in the axios request, and copy those in the guzzle request... usually is this the problem – Samuel Aiala Ferreira Sep 17 '21 at 18:48

0 Answers0