Output field in JSONAPI to support headless Drupal sites

Created on 14 January 2025, 6 days ago

Problem/Motivation

Last time I checked, the Views Reference field isn’t output in JSONAPI when inspecting a node that features one.

This means that headless Drupal sites with frontends that depend on JSONAPI output for building components need a workaround to retrieve Views data separately.

In my case, I used the JSONAPI Views module to expose the output of Views I needed. This works fine for accessing View data directly, provided you know the exact URL of the View including any arguments/filters.

This is where the editing experience falls over when using headless Drupal.

Steps to reproduce

To view the Views Reference field output:

1. Add a Views Reference field to a Content Type.
2. Create a new piece of content and select a View to add.
3. Save the new content
4. Visit <mysite.com>/jsonapi and select the endpoint link for that Content Type
5. Locate your saved node and inspect the Fields list output. The View Reference field should not appear.

Proposed resolution

I believe it would be much nicer UX if:

1. Editors chose their Views using Views Reference Field, then
2. The ID, display, args, limit, contextual filters etc of their selected View displays in the JSONAPI output for that node; and finally
3. If the JSONAPI Views module is installed, include a reference to that View endpoint URL under the node’s ‘relationship’ key in the JSONAPI output.

Remaining tasks

Decide on feasibility of this idea.

Feature request
Status

Active

Version

2.0

Component

Code

Created by

🇦🇺Australia timfletcher

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024