secret
Last active

  • Download Gist
drupal_services_api.md
Markdown

Node Resource

Retrieve

  • Args:
  • HTTP Method : GET
  • Example URL : http://drupal6-services/services/plist/node/1
  • Expected Response(in JSON): {"nid":"1","type":"story","language":"","uid":"0","status":"0","created":"1286592762","changed":"1286592762","comment":"2","promote":"0","moderate":"0","sticky":"0","tined":"0","translate":"0","vid":"1","revision_uid":"1","title":"test","body":"test","teaser":"test","log":"","revision_timestamp":"1286592762","format":"1","name":"","picture":"","data":null,"last_comment_timestamp":"1286592762","last_comment_name":null,"comment_count":"0","taxonomy":[],"files":[],"uric":"http:\/\/drupal6-services\/services\/plist\/node\/1"}

Create

  • Args: node*
  • HTTP Method: POST
  • Example URL : http://drupal6-services/services/plist/node
  • Example: &node[title]=testnode&node[type]=story&node[field_test][0][value]=testtting
  • Notes: field_test is a CCK field.
  • Expected Response(in JSON): {"nid":"45","uri":"http:\/\/drupal6-services\/services\/plist\/node\/45"}

Update

  • Args: node*
  • HTTP Method: PUTĀ 
  • Example URL : http://drupal6-services/services/plist/node/1
  • Example: &node[title]=testnode&node[type]=story&node[field_test][0][value]=testtting
  • Expected Response(in JSON): "1"

Delete

  • Args:
  • HTTP Method: DELETE
  • Example URL : http://drupal6-services/services/plist/node/1
  • Example:
  • Expected Response(in JSON): 1

Comment Resource

Retrieve

  • Args:
  • HTTP Method : GET
  • Example URL : http://drupal6-services/services/plist/comment/30
  • Expected Response(in JSON): {"cid":"30","pid":"0","nid":"48","uid":"1","subject":"asdfadf","comment":"dfgsdfgsdg","hostname":"127.0.0.1","timestamp":"1294792128","status":"0","format":"1","thread":"01\/","name":"admin","mail":"","homepage":""}

Create

  • Args: comment*
  • HTTP Method: POST
  • Example URL : http://drupal6-services/services/plist/comment
  • Example:&comment[body]=commentbody&comment[nid]=49
  • Expected Response(in JSON): {"cid":"31","uri":"http:\/\/drupal6-services\/services\/plist\/comment\/31"}

Update

  • Args: data*
  • HTTP Method: PUT
  • Example URL : http://drupal6-services/services/plist/comment/30
  • Example: &data[body]=commentbody&data[nid]=49
  • Expected Response(in JSON): "30"

Delete

  • Args:
  • HTTP Method: DELETE
  • Example URL : http://drupal6-services/services/plist/comment/30
  • Example:
  • Expected Response(in JSON): 1

User Resource

Retrieve

  • Args:
  • HTTP Method : GET
  • Example URL : http://drupal6-services/services/plist/user/1
  • Expected Response(in JSON): {"uid":"1","name":"admin","pass":"1a1dc91c907325c69271ddf0c944bc72","mail":"kyle@workhabit.com","mode":"0","sort":"0","threshold":"0","theme":"","signature":"","signature_format":"0","created":"1286571725","access":"1294792121","login":"1293782855","status":"1","timezone":null,"language":"","picture":"","init":"kyle@workhabit.com","data":"a:0:{}","roles":{"2":"authenticated user"}}

Create

  • Args: account*
  • HTTP Method: POST
  • Example URL : http://drupal6-services/services/plist/user
  • Example: &account[name]=test&account[mail]=test@test.com&account[pass]=pass
  • Expected Response(in JSON): {"uid":"15","name":"test","pass":"1a1dc91c907325c69271ddf0c944bc72","mail":"test@test.com","mode":"0","sort":"0","threshold":"0","theme":"","signature":"","signature_format":"0","created":"1294793391","access":"1294793391","login":"0","status":"1","timezone":"-25200","language":"","picture":"","init":"test@test.com","data":"a:0:{}","roles":{"2":"authenticated user"},"password":"pass"}

Update

  • Args: data*
  • HTTP Method: PUT
  • Example URL : http://drupal6-services/services/plist/user/15
  • Example: &data[name]=test&data[mail]=test@testing.com&data[pass]=pass
  • Expected Response(in JSON): {"name":"test","mail":"test@testing.com","pass":"pass","uid":"15"}

Delete

  • Args:
  • HTTP Method: DELETE
  • Example URL : http://drupal6-services/services/plist/user/15
  • Example:
  • Expected Response(in JSON): 1

