You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I’m using Statamic as a headless CMS and have a collection with a nested Link Fieldtype that provides URLs in its API response (e.g., link_url: "/example/path").
The issue is that the API doesn’t natively support querying by URL across collections. This makes resolving entries by path challenging, especially when the target could belong to various collections (pages, news, etc.).
Currently, the workaround involves enabling URL as a filter and querying like:
/api/collections/pages/entries?filter[url:is]=/example/path.
However, this approach breaks or requires further calls when the URL is from another collection.
Ideal Outcome:
We should be able to use the link_url value directly to resolve content dynamically, maintaining clean and user-friendly URLs.
For example, a URL like /content/nested-example/another-level/example-page in my app would map to /nested-example/another-level/example-page in Statamic. The app would fetch the associated entry without needing prior knowledge of the collection or entry type.
Proposed solution:
Something along the lines of route I added to Statamic: routes/api.php
<?php
namespace App\Http\Controllers\Api;
use Statamic\Http\Controllers\API\ApiController;
use Statamic\Support\Str;
use Statamic\Facades\Entry;
use Statamic\Http\Resources\API\EntryResource;
use Statamic\Exceptions\NotFoundHttpException;
class PageController extends ApiController
{
public function show($path)
{
$this->abortIfDisabled();
$path = Str::start($path, '/');
$path = Str::chopEnd($path, '/');
/** @var \Statamic\Structures\Page */
$page = Entry::findByUri($path);
throw_unless($page, new NotFoundHttpException);
$entry = $page->entry();
$this->abortIfUnpublished($entry);
return app(EntryResource::class)::make($entry);
}
}
Extra information:
The Statamic team kindly added this PR to help with this issue: statamic/cms#11375 - which is aimed for v6. Personally, my ideal solution would be both of these improvements to the API. We'd have enough information on the link to be able to handle it correctly and we would be able to use the URLs users create in Statamic within external apps.
Keen to hear thoughts / how people are handling this at the moment.
Thanks for reading!
The text was updated successfully, but these errors were encountered:
Context:
/api/collections/pages/entries?filter[url:is]=/example/path.
However, this approach breaks or requires further calls when the URL is from another collection.
Ideal Outcome:
Proposed solution:
Something along the lines of route I added to Statamic:
routes/api.php
PageController.php
Extra information:
The Statamic team kindly added this PR to help with this issue: statamic/cms#11375 - which is aimed for v6. Personally, my ideal solution would be both of these improvements to the API. We'd have enough information on the link to be able to handle it correctly and we would be able to use the URLs users create in Statamic within external apps.
Keen to hear thoughts / how people are handling this at the moment.
Thanks for reading!
The text was updated successfully, but these errors were encountered: