7

I have the services module installed, and I have both taxonomy_term and taxonomy_vocabulary checked. However I'm having problems getting just the terms for one vocabulary. when I do curl -g "http://domain.com/endpoint/taxonomy_term?args[0]=machine_name_of_vocabulary" or curl -g "http://domain.com/endpoint/taxonomy_term?args[0]=2"

I get an xml result like this:

<result>
  <item>
    <tid>2</tid>
    <vid>2</vid>
    <name>Blue</name>
    <description/>
    <format>filtered_html</format>
    <weight>0</weight>
  </item>
  <item>
    <tid>1</tid>
    <vid>5</vid>
    <name>Apple</name>
    <description/>
    <format>filtered_html</format>
    <weight>0</weight>
  </item>
</result>

which is the terms of all the vocabularies. In other words, I have the argument wrong, or the request wrong, or something else wrong.

How do I configure services and make a request to it to get only one vocabulary?

9
+100

I was working on exactly the same thing the other day, the format is like this:

http://domain.com/endpoint/taxonomy_term?parameters[vid]=2

To explain that a bit further...

If you look at the code in _taxonomy_resource_definition() the index resource defines a few arguments:

  • page (int)
  • fields (string)
  • parameters (array)
  • pagesize (int)

The way to pass any of those is:

http://domain.com/endpoint/taxonomy_term?arg_name=value

Since parameters is an array you need to format it as if it was an associative array in the URL, so you use (e.g.) parameters[vid]=2.

It will also work for other parameters, e.g. parameters[name]=TermName.

0

For Services 3.x on Drupal7, this also works:

curl -i -X POST \
 -H Cookie:SESSabcdefg12345baadbeef=ovQpBase62SessionIdHere_45AUSJ \
 -H X-CSRF-Token:v6j7r9RactujAHY-mYYZa \
 -H Accept:application/json \
 -H content-type:application/json \
 'http://services.example.com/rest/taxonomy_vocabulary/getTree' \
 -d '{ "vid" :"1" }'

Why?

Not sure. Not sure why they duplicated the capability. Also not sure why this is a POST. Someone on a drupal board said that it is because retrieving these things is "an action" and "actions" need to be done with POST. It didn't make sense to me. It looks like a query, not an action. But whatever.

But I like the other answer better.

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.