The Materials API

From Wiki
Revision as of 14:07, 29 August 2012 by Shyuep (talk | contribs) (materials)

Jump to: navigation, search

The Materials API (MAPI) is an open API for accessing Materials Project data based on REpresentational State Transfer (REST) principles. In a RESTful system, information is organized into resources, each of which is uniquely identified via a uniform resource identifier (URI).

Resources

In the Materials Project, resources are generally packages of information about a material or an analysis (e.g., a reaction). Currently supported information types (v1 of the REST API) include the following:

  1. Materials - Standard calculated or experimental information about a material.
  2. Battery - Battery application specific information
  3. Reaction - Information about a reaction.

Authentication

SSL Encryption

All requests to the Materials API must be done over HTTPS. Non-secure http requests are not allowed and will result in a HTTP 403 (Forbidden) response.

API keys

To access the Materials API, you will need your API key. You can obtain your API key by logging into the Materials Project website, and going to www.materialsproject.org/profile. Your API key and a button to regenerate the key is provided at the top of the page.

Note that the API key effectively allows access to Materials Project data via your account. You should therefore make all efforts to keep it secret and under no circumstances should you share your API key with anyone. You will be held responsible for any violations conducted using your API key. Should anyone else require access to the MAPI, they should register for an account on the Materials Project and generate their own API keys.

All MP https requests must supply API key as:

  • A x-api-key header, e.g., {‘X-API-KEY’: ‘YOUR_API_KEY’} (recommended method) or
  • As a GET (e.g., ?API_KEY=YOUR_API_KEY) or POST variable, e.g., {‘API_KEY’: ‘YOUR_API_KEY’}

The following is an example of a full url requesting for information of the material with material id 1234 with the API key supplied as a GET variable.

https://www.materialsproject.org/rest/v1/1/vasp?API_KEY=YOUR_API_KEY

API documentation

General URI Format

All URIs in the MAPI are of the general form

https://www.materialsproject.org/rest/v1/{request_type}[/{identifier}][/{parameters}]
  1. The initial part of the URI (https://www.materialsproject.org/rest/v1/) is a preamble, specifying a https REST request. The v1 denotes version 1 of the MAPI, to provide flexibility to support multiple versions of the API in future.
  2. {request_type} specifies the kind of information or operation being requested. Currently supported request types include "materials", "battery", "reaction", "mpquery" and "api_check".
  3. {identifier} is an identifier for the specific information requested. Depending on the {request_type}, an identifier may or may not be necessary.
  4. {parameters} - Some requests require additional parameters to be provided.

General Response Format

All responses from the Materials API are in the JavaScript Object Notation (JSON). XML is not supported currently. The responses generally are of the following form:

{
    valid_response: true,
    version: {
        pymatgen: "2.2.0",
        db: "2012.07.09",
        rest: "1.0"
    },
    created_at: "2012-08-29T05:21:51.232084",
    copyright: "Copyright 2012, The Materials Project",
    response: {response_content}
}

Resources

materials

GET https://www.materialsproject.org/rest/v1/materials/{material id, formula, or chemical system}/{vasp/exp}/{properties}

Obtain material information based on an identifier. The response is always a list of associative arrays, i.e., [ {key:value, ... }, {... }, ...]. The identifier can be a Materials Project material id (e.g., 1234), a formula, e.g. (Fe2O3), or a chemical system ("-" separated list of elemments, e.g., Li-Fe-O).

Operations

api_check

GET or POST https://www.materialsproject.org/rest/v1/api_check

Checks if supplied API key (via GET, POST or x-api-key header) is a valid API key.

Example response:

{
    valid_response: true,
    api_key_valid: true
}