0

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)

2 Answers 2

0

You're missing closing quotation marks in your url.

1
  • I changed the code but am still getting a (different) error. I added this in the original post
    – Vincent
    Feb 16, 2016 at 9:06
0

After looking for a long while, I finally got it... it's a badly configured api (ie on outpans side) - I think they were doing something on their side (I could view their whole api directory at some time yesterday).

Anyway, got everything working and notified the outpan team!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .