Core APIs Quick Start Guides

Here are some guick start quides and code snippets to show you the capabilities of some of the core APIs.

OAuth API Tutorial

Document types are commonly used to populate selection user interface controls.The JavaScript snippet below illustrates the creation of a popup menu with document types and the setting of the chosen value on a document object:

See steps involved

Populate user interface controls for with document types

Catalog API Tutorial

Display readership statistics onto a world map

Displays document reader locations plotted onto a world map. Illustrates implicit OAuth flow, fetching user documents and requesting readership statistics for catalog documents.

GitHub source code repository

Simple catalog query

Perform a general search where the metadata provided matches any terms.

See steps involved

 curl 'https://api.mendeley.com/search/catalog?query=whales' \
					-X GET \
					-H 'Authorization: Bearer ' \
					-H 'Accept: application/vnd.mendeley-document.1+json'

A list of catalog documents is returned from the API resource but only the first item retunred is displayed for brevity. The search query has found all papers with the word whales in any of the fields. Statistics aggregated from all Mendeley users have been provided also.

Advanced catalog search with operators

Perform an advanced search using advanced search operators so that you can get better results. See advanced search

Advanced Search

If you have any metadata about the papers you are searching for then you can use the more advanced searching features. The more fields that you provide then the better the results.

At least one of title, author, source or abstract must be provided. If more than one of these is set, the results will return documents which match any of these, but rank those which match several fields higher than those which match fewer fields.

If you would like to filter down the results to a particular year then you can use the min_year and max_year parameters. Setting either a minimum or maximum year excludes documents which do not have a year defined.

Setting the open_access=true will return just the open access journals.

Advanced Search Operators

If you're having trouble narrowing down your search results, you might want to try using our search operators, which you can use to fine-tune your search query. Follow the examples provided below and edit in your own search terms to see the best results.

Search for... ...to find articles that have
citation analysis the words citation or analysis
citation + analysis both the words citation and analysis
ponies | "small horses" the word ponies OR the exact phrase small horses
ponies +-"small horses" the word ponies but NOT the phrase small horses

Documents API Tutorial

List user documents

Displays current user's documents in their library together with the document annotations. Catalog documents can also be retrieved using a DOI.

GitHub source code repository

Determine if a document for a PDF file exists within the Mendeley catalog

Catalog documents can be fetched from the /catalog API resource using a SHA1 hash of the file. Compute a hash of the PDF file and use as the value for the filehash HTTP query string field. If the response contains a document, the file has been included in the catalog.

See steps involved

openssl sha1 sample.pdf SHA1(/path/to/sample.pdf)= b0b75611366f6a5af8dd906c935f38bf3f509751
curl -H "Authorization: Bearer MSwxNDA5…a1BJUTQ" "https://api.mendeley.com/catalog?filehash=b0b75611366f6a5af8dd906c935f38bf3f509751"

Extract metadata from a PDF

Documents can be created in your library from a PDF. The best metadata available gets returned. It is either the validated record from our /catalog, if it's a paper we already know about, or the data extracted from the PDF, if it's one we've not seen yet. The newly created document data will be returned.

See steps involved

 curl 'https://api.mendeley.com/documents' \
	-X POST \
	-H 'Authorization: Bearer ACCESS_TOKEN' \
	-H 'Content-Type: application/pdf' \
	-H 'Content-Disposition: attachment; filename="example.pdf"' \
	--data-binary @example.pdf     

Determine if documents in a collection have files attached

To determine if documents in a collection may have files attached, inspect the file_attached member of a document. Request all the documents.

See steps involved

GET /documents
{
  "id": "1137042a-8c30-3cd6-a7f6-7d5f1f6c450d",
  …
  "file_attached": true,
  …
}

Get documents for a group

Demonstrates getting all documents in a group.

See steps involved

GET /documents?group_id=77dd7020-e2f6-3fb3-94ea-3cea11555af2

Add a document to a group

Documents created with a group ID included are inserted into the group. The group must exist and the authorized user must be an owner, administrator or member of the group. Adding a library document to a group, creates a copy of the original document.

See steps involved

POST /documents

{
  "group_id":"77dd7020-e2f6-3fb3-94ea-3cea11555af2",
  "title": "Map Reduce: Simplified data processing on large clusters",
  "type": "journal",
  "authors": [
    {
      "first_name": "Jeffrey",
      "last_name": "Dean"
    },
    {
      "first_name": "Sanjay",
      "last_name": "Ghemawat"
    }
  ],
  "year": 2008
}

Files API Tutorial

Check files attached to a document

To determine if a single document has a file attached.

See steps involved

GET /files?document_id=1137042a-8c30-3cd6-a7f6-7d5f1f6c450d

An empty array in the response indicates the document does not have files attached.

To determine if documents in a collection may have files attached, inspect the file_attached member of a document. Request the documents with a client or all value for the view HTTP query string field.

{
  "id": "1137042a-8c30-3cd6-a7f6-7d5f1f6c450d",
  …
  "file_attached": true,
  …
}

Download a media file

Demonstrates downloading a media file.

See steps involved

GET /files/1137042a-8c30-3cd6-a7f6-7d5f1f6c450d

The successful API response will have:

  • 303 See Other HTTP status
  • HTTP Location header containing a link to the file location
  • an empty body

