Posted by GigabyteJack on January 31, 2011 at 5:04am
Hi Everyone,
I am looking for a really simple example of how to make a call to the node index action in the latest REST server.
This is what I have so far - but I am getting a 406 (Not Acceptable) returned. I assume this is because I am not passing the correct arguments - so the better question might be - how do I find the correct arguments/parameters to send to a services call?
$.ajax({
type: "POST",
dataType: 'json',
url: "http://localhost/api/node.json",
data: 'sessid=' + $('#sessid').val(),
success: function (msg) {
console.log("node.list:");
console.log(msg);
}
});
Thanks in advance for your time and expertise.
GJ
Comments
Isn't the node index a
Isn't the node index a GET?
See http://drupal.org/node/783254 under CRUD for Services 3.x
See http://drupal.org/project/rest_server under CRUD as well for Services 2.x
Thanks tedlchen - you're
Thanks tedlchen - you're right (I just facepalmed) - although I'm now getting an empty array (even though there is content within the site).
Do you know what other variables the index function is expecting? (Or how I could go about working this out myself)
Thanks again for your help!
index function arguments
Index function expects optional variables:
page -- page to display if there are more than 20 results
fields -- coma separated string of fields to display
parametes -- array of values of fields to filter results
For standard services resources arguments you should check the code. Please see resources/node_resource.inc file. In the beginning of this file you can see definitions of standard CRUD operations and actions. There you can find arguments.
Also if you checkout dev version from CVS you can find tests for node resource where you can see how all operations and actions are called.
Thanks so much for pointing
Thanks so much for pointing me in the right direction. This isn't the first time it's been pointed out but the drupal community is just fantastic.
Thanks to your help I am confident I am calling the services module correctly, after looking in the event log it appears a SQL error is the problem (looks like the node table is not being aliased), I'll start in the node_resource.inc and see if I can track down where this SQL is constructed and try to write/apply a fix.
Unknown column 'n.nid' in 'on clause' query: SELECT DISTINCT * FROM node LEFT JOIN domain_access da ON n.nid = da.nid WHERE ((da.realm = "domain_id" AND da.gid = 0)) ORDER BY sticky DESC, created DESC LIMIT 0, 20 in _db_query() (line 149 of /var/www/drupal/includes/database.mysql.inc).
I have the domains module installed, maybe that's messing with it.
Thanks again for taking the time to answer my question!
Regards,
GJ
Tried the latest dev-release?
Tried the latest dev-release? Looks to me like this is fixed there.
Hi Pelle, Which component
Hi Pelle,
Which component (services module, domain module or the entire drupal branch?)
Thanks for your help!
Regards,
GJ
Services
Services
Thanks Pelle - you're right
Thanks Pelle - you're right that works! Funny I only got that branch a few days ago - next time the first thing I'll check for updates first!
Thankyou for sharing your knowledge.
Regards,
GJ
Returning more than 20 results
Is there a way to have more than the 20 results returned for the index request? If not, is there a way to indicate how many pages of results there are as opposed to keep going until you don't get any results?
I just do this for my index:
Using Services 3.0 for D6, REST server, Dev version from Jan 31,2011:
$.getJSON(this.apiPath, callback);Where this.api path is the url to the endpoint, and callback is a 'success' function.