E.g. when requesting my user data from /jsonapi/user/user I can get only my UUID by filtering ?fields[user--user]=uuid .

However if I have thousands of users the output payload gets huge because for all other accounts I get 403 as meta.errors and therefore JSON API response is something like:

{
    "data": [
        {
            "type": "user--user",
            "id": "2596ec3c-3d58-4af4-b3cc-d6ae9ec5c3b0",
            "attributes": {
                "uuid": "2596ec3c-3d58-4af4-b3cc-d6ae9ec5c3b0"
            },
            "links": {
                "self": "http://stage.habinator.com/jsonapi/user/user/2596ec3c-3d58-4af4-b3cc-d6ae9ec5c3b0"
            }
        }
    ],
    "jsonapi": {
        "version": "1.0",
        "meta": {
            "links": {
                "self": "http://jsonapi.org/format/1.0/"
            }
        }
    },
    "meta": {
        "errors": [
            {
                "title": "Forbidden",
                "status": 403,
                "detail": "The current user is not allowed to GET the selected resource.",
                "links": {
                    "info": "http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.4"
                },
                "code": 0,
                "id": "/user--user/62590b54-8c49-427d-8ad0-cf2f8a9d4fdb",
                "source": {
                    "pointer": "/data"
                }
            },
            {
                "title": "Forbidden",
                "status": 403,

... thousand times.

So how can I omit the meta part altogether?

Comments

TipiT created an issue. See original summary.

gabesullice’s picture

Status: Active » Fixed
Issue tags: +API-First Initiative

Hi @TipiT! Thanks for opening an issue for this.

Two things:

  1. ?fields[user--user]=uuid is not a filter, it is a "sparse field set". It's saying, "only print the uuid field". What you want is ?filter[uuid]={uuid}. IOW, use filter not fields as the query param name.
  2. If you upgrade to 2.x, we've addressed this exact need already in (I think) a more elegant way. Check out the change record: The JSON API entrypoint (/jsonapi) now provides information about the current user: `meta.links.me`.

Let me know if you have any other questions! Also, when you're finished with your project, please consider filing an experience report like this one. Those reports give us maintainers extra motivation to keep working on open source :)

wim leers’s picture

I think #2 could've said three things, so I'll append one 🙂

  1. Thousands of meta.errors entries are a thing of the past since JSON API responses now contain a `meta.omitted` object when resources have been removed from the response for access reasons!
wim leers’s picture

Priority: Minor » Normal
tipit’s picture

Really nice guys!

For fast support and implementing this. I'll try it ASAP.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.