3

I am implementing a headless drupal website with json:api as the gateway to get all the data. I am able to get data by their node ids, but that is only if I knew the node id and type beforehand. Is there anyway to get the content by just using the url path?

For example, if one visits the url https://mywebsite/article/test I need to be able to use jsonapi to get all the data from that url, but because I don't know what the node id is for that url, I won't be able to retrieve those data. So, is there a filter I can use for url path using jsonapi?

Edit: I tried it by using the filter:

https://localhost:8080/jsonapi/node/blog_article?filter[path]=/us/articlepage/testpage&include=field_custom_container

and it gives the following error:

Invalid nested filtering. The field path, given in the path path is incomplete, it must end with one of the following specifiers: alias, pid, langcode.

Any ideas?

Thanks

1 Answer 1

6

With JSON:API you can't filter by path because of technical limitations; JSON:API filters translate to entity queries on field values; because Drupal path aliases aren't fields you can't use the filter query param to look up articles by their alias.

A couple of different Drupal projects have cropped up around this limitation:

  • Decoupled Router: Provides a new endpoint where a client can query a path for any possible JSON:API resources.
  • Fieldable Path: Provides a new entity field (and thus queryable via the filter query param) that is designed to mimic the entity's path (with Pathauto support).

You can assess the tradeoffs from both modules and choose the one that makes the most sense for your use scenario.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.