The Location header contains a URL value to download the media file. The URL will only remain valid for a short period of time so your application should not cache these values and should only request a location just before the application intends to download the media file. The URL location, format and authorization mechanism are subject to change and your application must not attempt to parse the download URL.

HTTP/1.1 303 See Other
Location: Location: https://mendeley-files.s3.amazonaws.com/0c/07/0c071302a58db1e471c0923deeb9f47c5cd2f63d?response-content-disposition%3Dattachment%3Bfilename%3D%E2%80%9CReport.pdf%22&response-content-type=application%2Fpdf&AWSAccessKeyId=AKIAJGTIMKBSM3FEA25A&Expires=1409062238&Signature=aLU%2F%2FaqPGYgmiTCgHuKT%2B%2F%2BgWNk%3D
Content-Length: 0

Once the file has completely downloaded to local storage, your application should ensure file integrity by comparing the file size or a SHA1 hash to the API response file metadata.

// API response for file:
{
    "id":"76d0efcb-2690-507f-07b7-21234c617b03",
    "document_id":"1137042a-8c30-3cd6-a7f6-7d5f1f6c450d",
    "mime_type":"application/pdf",
    "file_name":"Report.pdf",
    "size":6123,
    "filehash":"0c071302a58db1e471c0923deeb9f47c5cd2f63d"
}


stat -f %z report.pdf
6123
openssl sha1 report.pdf
SHA1(/path/to/report.pdf)= 0c071302a58db1e471c0923deeb9f47c5cd2f63d

Upload a media file

Each file upload request transfers the media data and creates a new object to reference the media file. Files are uploaded using a POST request with HTTP headers containing the metadata and the body containing the media data. Four additional HTTP headers and values.

See steps involved

POST /files HTTP/1.1
Authorization: Bearer MSwxNDA5MDU0ODM0MTQy…zFJd0liZHpSMVU
Link: <https://api.mendeley.com/documents/1137042a-8c30-3cd6-a7f6-7d5f1f6c450d>; rel="document"
Content-Disposition: attachment; filename="report.pdf"
Content-Type: application/pdf
Content-Length: 6123

[binary data in the request body]

The request HTTP header values should be:

Link
The document relationship must contain the URL to the intended parent document.
Content-Disposition
This must be attachment and your application can use the filename qualifier to suggest a filename.
Content-Type
The Internet MIME type for the uploaded file. Unrecognized MIME types are persisted and delivered as binary data: application/octet-stream.
Content-Length
The number of bytes in the request's body.

A successful file upload generates an HTTP response with:

  • an HTTP status of 201 Created.
  • an HTTP Location header containing the URL of the newly created file.
  • a body containing the JSON representation of the newly created file.

Upload a file object

File objects are immutable and can not be updated. Your client application should replace the document's file in an atomic manner by:

  1. Uploading a new file for the document
  2. Removing the file your application wished to update

Groups API Tutorial

Find the owner of a group

The owner of a group has a profile identifier that can be used to retrieve metadata for the group owner.

See steps involved

  1. Request the group using GET /groups/{id}.
  2. Retrieve the identifier value for the member owning_profile_id from the response.
  3. Use the identifier to request the profile information using GET /profiles/{id}.

Folders API Tutorial

Create a folder inside an existing folder

When creating a new folder, include a value for a parent folder's identifier in the request's body.

See steps involved

POST /folders

{
  "name":"Untitled folder",
  "parent_id":"95342445-ab75-42ba-b98f-888bbe543c0f"
}

Create a folder in a group

When creating a new folder, include a value for the group's identifier in the request's body.

See steps involved

POST /folders

{
  "name":"デジタルコンテンツ",
  "group_id":"9ab2887c-9b1c-38d7-a64a-3491306362a7"
}

Move a folder into another folder

Update the value of the parent_id member to move a folder within a hierarchy. A folder can not be moved into itself or any of it's descendent child folders.

See steps involved

PATCH /folders/9ab2887c-9b1c-38d7-a64a-3491306362a7
{
  "parent_id":"95342445-ab75-42ba-b98f-888bbe543c0f"
}

List the child folders of a folder

It is not possible to list the child folders of a folder directly using the API. Your application should construct a tree model of folders by parsing the results of /folders and using the value of the parent_id member to establish a parent relationship.

Move a folder into the root level

Update the parent_id value of a folder to the special value root to remove any previous parent folder.

See steps involved

PATCH /folders/9ab2887c-9b1c-38d7-a64a-3491306362a7

{
  "parent_id":"root"
}

Document Types API Tutorial

Document types are commonly used to populate selection user interface controls.The JavaScript snippet below illustrates the creation of a popup menu with document types and the setting of the chosen value on a document object:

See steps involved

Populate user interface controls for with document types

…
<select id="doc_type_popup" onchange="docTypeDidChange(this);"></select> <!-- the popup menu in the HTML -->

…
function processDocumentTypesResponse(xmlhttp) {
    // in the successful response to an AJAX request for /document_types
    data = JSON.parse(xmlhttp.responseText);

    popup_menu = document.getElementById("doc_type_popup");
    for (i=0;i<types.length;i++) {
        var option = document.createElement("option");
        option.textContent = types[i].description; // set the label visible to the user
        option.value = types[i].name; // set the data value
        popup_menu.appendChild(option);
    }
}

function docTypeDidChange(sender) {
    selectedDocument.type = sender.value; // assume selectedDocument is a JS object
}