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

MrMooky's avatar

API Connection from Provider

I'd like to connect Statamic CMS with my Laravel app and grab some data via the Content API. In my HelperServiceProvider (I also tried AppServiceProvider.php) I have this code:

$footerNav = CMSConnect::getJsonData("/cms/collections/pages/entries");

My Service file looks like this:

    public static function getJsonData($endpoint)
    {
        $connection = config('app.url').$endpoint;

        if (App::environment('local')) {
            $response = Http::withOptions(['verify' => false])->get($connection);
        } else {
            $response = Http::get($connection);
        }

        if ($response->successful()) {
            return $response->json()['data'];
        }
    }

When I load this page, it takes about a minute and returns a "504 Gateway Time-out". Is it not possible to make an API connection that "early" in the code, or why am I not getting any data here? The endpoint works perfectly fine when I use the same code within any Controller.

0 likes
0 replies

Please or to participate in this conversation.