Login

  • Args:
  • HTTP Method: POST
  • Example URL : http://drupal6-services/services/plist/user/login
  • Example: &name=admin&pass=pass
  • Expected Response(in JSON): {"sessid":"853c6c7f6eaa051724080dff202eeec0","session_name":"SESS8b1f176c338bbcc3922a56004cec3c41","user":{"uid":"1","name":"admin","pass":"1a1dc91c907325c69271ddf0c944bc72","mail":"kyle@workhabit.com","mode":"0","sort":"0","threshold":"0","theme":"","signature":"","signature_format":"0","created":"1286571725","access":"1294794381","login":1294794548,"status":"1","timezone":null,"language":"","picture":"","init":"kyle@workhabit.com","data":"a:0:{}","roles":{"2":"authenticated user"}}}

Logout

  • Args:
  • HTTP Method: POST
  • Example URL : http://drupal6-services/services/plist/user/logout
  • Example:
  • Expected Response(in JSON): 1

To create a comment on drupal7 I had to format the POST like this:

How do you upload an image for a node's ImageField? I tried using multipart form data, but the content type was rejected "406 Not Acceptable: Unsupported request content type multipart/form-data". Can I Base64 encode the data and send it via json or xml?

jnross, whoops! thats a bug in services about unsupported content type. BUt yes, you can base64_encode

I am trying to use the user.logout service but I can not find any sample/documentation to get me going.

Here is my sample to log in using cURL: (Works!)

curl -v --data "method=user.login&username=u701@e.com&password=u701" http://localhost:8080/drupal622/myendpoint/user/login
This returned a "sessid":"74q35epc63o2v4brr1e37283p3"

The following requests each failed with an error 406 - 406 Not Acceptable: User is not logged in.

curl -v --data "method=user.logout&sessionID=74q35epc63o2v4brr1e37283p3" http://localhost:8080/drupal622/myendpoint/user/logout

curl -v --data "method=user.logout&sessid=74q35epc63o2v4brr1e37283p3" http://localhost:8080/drupal622/myendpoint/user/logout

Can someone shed some light ?

I have posted the same on drupal but no responses yet.
http://drupal.org/node/1265018

sessid is only used as a parameter in the call to user.login. When user.login returns, a session_name and sessid are returned. This information should be included in subsequent requests as the header "Cookie: <session_name>=<sessid>". Here is an example of system.connect, user.login, and user.logout operations using curl:

$ curl http://example.com/services/system/connect -d "" -v
sessid: eb4d98ee2d6647488d3359d4d7990515

$ curl http://example.com/services/user/login -d "username=joe&password=pass&sessid=eb4d98ee2d6647488d3359d4d7990515" -v
sessid: 9cc1a2cfa782d3d614a947a6a48066a0
session_name: SESS46e169b3ee0c2423dbf60ab06d25e9d7

$ curl http://example.com/services/user/logout -d "" -H "Cookie: SESS46e169b3ee0c2423dbf60ab06d25e9d7=9cc1a2cfa782d3d614a947a6a48066a0;" -v
< HTTP/1.1 200 OK

Hi,
Thanks for taking the time to respond. I tried what you suggested, but got the same error. - HTTP 406 - User Not logged in. attached is a log.

Request :

curl http://127.0.0.1:8080/drupal622/myendpoint/system/connect -d"" -v

Resposne:

{"sessid":"atc8335n25ak2b8d3ii6h04bi4","user":{"uid":0,"hostname":"127.0.0.1","roles":{"1":"anonymous user"},"session":"","cache":0}}

