0

I'm trying to use Coinbase's REST API to get a list of available currencies:

Here is the endpoint - https://api.prime.coinbase.com/currencies

You can see the JSON loads when you click the link above.

$coinbase_coins = file_get_contents('https://api.prime.coinbase.com/currencies');
$coinbase_coins = json_decode($coinbase_coins, true);

Now when I try to load it with file_get_contents, I get the error "failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request"

Why is it that I can access the endpoint via browser but now with file_get_contents?

Thanks ;)

cpcdev
  • 1,130
  • 3
  • 18
  • 45
  • dupe of https://stackoverflow.com/questions/697472/php-file-get-contents-returns-failed-to-open-stream-http-request-failed ? – Chris Cousins Aug 28 '18 at 04:48
  • Try setting a user-agent. That worked for me. See: https://stackoverflow.com/questions/30120211/php-file-get-contentsurl-turns-into-amp/30120589#30120589 – Thomas Park May 16 '21 at 00:03

1 Answers1

0

Could be your php runtime configuration. allow_url_fopen needs to be set to true.

Read about it here here in the manual.

Nanobrain
  • 23
  • 7