REST API - "Not Found" When Retrieving Globals by Handle in Multisite Setup
Bug description
In a Statamic multisite setup, attempting to retrieve globals by handle using the REST API with and without specifying the site using the ?site=site_handle query parameter results in a {"message": "Not found."} error. This issue occurs when the global does not belong to the first site in the configuration, making it inaccessible via the API for other sites.
Notably, the issue is resolved immediately if the global is added to the first site in the multisite configuration. Once the global is associated with the first site, it becomes accessible via the API.
How to reproduce
- Set up a multisite environment in Statamic with two sites and enable the content rest api.
- Create global and configure it to belong to the second site
- Attempt to retrieve the global variable via the REST API using the endpoint /api/globals/{handle} returns
{"message": "Not found."} - Attempt to retrieve the global variable via the REST API using the endpoint /api/globals/{handle}?site=site_handle returns
{"message": "Not found."} - Add the global to the first site in the multisite configuration OR reorder sites so that the second site is the first site
- Retry retrieving the global via the API and the global is returned as expected.
I am doing the same thing with nav trees and there it works as expected.
Thanks for looking into this!
Logs
No response
Environment
Environment
Application Name: Statamic DEV
Laravel Version: 11.20.0
PHP Version: 8.3.9
Composer Version: 2.7.7
Environment: local
Debug Mode: ENABLED
URL: localhost:3000
Maintenance Mode: OFF
Timezone: UTC
Locale: en
Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: CACHED
Drivers
Broadcasting: null
Cache: file
Database: sqlite
Logs: stack / single
Mail: smtp
Queue: sync
Session: file
Statamic
Addons: 0
Sites: 2 (Site de, , Site en)
Stache Watcher: Enabled
Static Caching: Disabled
Version: 5.21.0 PRO
Installation
Fresh statamic/statamic site via CLI
Additional details
No response