Personal tools

Views

Share:API

From Adobe Labs

Table of contents

Overview

Note: This document is also available as a PDF from HERE.

The Share APIs provide developers with a platform for leveraging Share in their own applications. Share enables any number of users with the requisite privileges to manipulate files and folders located on https://share.acrobat.com. Share uses a relatively simple REST-based interface, so using it requires that developers know a few details about the following:

Accessing the Share API

Developers typically start with an application or create one (such as an AIR application). The application provides the user interface end users interact with to access the Share service. It's the developer's job to connect the application to a networking layer that can create the HTTP headers and XML requests that the Share service can parse. You can write your own code or leverage an existing library for this purpose. Some existing libraries include the following:


HTTP requests and responses

To write applications that leverage or to interact with the Share service, developers should understand the basics of constructing HTTP requests and parsing the HTTP responses. For an overview of Share-specific details, see the following:

Making HTTP Requests

Share API requests may consist of the following components:

Request methods

Each request begins with an HTTP method. Because some clients do not support every HTTP method, alternate syntax is supported. For example, where DELETE is not supported by the client, you can use POST and set a query parameter method to the needed method. For example, the two DELETE requests below are equivalent.

  DELETE https://api.share.acrobat.com/webservices/api/v1/dc/[nodeid/]
  POST https://api.share.acrobat.com/webservices/api/v1/dc/[nodeid/]?method=DELETE

Request path basics

The base (root) path for all requests is always in the format of <https://><base URL><trailing slash>. The base path is then appended with three possible paths plus request-specific node or path information. The possible paths include the following:

  https://api.share.acrobat.com/webservices/api/v1/

For example, a dc/share request with a node ID of xyzDoc would be: POST https://api.share.acrobat.com/webservices/api/v1/dc/xyzDoc/share/. All requests must include the trailing slash.

Request authorization

Using an HTTP request header

Most HTTP requests will include an authorization header which have the following requirements:

  Authorization: AdobeAuth
  apikey="1dbcbb7111618358a3a6c7f62b152381",
  data="POST https://api.share.acrobat.com/webservices/api/v1/auth/ 1196363602050",
  sig="1bda167c5c4a96483b50788430351b43"
  
  
  Authorization: AdobeAuth
  sessionid="3bafbc700acd2ca0d38433230a408c2a",
  apikey="6b8b71755fe80445276d0f7d1d5c3d65",
  data="GET https://api.share.acrobat.com/webservices/api/v1/dc/ 1188518642796",
  sig="308421b3840c7bad180e7ea13b32ffde"
Table: Authorization header parameters
Parameter Description
AdobeAuth A literal string indicating that this is an authorization header.
apikey The API key registered to this application.
dataA concatenation of three values separated by spaces: the HTTP method, the URL of the request, and the timestamp of the request in milliseconds.
sigThe MD5 digest of the string formed by concatenating data with the shared secret returned by an authorization token request.
sessionidThe session ID returned from a new session request. Not used for the initial authorization token and new session requests.
Using authorization parameters in an HTTP request

For clients that do not have access to HTTP headers, the authorization parameters can be passed to Share via an HTTP request method. The parameters apikey, calltime, and sig are required. sessionid is only required for existing sessions.

data is not required. The data string to sign consists of the following:

For example, the data string for the URL https://api.share.acrobat.com/webservices/api/v1/dc/ could look like:

  GET /webservices/api/v1/dc/
  apikey=6b8b71755fe80445276d0f7d1d5c3d65
  calltime=1188518642796
  sessionid=3bafbc700acd2ca0d38433230a408c2a

As with the HTTP authorization header, the signature is formed by taking the MD5 digest of the concatenated data string and the shared secret. After the signature is calculated, the final URL with all the query parameters could appear as below:

  https://api.share.acrobat.com/webservices/api/v1/dc/
  ?apikey=6b8b71755fe80445276d0f7d1d5c3d65
  &calltime=1188518642796
  &sessionid=3bafbc700acd2ca0d38433230a408c2a
  &sig=308421b3840c7bad180e7ea13b32ffde

Requests with XML payloads

