for my final project I am trying to query a barcode database through via their API.
When I hardcode the barcode and api key, everything works as expected but when I am using variables, file_get_contents() keeps returning false.
works
$response = @file_get_contents("https://api.outpan.com/v2/products/039800027047?apikey=[APIKEY]");
Doesn't work
$apikey = // APIKEY;
$barcode = 039800027047;
$response = @file_get_contents("https://api.outpan.com/v2/products/".$barcode."?apikey=".$apikey);
Anyone wanting to take a gander at what I'm doing wrong?
ps: the API documentation can be found at https://www.outpan.com/developers.php
Edit:
maybe I am missing something?
$contents = file_get_contents("https://api.outpan.com/v2/products/{$barcode}?apikey={$apikey}");
still doesn't work but this does:
$contents = file_get_contents("https://api.outpan.com/v2/products/{$barcode}?apikey=/* hardcoded APIKEY */");
The error changed though, now it displays file_get_contents(https://api.outpan.com/v2/products/039800027047?apikey=00000000000): failed to open stream: php_network_getaddresses: getaddrinfo failed: No address associated with hostname in /home/jharvard/vhosts/panapp/includes/functions.php on line 60
(apikey zeroed out)
ps: I double checked whether I'm passing in a wrong apikey but everything should be exactly the same (it's been copy pasted)