Dear all,

I have just upgraded my json_api from 1.x to 2.3.

Reading the documentation that says this

filter[uid.uuid][value]=BB09E2CD-9487-44BC-B219-3DC03D6820CD

My filter like this
?filter[field_lead.uuid][value]=dd9ef2a3-640d-4282-9a86-835625670a7e

should work...

But it does not... (it gives me a 400) ;-)

After finding this: https://www.drupal.org/node/3015183, just now, i would assume that this should work
?filter[field_lead.id]=dd9ef2a3-640d-4282-9a86-835625670a7e

Then i get a 200, but the data[] is empty...while i know for sure it should not be

Am i missing something stupid here?

Comments

guardian87 created an issue. See original summary.

guardian87’s picture

Issue summary: View changes
guardian87’s picture

Issue summary: View changes
gabesullice’s picture

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

See https://www.drupal.org/node/3015183 :)

All breaking changes (and most new features are listed here): https://www.drupal.org/list-changes/jsonapi

Thanks for pointing out the documentation, which page was that on so we can update it?

gabesullice’s picture

Status: Fixed » Active

Leaving as active actually, for the question in #4.

gabesullice’s picture

Ohhh, sorry! I completely missed the second part of your issue:

After finding this: https://www.drupal.org/node/3015183, just now, i would assume that this should work
?filter[field_lead.id]=dd9ef2a3-640d-4282-9a86-835625670a7e

Then i get a 200, but the data[] is empty...while i know for sure it should not be

🙈


This is probably due to: https://www.drupal.org/sa-contrib-2018-081

There are lots of docs about these hooks in jsonapi.api.php

guardian87’s picture

Thanks for getting back to me.

The docs is was referring to are these:
https://www.drupal.org/docs/8/modules/jsonapi/filtering

I don't really understand the sa-contrib-2018-081 link, since i have just upgraded to json_api 2.x

So im kinda left with my initial question, how can i get this filter to work on 2.x?
because the empty data[] is wrong in my example, that i know for sure...it seems like it is just filtering on uuid?

wim leers’s picture

I have just upgraded my json_api from 1.x to 2.3.

🥳

I don't really understand the sa-contrib-2018-081 link, since i have just upgraded to json_api 2.x

Which entity type is this happening for? Does it happen to be a custom one?

guardian87’s picture

Hi Wim,

yes, they are ECK entities.

gabesullice’s picture

@guardian87, that explains it then. Custom entities need to have one of the entity-level hooks implemented for them. I just published a new change record. Feel free to ask any specific questions about how to implement them if the docs aren't clear.

https://www.drupal.org/node/3036792

guardian87’s picture

Oh i see...
So this is a requirement as of json_api 2.x then?
As it was working in 1.x?

Sorry, i could have specified the eck usage in my question.

[EDIT]
Oh, i see, as of 1.24 this was changed if i read this correctly?
I upgraded from 1.23.

gabesullice’s picture

Oh, i see, as of 1.24 this was changed if i read this correctly?
I upgraded from 1.23.

Yep, since it was a security issue, it was applied to both the 1.x and 2.x branches.

guardian87’s picture

As a quick test, to see if this is actually my problem, i just implemented something like this

function project_jsonapi_entity_field_filter_access(\Drupal\Core\Field\FieldDefinitionInterface $field_definition, \Drupal\Core\Session\AccountInterface $account) {
  return AccessResult::allowed();
}

function project_jsonapi_entity_filter_access(\Drupal\Core\Entity\EntityTypeInterface $entity_type, \Drupal\Core\Session\AccountInterface $account) {
    return ([
      JSONAPI_FILTER_AMONG_ALL => AccessResult::allowed(),
    ]);
}

Obviously this is not what i want to keep, but i just want to figure out if it actually solves the problem at hand.
So far there is no difference when implementing these...

Am I missing something?

Ps: The hooks do get invoked though..

wim leers’s picture

Please go to http://example.com/rebuild.php as the admin user first, or do drush cr.

guardian87’s picture

Hi Wim,

I did that before posting ;)

Okay nevermind...
cleared cache 3 more times, now its good :(

Sometimes i hate you drupal ;)

Thanks guys.

wim leers’s picture

In Drupal code bases, you clear caches. In JS code bases, you need to create a build. In C code bases, you need to compile. Just different trade-offs.

Drupal's trade-offs enable non-programmers to assemble web sites from components without needing to knowing any programming :)

guardian87’s picture

Status: Active » Fixed

Tell me about it, after all these years of dev, it still gets me apparently. ;-)

wim leers’s picture

:)

Status: Fixed » Closed (fixed)

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