Question

i am using drupal 6 and services 6.3x module but i am unable to use this module completely. I have enabled rest server module also. I added a new service and added resources to it. I added node resource to it and i am able to fetch all the nodes in json format

what i am not able to understand is :-

  1. The exact uri or may be the procedure to call getTree method in taxonomy_vocabulary resource

  2. How to acccess all the methods (CRUD) functions under every resource enabled

  3. The url -> mydomain.com/service/rest/node.json works for me but how can i access the getTree method ??

I am stuck on this like forever i have even posted jobs on the drupal site but i guess there are very rare people who have knowledge about this.

Edit :-

Live link is http://delvelogic.com/merchant/drupal-6.22/services/rest/taxonomy_vocabulary

The following is the java code i am using :-

    DefaultHttpClient httpClient = new DefaultHttpClient();
    HttpResponse response = null;  
    HttpPost postMethod = new HttpPost("http://delvelogic.com/merchant/drupal-6.22/rest/taxonomy_vocabulary/getTree.json");
    postMethod.addHeader("Content-type", "application/x-www-form-urlencoded");
    postMethod.addHeader("Accept","application/json");
  //  postMethod.addHeader("Authorization", "basic " + Base64.encodeBytes(("admin"+":"+"admin123").getBytes()));
 //   httpClient.getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT));

     List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();  
     nameValuePairs.add(new BasicNameValuePair("vid", ""+1));
     nameValuePairs.add(new BasicNameValuePair("parent", ""+1));
     nameValuePairs.add(new BasicNameValuePair("maxdepth",""+1));
    // nameValuePairs.add(new BasicNameValuePair())
    try{
     postMethod.setEntity(new UrlEncodedFormEntity(nameValuePairs));  
     response = httpClient.execute(postMethod); 

     InputStream input = response.getEntity().getContent();
      BufferedReader rd = new BufferedReader(new InputStreamReader(input),input.toString().length());
     String line;
     StringBuilder sb =  new StringBuilder();
     while ((line = rd.readLine()) != null) {
            sb.append(line);
     }
     rd.close();
     uploadresponse = sb.toString();

     Log.d("Response", ""+uploadresponse);
    }catch (Exception e) {
        // TODO: handle exception
        e.printStackTrace();
    }

Also if there is any firefox add on so that i can actually see the method working ??

Edit Again :-

I have found this add on restclient to work on firefox

i choose the method as post in the url i typed http://delvelogic.com/merchant/drupal-6.22/services/rest/taxonomy_vocabulary/getTree

added header :-

Content-type : application/x-www-form-urlencoded

Accept : application/json

request body :-

&vid=1&parent=1&maxdepth=1

it gives me 404 not found with no vocabulary with id 1 found Thanks in advance

Was it helpful?

Solution

According to the documentation the URLs shouldn't necessarily have .json at the end, but I guess this is a setting you've changed if it's working for the node functions. I know you're not going to like this answer (I'm fairly certain you've tried it before) but the URL is: mydomain.com/service/rest/taxonomy_vocabulary/getTree. I've even been through the service and rest_server modules' respective code and that is definitely what it should be.

For further proof look at the (valid, passed) test module for services taxonomy_vocabulary:

ServicesResourceTaxonomyTests::testVocabularyGetTree.

You'll see that the URLs accessed by this successfully passed test are: $path . '/taxonomy_vocabulary/getTree', where $path is the path to the endpoint (i.e. mymodule.com/service/rest/).

It really would help if you could provide a live link though so we can test to see if the problem is in your Java code or with Drupal (although the latter seems very unlikely).

EDIT

p.s. do comment on this answer as I have a lot of experience with the services module and I'm sure I can point you in the right direction with a bit more info. It pains me to see someone struggling with something that I've had nothing but joy with in the past!

ANOTHER EDIT

This is the response I get from http://delvelogic.com/merchant/drupal-6.22/services/rest/taxonomy_vocabulary:

<?xml version="1.0" encoding="utf-8"?>
  <result>
    <nodes/>
    <module>taxonomy</module>
    <name></name>
    <help></help>
    <relations>0</relations>
    <hierarchy>0</hierarchy>
    <multiple>0</multiple>
    <required>0</required>
    <tags>0</tags>
    <weight>0</weight>
    <vid>4</vid>
  </result>

Notice the <vid>4</vid> bit...I'm pretty sure the vid you should be looking for is 4, not 1!

Licensed under: CC-BY-SA with attribution
Not affiliated with drupal.stackexchange
scroll top