As you will learn from the subsequent sections that describe in detail how to communicate with the Share API, not all requests include an XML body. However, when they do, the request XML body element is request. Additional elements containing parameters may reside within the request element. While GET requests will not have elements, PUT and POST usually do. As you refer to the following sections, if a feature is associated with a parameter table, then an XML body must be used. If the parameter is not explicitly listed as optional in the tables below, it is required.

  <request>
  <some element/>
  <anotherelement>Some parameter value</anotherelement>
  </request>

Handling HTTP responses

HTTP responses should be parsed and handled according to the requirements of your application. In general:

XML elements common to file and folder nodes

HTTP responses may or may not be returned with an XML payload depending on the nature of the response. Responses that return information about a file or folder node will generally have the elements shown below.

Table: HTTP response attributes: for files and folders

ElementDescription
createddateThe node creation date.
descriptionThe node description.
directoryTrue if the node is a folder or a directory.
hascontentTrue if the node is a file.
linkTrue if someone else has shared this file with you.
modifieddateThe nodes last modified date.
nameThe node name.
nodeidThe string that uniquely identifies the node.
ownerThe Adobe ID of a given nodes owner.
ownernameThe full owner name of a given node.

XML elements specific to file nodes

HTTP responses may or may not be returned with an XML payload depending on the nature of the response. Responses that return information about a file nodes will generally have the elements shown below.

Table: HTTP response attributes: for files only