Request:
curl http://127.0.0.1:8080/drupal622/myendpoint/user/login -d"username=user&password=pass&sessid=atc8335n25ak2b8d3ii6h04bi4" -v

  • About to connect() to 127.0.0.1 port 8080 (#0)
  • Trying 127.0.0.1... connected
  • Connected to 127.0.0.1 (127.0.0.1) port 8080 (#0) > POST /drupal622/myendpoint/user/login HTTP/1.1 > User-Agent: curl/7.19.5 (i586-pc-mingw32msvc) libcurl/7.19.5 zlib/1.2.3 > Host: 127.0.0.1:8080 > Accept: / > Content-Length: 61 > Content-Type: application/x-www-form-urlencoded > < HTTP/1.1 200 OK < Date: Sun, 11 Sep 2011 18:37:30 GMT < Server: Apache/2.2.17 (Win32) PHP/5.3.5 < X-Powered-By: PHP/5.3.5 < Set-Cookie: SESS0902a91cf59c38431753fb2428aaaeea=83hp3e9lqtoaujlerpo9a9n8c0; expires=Tue, 04-Oct-2011 22:10:51 GMT; pa th=/ < Expires: Sun, 19 Nov 1978 05:00:00 GMT < Last-Modified: Sun, 11 Sep 2011 18:37:31 GMT < Cache-Control: store, no-cache, must-revalidate < Cache-Control: post-check=0, pre-check=0 < Vary: Accept < Set-Cookie: SESS0902a91cf59c38431753fb2428aaaeea=l3olkdfneiadvrv7t33k0tefu4; expires=Tue, 04-Oct-2011 22:10:52 GMT; pa th=/ < Set-Cookie: SESS0902a91cf59c38431753fb2428aaaeea=4g05o3hq1r5gnf6i94ev5c01h1; expires=Tue, 04-Oct-2011 22:10:52 GMT; pa th=/ < Content-Length: 646 < Content-Type: application/json < {"sessid":"4g05o3hq1r5gnf6i94ev5c01h1","session_name":"SESS0902a91cf59c38431753fb2428aaaeea","user":{"uid":"3","name":"u ser","pass":"1a1dc91c907325c69271ddf0c944bc72","mail":"user@abcdefgh.net","mode":"0","sort":"0","threshold":"0","theme": "","signature":"","signature_format":"0","created":"1309028308","access":"1315765845","login":1315766252,"status":"1","t imezone":"-14400","language":"","picture":"","init":"user@abcdefg.net","data":"a:1:{s:13:\"form_build_id\";s:37:\"form- 69a6d76484049252cfb469a3bc76266e\";}","timezone_name":"America\/New_York","form_build_id":"form-69a6d76484049252cfb469a3 bc76266e","roles":{"2":"authenticated user"}}}* Connection #0 to host 127.0.0.1 left intact
  • Closing connection #0

Request:
curl http://127.0.0.1:8080/drupal622/myendpoint/user/logout -d "" -H "Cookie: SESS0902a91cf59c38431753fb2428aaaeea=4g05o3hq1r5gnf6i94ev5c01h1;" -v

  • About to connect() to 127.0.0.1 port 8080 (#0)
  • Trying 127.0.0.1... connected
  • Connected to 127.0.0.1 (127.0.0.1) port 8080 (#0) > POST /drupal622/myendpoint/user/logout HTTP/1.1 > User-Agent: curl/7.19.5 (i586-pc-mingw32msvc) libcurl/7.19.5 zlib/1.2.3 > Host: 127.0.0.1:8080 > Accept: / > Cookie: SESS0902a91cf59c38431753fb2428aaaeea=4g05o3hq1r5gnf6i94ev5c01h1; > Content-Length: 0 > Content-Type: application/x-www-form-urlencoded >
  • HTTP 1.0, assume close after body < HTTP/1.0 406 Not Acceptable: User is not logged in. < Date: Sun, 11 Sep 2011 18:44:13 GMT < Server: Apache/2.2.17 (Win32) PHP/5.3.5 < X-Powered-By: PHP/5.3.5 < Expires: Sun, 19 Nov 1978 05:00:00 GMT < Last-Modified: Sun, 11 Sep 2011 18:44:14 GMT < Cache-Control: store, no-cache, must-revalidate < Cache-Control: post-check=0, pre-check=0 < Vary: Accept < Content-Length: 4 < Connection: close < Content-Type: application/json < null* Closing connection #0

Your curl requests look right to me, but I notice there is a seven minute window between login and logout. What were you doing during that seven minutes? If you logged in or logged out via the web browser during that time, it might have mucked up your session.

login: Date: Sun, 11 Sep 2011 18:37:30 GMT
logout: Date: Sun, 11 Sep 2011 18:44:13 GMT

I got the same result than dhammikab on Drupal 7

If node has a image field how to create node with image?

Hi,

When I retrieve a node (server/rest/node/8.xml) I get the taxonomy or field collection's ids, but not their value/structure... is there any way to get all of the info in one request?

Thank you

How to retrieve a view from services module drupal and display it?i see in service has a option can response a view

any sample for oauth authentication?

I am using user.login service via json server (using an iPad application) It appears that when the login is successful, the service returns the HTML content of the home page, while if it is not, it returns a json string that says why not. I was expecting it to return user information in the form of a json string when user.login is successful.

Is this an issue with my particular set up? Thanks!

i am using put service in android how to update user

hello how to upload video file using rest server file resource

hello how to upload video file using rest server file resource

A good resource to unterstand the module Services is "Services Sandbox. Testing resources on a test server."
http://drupal.org/node/1447020. I wished I explored it first of all!

Howdo create a contact (contact form module) with this service?

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.