Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

JohnConnet's avatar

Can t acess external API

So, i have the following code with guzzle to connect to an external API, with the domain "http://api.parksandrecreation.com/data/parks" and i also have an api_key (parksandrecreationapi)

function getAPIData() { $client = new client(); $res = $client->post( 'http://api.parksandrecreation.com/data/parks', ['auth' => ['api', 'parksandrecreationapi']] );

    $contents = $res->getBody()->getContents();
    var_dump(json_decode($contents));
}

so this function is on the controller, yet i can t acess it, giving me the following

object(stdClass)#286 (2) { ["success"]=> bool(false) ["message"]=> string(20) "Unauthorized request" }

can someone help me pls?

0 likes
1 reply
Brian Kidd's avatar

@johnconnet Have you verified this works using an HTTP client, like Postman? Start there and ensure it's working then come back to your code. Not knowing that endpoint, I'm not sure what else to suggest.

Please or to participate in this conversation.