ElementDescription
adobedocTrue if the file is a special file from Adobe.
authorThe author of a document, if the author's name was able to be extracted from file metadata.
filesizeThe file size in bytes.
flashpreviewembedThe HTML object code that can be used to embed a flash preview in a web page.
flashpreviewpagecountThe number of document pages if a flash preview was successfully generated.
flashpreviewstateThe preview state: 1: The flash preview is ready. 0: The flash preview is still being generated. -1: Flash preview generation failed.
mimetypeThe file type, such as PDF, doc, and so on.
pdfstate-1: Failed. 0: Unknown. 1: Not available for download. 2: Available for download. 3: Converting.
recipients (child element's "recipient")The Adobe IDs of each person with which the document has been shared. Each Adobe ID will be a child recipient element.
recipienturlThe URL a recipient uses to view a document (such as a link in an email).
sharelevelThe share level: 0: The file is unshared. 1: The file is only accessible to those with whom the file has been shared. 2: The file is publicly accessible.
thumbnailstateThe thumbnail state: 1: The thumbnail is ready 0: the thumbnail is still being generated. -1: Thumbnail generation failed.

Error Messages for responses

The error messages shown below pertain to all calls and may be returned by any request. Additional errors may be returned for any request-specific errors.

Table: HTTP response: error messages

StatusReason
BadApikeyThe given API key is invalid.
BadAuthHeaderThe authorization header has the wrong format or syntax.
BadAuthQueryThe query does not contain the required parameters. This error is only returned when the authorization parameters are passed in an HTTP request rather than in an HTTP header as described in Using authorization parameters in an HTTP request.
BadCalltimeThe given calltime has problems:
  • Either it does not come after the calltime of the most recent successful request, or
  • The request was issued too soon after the prior request.

The suggested time between requests per session is half a second.

BadFormatThe request body is malformed.
BadSessionidThe given sessionid does not exist or is expired.
BadSigThe authorization signature is incorrect.
ErrorAn unknown error has occurred.
LimitReachedThe number of allowable requests was exceeded in the last hour.
MissingElementsThe request body is missing required elements.
UnauthorizedThe user does not have authorization to perform the requested action.

Authentication and sessions

Before an application can leverage the Share API, the application must initiate an API session on behalf of the user. Doing so requires two steps:

Requesting an authorization token

Authenticating a request requires that it includes a user's Adobe ID credentials. When the Share service receives the user's username and password, it returns an authorization token.

auth/ gets an authorization token for use with subsequent requests. It is only used for initial authentication. Before starting a session, you must post a user's credentials to receive an authorization token for use with subsequent requests.

Example: auth token request path

  POST https://api.share.acrobat.com/webservices/api/v1/auth/

Table: Auth request XML parameters

ParameterDescription
usernameThe user's Adobe ID username.
passwordThe user's Adobe ID password.

Example: auth request

  <request>
  <username>user@domain.com</username>
  <password>qwerty123</password>
  </request>

Authorization response

Table: Response: auth XML parameters

ParameterDescription
authtokenA token that can be used to request a new session. Each token is valid only for one session start request.

Example: auth response

 <response status="ok">
 <authtoken>22e7909e7453cf0b62f656ecae66efdf</authtoken>
 </response>

Error messages for authization

If the request fails, error messages may be returned. See also the general errors described in Error Messages for responses.

Table: Error messages: auth api request

ErrorDescription
BadLoginInvalid username or password.
LockedOutToo many failed login attempts; try again later.

Starting a new session

After an authentication token has been returned from the previous request, that token can be used once to start a new session.

sessions/ starts and ends Share sessions. After getting an authorization token, use sessions to obtain a Share session ID for use with all subsequent requests. An authorization token can be used only once to request a session. If this session request fails, a new authorization token is required (see Requesting an authorization token).

Example: session token request path

  POST https://api.share.acrobat.com/webservices/api/v1/sessions/

Table: Auth request XML parameters

ParameterDescription
authtoken Single-use authorization token returned from auth/.

Example: session request

  <request>
  <authtoken>22e7909e7453cf0b62f656ecae66efdf</authtoken>
  </request>

Authorization response

Table: Session response XML parameters

ParameterDescription
sessionidThe new session ID which to use in the Authorization header of all subsequent requests.
secretThe new, shared secret to use in the Authorization header of all subsequent requests.
levelUser's subscription level: 0: Trial. >0: Subscribed. -1: Special account.

Example: Response: session XML parameters

  <response status="ok">
  <sessionid>1ab1a6190dc1f1f849ca7649190cca83</sessionid>
  <secret>3965c47eb9c937f78d49f3f33e19ca45</secret>
  <level>1</level>
  </response>

Authorization error messages

If the request fails, error messages may be returned. See also the general errors described in Error Messages for responses.

Table: Error messages: session api request

ErrorDescription
BadAuthtokenInvalid authorization token.

Ending a session

delete immediately ends a session. As shown below, there are alternate methods for ending a session. The session will automatically be deleted after 1 hour of inactivity.

Example: HTTP request: for ending a session (method 1)

  DELETE https://api.share.acrobat.com/webservices/api/v1/sessions/[sessionid/]

Example: HTTP request for ending a session (method 2)

  POST https://api.share.acrobat.com/webservices/api/v1/sessions/[sessionid/]?method=DELETE

Error messages for ending a session

If the request fails, error messages may be returned. See also the general errors described in Error Messages for responses.

Table: Error messages: End session request

ErrorDescription
BadSessionidThe session ID is invalid.

Managing files and folders

Once the use is authenticated and a session ID obtained through the use of auth and sessions, you application can manipulate files and folders as well as access to them.

dc/ provides requests to work with files and folders. Requests using dc/ may or may not require an XML request payload. In general, GET requests do no require XML while most PUT and POST requests provide XML containing information about files or folders or instructions for the Share API.

For example, using a GET method with dc and a node ID does not require XML. Share simply returns all the child nodes for that node ID. Each child node is returned with the information shown in XML elements common to file and folder nodes as well as XML elements specific to file nodes if it is a file.

Many PUT and POST requests require an XML payload in the request as described below. The XML elements and their parameters listed in the tables below are required.

Listing file and folder information

A dc request with a node ID retrieves information about a given node. The following rules apply:

Example: dc request: GET for listing node details

  GET https://api.share.acrobat.com/webservices/api/v1/dc/[nodeid/]

Example: dc request: XML payload for listing node details

 <response status="ok">
 <node />
 <children>
 <node>
    snip ----------- File and folder details -----------
 <node />
 <node>
    snip ----------- Another node.... until the nth node -----------
 <node /
 </children>
 </response>
 

Creating a PDF

See Uploading a file below.

Uploading a file

To upload a file, construct a POST request with a node ID and an XML payload describing the file. The file will be added to the folder with the given node ID. The following rules apply:

Example: dc request: POST for file upload

POST https://api.share.acrobat.com/webservices/api/v1/dc/[nodeid]

Example: dc request: XML payload for file upload

 <request>
 <file>
 <name>myfile.pdf</name>
 <description>My File</description>
 <renditions>true</renditions>
 <createpdf>true</createpdf>
 </file>
 </request>

Table: dc request XML parameters: file upload

ParameterDescription
nameFile name.
descriptionOptional.
renditionsIf true, uploads the file, and then automatically creates thumbnail, preview, and PDF renditions after upload. If false, adds only the file.
createpdfOptional. If true, uploads the file, and then automatically createsa PDF of the file. If false, adds only the file.
Multi-part POST requests

Files can be uploaded and added through the API using multi-part POST requests. The format for these requests adheres to the standard RFC1867. For details, see http://www.ietf.org/rfc/rfc1867.txt.

Example: dc request: Multi-part POST request

 POST /webservices/api/v1/dc/ HTTP/1.1
 Host: api.share.acrobat.com
 Content-type: multipart/form-data, boundary=314159265358979323846
 Content-Length: 12345
 Authorization: AdobeAuth................
 
 ------------------314159265358979323846
 
 content-disposition: form-data; name="request"
 <request>
 <file>
 <name>test.pdf</name>
 <description>My File</description>
 <renditions>true</renditions>
 </file>
 </request>
 
 ------------------314159265358979323846
 
 content-disposition: form-data; name="file"; filename="test.pdf"
 Content-Type: application/octet-stream
 Content-Transfer-Encoding: binary
 binary data here...
 
 ------------------314159265358979323846

Upload response

Share returns all the node elements shown in shown in XML elements common to file and folder nodes as well as XML elements specific to file nodes if it is a file.

Example: dc request: File upload response

 <response status="ok">
 <node>
 first node data
 </node>
 
.....
 
 <node>
 nth node data
 </node>
 </response>

Upload error messages

If the request fails, error messages may be returned. See also the general errors described in Error Messages for responses.

Table: Error messages: File upload

ErrorDescription
QuotaReachedAdding the file would exceed the user's storage quota.

Adding a folder

To add a folder, construct a POST request with a node ID and an XML payload describing the folder. The folder will be added to the folder with the given node ID. The following rules apply:

Example: dc request: POST for adding a folder

  POST https://api.share.acrobat.com/webservices/api/v1/dc/[nodeid]

Example: dc request: XML payload for adding a folder

  <request>
  <folder>
  <name>New Folder</name>
  <description>This is a new folder</description>
  </folder>
  </request>

Table: dc request XML parameters: Adding a folder

ErrorDescription
nameThe new folder's name.
descriptionOptional. A description of the new folder.

Adding a folder response

Share returns all the node elements shown in XML elements common to file and folder nodes as well as XML elements specific to file nodes if it is a file.

Example: Response: for adding a folder

 <response status="ok">
 <node>
 first node data
 </node> 
 
.....
 
 <node>
 nth node data
 </node>
 </response>

Adding a folder error messages

If the request fails, error messages may be returned. See also the general errors described in Error Messages for responses.

Table: Error messages: Adding a folder

ErrorDescription
ErrorThe error is returned when the Share API cannot understand the request; for example, when the sent node ID doesn't exist.

This is a generic error. Error handling will be further refined in future releases.

Deleting a file or folder

To delete a file or folder, construct a request with a node ID as shown below. The node will be deleted to the folder with the given node ID. The following rules apply:

Example: DELETE method for deleting nodes

 DELETE https://api.share.acrobat.com/webservices/api/v1/dc/[nodeid/]

Example: POST method for deleting nodes

 POST https://api.share.acrobat.com/webservices/api/v1/dc/[nodeid/]?method=DELETE

Deleting a node response

No XML is returned if there are no errors The response header includes the HTTP status code of 200 indicating the request has succeeded.

Deleting a node error messages

If the request fails, error messages may be returned. See also the general errors described in Error Messages for responses.

Table: Error messages: Deleting a node

ErrorDescription
ErrorThe error is returned when the Share API cannot understand the request; for example, when the sent node ID doesn't exist.

This is a generic error. Error handling will be further refined in future releases.

Moving or renaming a file or folder

To move or rename a node (a file or a folder), construct a request with a node ID as shown below. The node is moved or renamed as specified in the request. The following rules apply:

Example: MOVE for renaming nodes

 MOVE https://api.share.acrobat.com/webservices/api/v1/dc/[nodeid/]?[destnodeid=newfolderid&]newname=newid

Example: POST for moving nodes

 POST https://api.share.acrobat.com/webservices/api/v1/dc/[nodeid/]?method=MOVE

Table: dc request XML parameters: Moving or renaming file and folder

ParameterDescription
destnodeidOptional and for moving only. The folders node id or else the root for the root folder.
newnameThe new name for the file or folder. For moving a node, it can be the current name.

Moving or renaming node response

No XML is returned if there are no errors The response header includes the HTTP status code of 200 indicating the request has succeeded.

Moving or renaming node error messages

If the request fails, error messages may be returned. See also the general errors described in Error Messages for responses.

Table: Error messages: moving or renaming a node

ErrorDescription
ErrorThe error is returned when the Share API cannot understand the request; for example, when the sent node ID doesn't exist.

This is a generic error. Error handling will be further refined in future releases.

Sharing a file

To share a file or a folder, construct a PUT request with a node ID and an XML payload describing the folder. You can specify an optional email message which is automatically sent to those you share the node's URL with. The following rules apply:

Example: PUT for sharing files

 PUT https://api.share.acrobat.com/webservices/api/v1/dc/[nodeid/]share/

Example: XML payload for sharing files

 <request>
 <share>
 <user>alice@example.com</user>
 <user>bob@example.com</user>
 </share>
 <message>hello world</message>
 <level>2</level>
 </request>

Table: dc request XML parameters: File sharing

ParameterDescription
levelThere are two possible values:

1: Private share: Access is limited to the specified users.

2: Public share: Anyone can access the files.

messageOptional. A message to be included in the notification email.
userThe user's email address.

Sharing a file response

No XML is returned if there are no errors The response header includes the HTTP status code of 200 indicating the request has succeeded.

Sharing a file error messages

If the request fails, error messages may be returned. See also the general errors described in Error Messages for responses.

Table: Error messages: Sharing a file

ErrorDescription
ErrorThe error is returned when the Share API cannot understand the request; for example, when the sent node ID doesn't exist.

This is a generic error. Error handling will be further refined in future releases.

Adding or removing recipients

To add or remove user access to a file that has been shared, construct a POST request with a node ID and an XML payload describing the changes. You can specify an optional email message which is automatically sent to those whose privileges change. The following rules apply:

Example: POST for adding or removing recipients

 POST https://api.share.acrobat.com/webservices/api/v1/dc/[nodeid/]share/

Example: XML payload for adding or removing recipients

 <request>
 <share>
 <user>alice@example.com</user>
 <user>bob@example.com</user>
 </share>
 <unshare>
 <user>charles@example.com</user>
 </unshare>
 <message>You now have access to my documents (except for Charles).</message>
 </request>

Table: dc request XML parameters: Adding or removing recipients

ParameterDescription
shareThe parent element for the list of users with which to share the file or folder.
unshareThe parent element for the list of users with which to unshare the file or folder.
userThe user(s) email address to add or remove.
messageOptional. The message to be included in an email to the user.

Adding recipient response

No XML is returned if there are no errors The response header includes the HTTP status code of 200 indicating the request has succeeded.

Adding recipient error messages

If the request fails, error messages may be returned. See also the general errors described in Error Messages for responses.

Table: Error messages: Adding a recipient

ErrorDescription
ErrorThe error is returned when the Share API cannot understand the request; for example, when the user ID is malformed.

This is a generic error. Error handling will be further refined in future releases.

Accessing file renditions

A rendition is the representation of the file provided to the requester. A request can ask for either a thumbnail, the file source, or both. To request a file rendition, construct a request with a node ID. The following rules apply:

Example: GET for a thumbnail

 GET https://api.share.acrobat.com/webservices/api/v1/dc/[nodeid/]thumbnail/

Example: GET for the file source

 GET https://api.share.acrobat.com/webservices/api/v1/dc/[nodeid/]src/

Table: dc request XML parameters: Adding or removing recipients

ParameterDescription
thumbnailThe file's thumbnail, if any.
srcThe actual node's source. For example, for a text file, it returns the text.

Assessing file rendition response

Depending on the nature of the request, Share can return the following:

Assessing file rendition error messages

If the request fails, error messages may be returned. See also the general errors described in Error Messages for responses.

Table: Error messages: deleting a node

ErrorDescription
ErrorThe error is returned when the Share API cannot understand the request; for example, when the node ID doesn't exist or it refers to a folder instead of a file.

This is a generic error. Error handling will be further refined in future releases.

Retrieved from "http://labs.adobe.com/wiki/index.php/Share:API"