On this page
- Description
- Operations
- Retrieve
- Definition
- Example CURL Bash script for Retrieve operation
- Example Response Data
- Response Fields Definition
- Create
- Definition
- Example CURL Bash script for Create Operation
- Example POST data
- Example Response
- Delete
- Definition
- Example CURL Bash script for Delete operation
- Example Response
Services Content Lock Documentation
Description
services_content_lock adds Services support to the community module called content_lock that will prevent two users from editing the same node concurrently. This module exposes the main operations of content_lock through Services as a resource, so that content locking can be done over a web service API such as REST. The main operations it currently implements are retrieve, create, and delete. This page will document how to use the operations in this resource.
Operations
The operations this resource implements for content_lock are:
- retrieve - Find out if a node is locked and get info about a lock e.g. who owns the lock and when it was created.
- create - Create a new content lock on a node. Locks a node preventing other users from editing it.
- delete - Deletes an existing lock on a node. Only the lock owner may delete the lock.
Below each operation is documented in detail, including example CURL commands.
Retrieve
Definition
Example CURL Bash script for Retrieve operation
#!/bin/bash
# Drupal Session cookie of an authenticated user.
COOKIE=SESS49960de5880e8c687434170f6476605b=xo1yKeavUmvACa7_vDYSiXTu2-xDCF0Vq5SMG8BHE8g
# Drupal hostname where services is running
DRUPAL_HOST=localhost
# ENDPOINT corresponds to the path of the Services endpoint, that has
# the content_lock resource enabled that you configured under:
# admin/structure/services
# You can also import this endpoint by clicking the "Import" link at the page
# above and then copy and pasting the contents of the this file:
# services_content_lock/examples/endpoint_import.txt
ENDPOINT=content_lock_api
# NID you want to get retrieve content_lock info from
NID=1
curl -vkL -X GET -b $COOKIE -H "Accept: application/xml" "http://$DRUPAL_HOST/?q=$ENDPOINT/content_lock/$NID"
Example Response Data
<?xml version="1.0" encoding="utf-8"?>
<result>
<nid>1</nid>
<uid>1</uid>
<timestamp>1355340407</timestamp>
<ajax_key>2000157999</ajax_key>
<name>admin</name>
</result>
Response Fields Definition
|
nid |
The node id that the locked node. |
|
uid |
The drupal user id of the user who owns the lock |
|
timestamp |
The timestamp that the lock was created. This can be used to derive the |
|
ajax_key |
Random number used by the UI. Can be ignored. |
|
name |
The username of the user who owns the lock. |
Create
Definition
Example CURL Bash script for Create Operation
#!/bin/bash
# Drupal Session cookie of an authenticated user.
COOKIE=SESS49960de5880e8c687434170f6476605b=xo1yKeavUmvACa7_vDYSiXTu2-xDCF0Vq5SMG8BHE8g
# Drupal hostname where services is running
DRUPAL_HOST=localhost
# ENDPOINT corresponds to the path of the Services endpoint, that has
# the content_lock resource enabled that you configured under:
# admin/structure/services
# You can also import this endpoint by clicking the "Import" link at the page
# above and then copy and pasting the contents of the this file:
# services_content_lock/examples/endpoint_import.txt
ENDPOINT=content_lock_api
curl -vkL -X POST -b $COOKIE -H "Content-Type: application/xml" --data "`cat ./lock.xml`" "http://$DRUPAL_HOST/?q=$ENDPOINT/content_lock/"
Example POST data
In the above example “lock.xml” would look like this:
<?xml version="1.0" encoding="utf-8"?>
<lock>
<nid>1</nid>
</lock>
Example Response
<?xml version="1.0" encoding="utf-8"?>
<result>Lock successfully created on node: 2</result>
Delete
Definition
Example CURL Bash script for Delete operation
#!/bin/bash
# Drupal Session cookie of an authenticated user.
COOKIE=SESS49960de5880e8c687434170f6476605b=xo1yKeavUmvACa7_vDYSiXTu2-xDCF0Vq5SMG8BHE8g
# Drupal hostname where services is running
DRUPAL_HOST=localhost
# ENDPOINT corresponds to the path of the Services endpoint, that has
# the content_lock resource enabled that you configured under:
# admin/structure/services
# You can also import this endpoint by clicking the "Import" link at the page
# above and then copy and pasting the contents of the this file:
# services_content_lock/examples/endpoint_import.txt
ENDPOINT=content_lock_api
# NID you want to get retrieve content_lock info from
NID=1
curl -vkL -X DELETE -b $COOKIE -H "Accept: application/xml" "http://$DRUPAL_HOST/?q=$ENDPOINT/content_lock/$NID"
Example Response
<?xml version="1.0" encoding="utf-8"?>
<result>Lock successfully deleted on node: 1</result>
Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion