The intent of this document is to walk you through some basic operations of the Cloud Storage Platform API. After completing this howto, you should feel comfortable with the basic operations of the Cloud Storage Platform API and be able to begin creating your own application that leverages cloud storage.
Minor text editing to create the XML snippets used as input to create the different resources in the API will be needed.
Note: The GUID values will be different for each user and for each item created since they are globally unique.
Note:“$Key”represents your client (API) key. You will need to specify it for each operation.
This howto will use the following command line programs:
- curl (http://curl.haxx.se/)
- xmlstarlet (http://xmlstar.sourceforge.net/)
For a more in-depth description of the Cloud Storage Platform API, please reference the Developer Guide.
Container Listing Operation
Each user has a root container that contains all the files and containers that are created and placed in the system using the API.
To get started with the API, let us use curl to do a HTTP/1.1 GET on the root resource to retrieve all the resources that are available to you:
Example curl command:
curl -u $cred -H ‘X-Client-Specification: 2’ –H ‘X-Cloud-Key: $Key’\
-X GET https://api.example.com/v2 | xml foThis will return a Cloud resource listing similar to the following which contains a URI for the root container:
<?xml version="1.0" encoding="UTF-8"?>
<cloud xmlns:xlink="http://www.w3.org/1999/xlink">
<rootContainer xlink:href="https://api.example.com/v2/containers/9EC89EB0" xlink:type="simple"/>
<contacts xlink:href="https://api.example.com/v2/contacts" xlink:type="simple"/>
<shares xlink:href="https://api.example.com/v2/shares" xlink:type="simple"/>
<metacontainers xlink:href="https://api.example.com/v2/metacontainers" xlink:type="simple"/>
<account xlink:href="https://api.example.com/v2/account" xlink:type="simple"/>
<tags xlink:href="https://api.example.com/v2/tags" xlink:type="simple"/>
<recyclebin xlink:href="https://api.example.com/v2/recyclebin" xlink:type="simple"/ >
</cloud>
To retrieve information regarding the rootContainer, run the following command:
Example curl command:
curl -u
<username>:<password> https://api.example.com/v2/containers/9EC89EB0 | xml fo
<?xml version="1.0" encoding="UTF-8"?>
<container xmlns:xlink="http://www.w3.org/1999/xlink">
<name>/</name>
<created>1246900106</created>
<inproject>False</inproject>
<modified>1248120109</modified>
<owner>username@api.example.com</owner>
<version>0</version>
<shared>False</shared>
<accessed>1248120109</accessed>
<bytes>307219976</bytes>
<contents xlink:href="https://api.example.com/v2/containers/9EC89EB0/contents" xlink:type="simple"/>
<tags xlink:href="https://api.example.com/v2/containers/9EC89EB0/tags" xlink:type="simple"/>
<parent xlink:href="https://api.example.com/v2/containers/9EC89EB0" xlink:type="simple"/>
</container>
curl -u
<username>:<password> \
https://api.example.com/v2/containers/9EC89EB0/contents \
| xml fo
<?xml version="1.0" encoding="UTF-8"?>
<file-list xmlns:xlink="http://www.w3.org/1999/xlink">
<container xlink:href="https://api.example.com/v2/containers/782B9650" xlink:type="simple"/>
<file xlink:href="https://api.example.com/v2/files/539C8EBC" xlink:type="simple"/>
</file-list>
Container Create Operation
newcontainer.xml
<container>
<name>New container</name>
</container>
curl -u <username>:<password> -X POST \
-H 'Content-Type: application/vnd.csp.container-info+xml' \
https://api.example.com/v2/containers/9EC89EB0/contents -d @newcontainer.xml
<?xml version="1.0" encoding="UTF-8"?>
<file-list xmlns:xlink="http://www.w3.org/1999/xlink">
<container xlink:href="https://api.example.com/v2/containers/782B9650" xlink:type="simple"/>
<container xlink:href="https://api.example.com/v2/containers/B22DA7BA" xlink:type="simple"/>
<file xlink:href="https://api.example.com/v2/files/539C8EBC" xlink:type="simple"/>
</file-list>
Container Rename Operation
updatecontainer.xml
<container>
<name>Renamed Container</name>
</container>
curl -v -u <username>:<password> -X PUT \
-H 'Content-Type: application/vnd.csp.container-info+xml' \
https://api.example.com/v2/containers/B22DA7BA -d @updatecontainer.xmlContainer Move Operation
updatecontainer.xml
<container>
<parent xlink:href="https://api.example.com/v2/containers/E0463284" xlink:type="simple"/>
</container>
curl -v -u
<username>:<password> -X PUT \
-H 'Content-Type: application/vnd.csp.container-info+xml' \
https://api.example.com/v2/containers/B22DA7BA -d @updatecontainer.xmlContainer Copy Operation
<?xml version="1.0" encoding="UTF-8"?>
<container xmlns:xlink="http://www.w3.org/1999/xlink">
</container>
curl -v -u
<username>:<password> -X POST \
-H 'Content-Type:
application/vnd.csp.container-info+xml'
\
-H 'Content-Location: https://api.example.com/v2/containers/B22DA7BA' \
https://api.example.com/v2/containers/782B9650/contents -d @copycontainer.xmlContainer Delete Operation
curl -v
-u
<username>:<password>
-X DELETE \
https://api.example.com/v2/containers/B22DA7BAContact Listing Operation
curl -u <username>:<password> -X GET https://api.example.com/v2/contacts | xml fo
<?xml version="1.0" encoding="UTF-8"?><contacts xmlns:xlink="http://www.w3.org/1999/xlink">
<contact xlink:href="https://api.example.com/v2/contacts/4121DDB8" xlink:type="simple"/>
</contacts>
curl -u <username>:<password> https://api.example.com/v2/contacts/4121DDB8 | xml fo
<?xml version="1.0" encoding="UTF-8"?>
<contact>
<firstname>FirstName</firstname>
<lastname>LastName</lastname>
<email>firstlast@api.example.com</email>
</contact>
Contact Create Operation
<contact>
<firstname>John</firstname>
<lastname>Doe</lastname>
<email>john.doe@api.example.com</email>
</contact>
curl -u <username>:<password> -X POST -H 'Content-Type: application/vnd.csp.contact+xml' https://api.example.com/v2/contacts -d @newcontact.xml
<?xml version="1.0" encoding="UTF-8"?>
<contacts xmlns:xlink="http://www.w3.org/1999/xlink">
<contact xlink:href="https://api.example.com/v2/contacts/4121DDB8" xlink:type="simple"/>
<contact xlink:href="https://api.example.com/v2/contacts/1440339C" xlink:type="simple"/>
</contacts>
Contact Update Operation
<contact>
<firstname>John</firstname>
<lastname>Doe</lastname>
<email>john@doe.com</email>
</contact>
curl -u
<username>:<password>
-X PUT \
-H
'Content-Type:
application/vnd.csp.contact+xml'
\
https://api.example.com/v2/contacts/1440339C -d @updatecontact.xmlContact Delete Operation
curl -u <username>:<password> -X DELETE https://api.example.com/v2/contacts/1440339CShared Items Listing Operation
curl -u <username>:<password> -X GET https://api.example.com/v2/shares | xml fo
<?xml version="1.0" encoding="UTF-8"?>
<file-list xmlns:xlink="http://www.w3.org/1999/xlink">
<file xlink:href="https://api.example.com/v2/files/539C8EBC" xlink:type="simple"/>
<file xlink:href="https://api.example.com/v2/files/C6553BAC" xlink:type="simple"/>
</file-list>
curl -u <username>:<password> https://api.example.com/v2/files/539C8EBC | xml fo
<?xml version="1.0" encoding="UTF-8"?>
<file xmlns:xlink="http://www.w3.org/1999/xlink">
<name>shared-file.dat</name>
<created>1247062329</created>
<inproject>False</inproject>
<modified>1247062329</modified>
<owner>john.doe@api.example.com</owner>
<version>1</version>
<shared>True</shared>
<accessed>1247062329</accessed>
<public>false</public>
<mime_type>application/octet-stream</mime_type>
<bytes>307200000</bytes>
<content xlink:href="https://api.example.com/v2/files/539C8EBC/content" xlink:type="simple"/>
<parent xlink:href="https://api.example.com/v2/containers/9EC89EB0" xlink:type="simple"/>
<permissions xlink:href="https://api.example.com/v2/files/539C8EBC/permissions" xlink:type="simple"/>
<tags xlink:href="https://api.example.com/v2/files/539C8EBC/tags" xlink:type="simple"/>
<thumbnail xlink:href="https://api.example.com/v2/files/539C8EBC/thumbnail" xlink:type="simple"/>
</file>
Share Permissions Assignment Operation
<permission>
<grantee>john.doe@example.com</grantee>
<expiration/>
<permissions>rw</permissions>
</permission>
curl -u <username>:<password> -X POST \
-H 'Content-Type: application/vnd.csp.permission+xml' \
https://api.example.com/v2/projects/797B1992/permissions -d @permissions.xmlShare Permissions Removal Operation
curl -u <username>:<password> -X DELETE https://api.example.com/v2/files//permissions/
Tag Listing Operation
curl -u <username>:<password> -X GET https://api.example.com/v2/tags | xml fo
<?xml version="1.0" encoding="UTF-8"?>
<tags xmlns:xlink="http://www.w3.org/1999/xlink">
<tag
xlink:href="https://api.example.com/v2/tags/NewTag"
xlink:type="simple"/>
</tags>
curl -u <username>:<password> https://api.example.com/v2/tags/NewTag | xml fo
<?xml version="1.0" encoding="UTF-8"?>
<tag xmlns:xlink="http://www.w3.org/1999/xlink">
<name>NewTag</name>
<objects
xlink:href="https://api.example.com/v2/tags/NewTag/objects"
xlink:type="simple"/>
</tag>
curl -u <username>:<password> https://api.example.com/v2/tags/NewTag/objects | xml fo
<?xml version="1.0" encoding="UTF-8"?>
<file-list xmlns:xlink="http://www.w3.org/1999/xlink">
<file xlink:href="https://api.example.com/v2/files/CE0D4812" xlink:type="simple"/>
</file-list>
Tag Create Operation
<tag>
<name>New Tag2</name>
</tag>
curl -u <username>:<password> -X POST \
-H 'Content-Type: application/vnd.csp.tag-info+xml' \
https://api.example.com/v2/files/CE0D4812/tags -d @tag.xml
<?xml version="1.0" encoding="UTF-8"?>
<tags xmlns:xlink="http://www.w3.org/1999/xlink">
<tag xlink:href="https://api.example.com/v2/tags/NewTag" xlink:type="simple"/>
<tag xlink:href="https://api.example.com/v2/tags/New%20Tag2" xlink:type="simple"/>
</tags>
Tag Deletion Operation
curl -u <username>:<password> -X DELETE \
https://api.example.com/v2/files/CE0D4812/tags/New%20Tag2RecycleBin Listing Operation
curl -u <username>:<password> -X GET https://api.example.com/v2/recyclebin | xml fo
<?xml version="1.0" encoding="UTF-8"?>
<file-list xmlns:xlink="http://www.w3.org/1999/xlink">
<container xlink:href="https://api.example.com/v2/recyclebin/782B9650" xlink:type="simple"/>
<file xlink:href="https://api.example.com/v2/recyclebin/539C8EBC" xlink:type="simple"/>
</file-list>
curl -u <username>:<password> https://api.example.com/v2/recyclebin/782B9650 | xml fo
<?xml version="1.0" encoding="UTF-8"?>
<file-list xmlns:xlink="http://www.w3.org/1999/xlink">
<container
xlink:href="https://api.example.com/v2/recyclebin/782B9650" xlink:type="simple"/>
<bytes>0</bytes>
<originalname>Renamed Container</originalname>
<recycleddate>1248212805</recycleddate>
</container>
</file-list>
RecycleBin Item Deletion Operation
curl -u <username>:<password> -X DELETE \
https://api.example.com/v2/recyclebin/782B9650RecycleBin Item Restore Operation
curl -u <username>:<password> -X RESTORE \
https://api.example.com/v2/recyclebin/539C8EBCMetaData Listing Operation
curl -u <username>:<password> -X GET https://api.example.com/v2/files/CE0D4812-6A75-11DE-8B5A-BF486DC27EE3/metadata | xml fo
<?xml version="1.0" encoding="UTF-8"?>
<metadata-list xmlns:xlink="http://www.w3.org/1999/xlink">
<metadata-item xlink:href="https://api.example.com/v2/files/CE0D4812/metadata/example"
xlink:type="simple"/>
</metadata-list>
curl -u <username>:<password> \
https://api.example.com/v2/files/CE0D4812/metadata/example | xml fo
<application>
<code>ED09</code>
</application>
MetaData Create Operation
This is the note contents.
curl -u <username>:<password> -X PUT \
-H 'Content-Type: application/txt' \
https://api.example.com/v2/files/CE0D4812/metadata/note -d @note.txt
<?xml version="1.0" encoding="UTF-8"?>
<metadata-list xmlns:xlink="http://www.w3.org/1999/xlink">
<metadata-item xlink:href="https://api.example.com/v2/files/CE0D4812/metadata/example"
xlink:type="simple"/>
<metadata-item xlink:href="https://api.example.com/v2/files/CE0D4812/metadata/note"
xlink:type="simple"/>
</metadata-list>
MetaData Get Operation
curl -u <username>:<password> -X GET \
https://api.example.com/v2/files/CE0D4812/metadata/noteThis is the note contents.
Metadata Deletion Operation
curl -u <username>:<password> -X DELETE \
https://api.example.com/v2/files/CE0D4812/metadata/noteFile Upload
- Multi-part form upload
Use a multi-part form upload Uploads the file all at once.
Required form elements:
- filename – name of the file to create
- form-data – binary file contents
curl -u <username>:<password> -F "file=@testfile.txt;filename=testfile.txt" https://api.example.com/v2/containers/9EC89EB0/contents - Two-part process
- Create the file resource
- Upload the file in one or more pieces using HTTP/1.1 PUT
Example curl command:
curl -u <username>:<password> -X PUT \ https://api.example.com/v2/files/CE0D4812/content --data-binary @filedata.bin
File Create Operation (Empty)
<file>
<name>testfile.txt</name>
<mime_type>text/plain</mime_type>
<public>false</public>
</file>
curl -u <username>:<password> -X POST \
-H 'Content-Type: application/vnd.csp.file-info+xml' \
https://api.example.com/v2/containers/9EC89EB0/contents -d @newfile.xml
<?xml version="1.0" encoding="UTF-8"?>
<file-list xmlns:xlink="http://www.w3.org/1999/xlink">
<container xlink:href="https://api.example.com/v2/containers/782B9650" xlink:type="simple"/>
<container xlink:href="https://api.example.com/v2/containers/B22DA7BA" xlink:type="simple"/>
<file xlink:href="https://api.example.com/v2/files/539C8EBC" xlink:type="simple"/>
<file xlink:href="https://api.example.com/v2/files/4B6B15E4" xlink:type="simple"/>
</file-list>
File Rename Operation
<file>
<name>test file renamed.txt</name>
<mime_type>text/plain</mime_type>
<public>false</public>
</file>
curl -v -u <username>:<password> -X PUT \
-H 'Content-Type: application/vnd.csp.file-info+xml' \
https://api.example.com/v2/files/4B6B15E4 -d @updatefile.xmlFile Move Operation
<file xmlns:xlink="http://www.w3.org/1999/xlink">
<name>testfile.txt</name>
<mime_type>text/plain</mime_type>
<public>false</public>
<parent xlink:href="https://api.example.com/v2/containers/E0463284" xlink:type="simple"/>
</file>
curl -v -u
<username>:<password> -X PUT \
-H 'Content-Type: application/vnd.csp.file-info+xml' \
https://api.example.com/v2/containers/B22DA7BA -d @updatefile.xmlFile Copy Operation
<?xml version="1.0" encoding="UTF-8"?>
<file xmlns:xlink="http://www.w3.org/1999/xlink">
</file>
curl -v -u
<username>:<password> -X POST \
-H 'Content-Type:
application/vnd.csp.file-info+xml'
\
-H 'Content-Location: https://api.example.com/v2/containers/B22DA7BA' \
https://api.example.com/v2/containers/782B9650/contents -d @copyfile.xml