Description of the code sample
The following command applies the properties listed in "properties.xml" to a user with user ID = 1.
Sample Code
curl -u admin:password -H "Content-Type: application/xml" -T properties.xml -i http://mindtouch.address/@api/deki/users/1/properties
Implementation notes
curl flags
- -u
- Basic HTTP authentication. Sends a username and password to server so it can verify whether a user is of privilege to perform specific operation.
- -H
- Adds a header or modifies an existing one. In this case, since an xml document is being sent, the content type must be set to "application/xml". The server will not accept the request otherwise.
- -T file
- Specifies the .xml file that contains the user property data.
- -i
- Includes the HTTP response header in the output. Useful for debugging.
Permissions
ADMIN permission is required to execute above command. Otherwise, a 403 HTTP response (Forbidden) will be returned.
Example
Batman happens to be a MindTouch user. We want to make changes to his properties. The following XML document adds a couple properties and removes the "alterego" property added in this example. Batman's user ID = 4.
batman.xml
Content-Type: application/xml
<properties>
<!-- Add a couple properties -->
<property name="location">
<contents type="text/plain">Gotham</contents>
</property>
<property name="transportation">
<contents type="text/plain">Batmobile</contents>
</property>
<!-- Remove a property, to do this omit contents element -->
<property name="alterego"/>
</properties>
Command Line
curl -u admin:password -H "Content-Type: application/xml" -T batman.xml -i http://192.168.168.110/@api/deki/users/4/properties
HTTP Response Headers
HTTP/1.1 200 OK
Date: Tue, 12 Jan 2010 23:51:20 GMT
Server: Dream-HTTPAPI/1.7.2.17433
X-Deki-Site: id="default"
Content-Type: application/xml; charset=utf-8
Content-Length: 2444
Via: 1.1 dekiwiki
HTTP Response Body
Content-Type: application/xml
<?xml version="1.0"?>
<properties count="3" href="http://192.168.168.110/@api/deki/users/4/properties">
<property name="location" href="http://192.168.168.110/@api/deki/users/4/properties/location/info" etag="37.r1_ts2010-01-12T23:51:20Z">
<contents type="text/plain" size="6" href="http://192.168.168.110/@api/deki/users/4/properties/location">Gotham</contents>
<date.modified>2010-01-12T23:51:20Z</date.modified>
<user.modified id="1" href="http://192.168.168.110/@api/deki/users/1">
<nick>Admin</nick>
<username>Admin</username>
<email>melder@mindtouch.com</email>
<hash.email>637b79dca5c8ebdc4347bccca42d3487</hash.email>
<uri.gravatar>http://www.gravatar.com/avatar/637b79dca5c8ebdc4347bccca42d3487</uri.gravatar>
</user.modified>
<status code="200"/>
</property>
<property name="transportation" href="http://192.168.168.110/@api/deki/users/4/properties/transportation/info" etag="38.r1_ts2010-01-12T23:51:20Z">
<contents type="text/plain" size="9" href="http://192.168.168.110/@api/deki/users/4/properties/transportation">Batmobile</contents>
<date.modified>2010-01-12T23:51:20Z</date.modified>
<user.modified id="1" href="http://192.168.168.110/@api/deki/users/1">
<nick>Admin</nick>
<username>Admin</username>
<email>melder@mindtouch.com</email>
<hash.email>637b79dca5c8ebdc4347bccca42d3487</hash.email>
<uri.gravatar>http://www.gravatar.com/avatar/637b79dca5c8ebdc4347bccca42d3487</uri.gravatar>
</user.modified>
<status code="200"/>
</property>
<property name="alterego" href="http://192.168.168.110/@api/deki/users/4/properties/alterego/info" etag="35.r2_ts2010-01-12T23:51:20Z">
<contents type="text/plain" size="11" href="http://192.168.168.110/@api/deki/users/4/properties/alterego">Bruce Wayne</contents>
<date.modified>2010-01-12T23:51:20Z</date.modified>
<user.modified id="1" href="http://192.168.168.110/@api/deki/users/1">
<nick>Admin</nick>
<username>Admin</username>
<email>melder@mindtouch.com</email>
<hash.email>637b79dca5c8ebdc4347bccca42d3487</hash.email>
<uri.gravatar>http://www.gravatar.com/avatar/637b79dca5c8ebdc4347bccca42d3487</uri.gravatar>
</user.modified>
<user.deleted id="1" href="http://192.168.168.110/@api/deki/users/1">
<nick>Admin</nick>
<username>Admin</username>
<email>melder@mindtouch.com</email>
<hash.email>637b79dca5c8ebdc4347bccca42d3487</hash.email>
<uri.gravatar>http://www.gravatar.com/avatar/637b79dca5c8ebdc4347bccca42d3487</uri.gravatar>
</user.deleted>
<date.deleted>2010-01-12T23:51:20Z</date.deleted>
<status code="200"/>
</property>
</properties>