5

I want to retrieve all the nodes associated with a given taxonomy term (field_term) using HTTP GET.

I have tried:

curl -v http://myserver/endpoint_path/node?parameters[field_term]=1

but I get an HTTP 406 Column not found.

Also later on I will need to use multiple taxonomy vocabularies to filter by more than one term.

I am using the Services 3 module in Drupal 7.

6

I found out how to do it, so I am posting it here in case it is helpful to somebody.
Feel free to post if you know a better way.

I assume you have created some content with fields corresponding to taxonomy vocabularies.

  1. Create a Services View

    • Install the Services View module, as suggested in my previous comment.
    • Go to Structure / Views / Add new view
    • Give your view a name and uncheck 'create a page' because we just want a service.
    • Click 'Continue & Edit', you should then be in the 'Displays' screen.
    • Click on the '+Add' displays button, select 'Services'.
    • Under 'Service Settings' click on the path and change it. e.g my_view_path.
  2. Create criteria for your view

    • Under 'Filter Criteria' click 'Add'. Do not use Advanced/Contextual Filters.
    • Search for your field, and click Apply'
    • 'Autocomplete' in the Selection Type, 'Apply and Continue'. It should not matter because we are going to call this from a URL, not a web page.
    • The 'Configure filter criterion' popover is shown.
    • Check 'Expose this filter to visitors'. If you don't do this, you will not be able to pass as an argument.
    • Scroll down to the bottom and click on 'More'.
    • Take note of the 'filter identifier'. This is the name of the argument you need to pass in the URL, e.g: field_myterm_tid
    • Click on Apply filter
    • Repeat for other filter criteria as needed.
    • Click on Save View
  3. Enable the Service Resource

    • One last step, go to Structure > Services
    • You should see a list of endpoints, click 'Edit resources'
    • Check to enable the resource you just created.
  4. Finally, retrieve your info with HTTP GET

http: //myserver/my_endpoint_path/my_view_path?field_myterm_tid=XX&field_myterm2_tid=YY

  • XX and YY are the textual names of the terms
0

Services in itself doesn't provide such specific use-cases.

You need a new resource, possibly you can find a module that provides what you are looking for, or you'll need to create a new one on your own.

The Services views module appears like an excellent start for creating such resources.

  • 1
    Thank you. Filtering by a term should be a common enough use case, but I might be wrong. I am looking into the services views module and it looks promising – David C Apr 8 '13 at 17:21
  • That looks like an absolutely excellent module. I'll update the answer with that as a suggestion. – Letharion Apr 8 '13 at 17:55
0

In Drupal 8 this can be done using json API module.

Install the module

Create a taxonomy color

Add vocabulary red, green and blue

Now to get all the vocabularies associated with the taxonomy color using get need to perform get on the following URL

http://localhost/drupal/jsonapi/taxonomy_term/color?_format=hal_json

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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