laravel-swap icon indicating copy to clipboard operation
laravel-swap copied to clipboard

The request call is null - Unable to parse JSON data: JSON_ERROR_SYNTAX - Syntax error, malformed JSON

Open komen205 opened this issue 3 years ago • 2 comments

Swap::latest('EUR/USD'); is throwing "Unable to parse JSON data: JSON_ERROR_SYNTAX - Syntax error, malformed JSON" on function

public function getExchangeRate(ExchangeRateQuery $exchangeQuery): ExchangeRate

    {

        $exceptions = [];

 

        foreach ($this->services as $service) {

            if (!$service->supportQuery($exchangeQuery)) {

                continue;

            }

            try {

                return $service->getExchangeRate($exchangeQuery);

            } catch (\Throwable $e) {

                $exceptions[] = $e;

            }

        }

 

        throw new ChainException($exceptions);

    }

I tried to dump the request on HttpService and it returns null. image And for the buildRequest function, if I dump the $request or $this->requestFactory->createRequest('GET', $url); returns

image

If I dump the $content in the private function doCreateRate in the AbstractApi.php file, it just returns nothing. I can't find where the problem is. Any ideas? image

komen205 avatar Jun 21 '21 16:06 komen205

I have the same issue

elfeffe avatar Feb 04 '22 22:02 elfeffe

Looks like it's an issue with AbstractApi's response?

florianv avatar Apr 04 '22 06:04 florianv

The issue has been documented here: https://github.com/florianv/exchanger/blob/master/doc/readme.md#configuration

You need to setup the curl client to follow location:

$options = [
    CURLOPT_FOLLOWLOCATION => true,
];
$client = new CurlClient(null, null, $options);

florianv avatar Dec 11 '22 06:12 florianv