Feb 28, 2021
0
Level 6
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.
Please or to participate in this conversation.