inspirehep.net

Science

Getting started with Inspire API

Inspirehep.net provides API services to access their scientific publications and author's data. In this tutorial, we'll learn how to use the Inspire API to fetch publications, authors, and a list of fields that we can query for.

Before we get started exploring the Inspire API, we need to create a free account. We'll get an API key after signing up. We'll be using this API key to authenticate each request we make to the Inspire API.

Authorizing the Inspire API

We'll use the Authorization header to authenticate each request. The format of the Authorization header is:

Authorization: Bearer <access_token>

Where <access_token> is the API key generated when we signed up for the Inspire API.

We need to make sure that our API key is not public and is only visible to us.

Fetching Publications

To fetch publications, make a GET request to the following endpoint:

https://inspirehep.net/api/literature?q=<query>[&p=<page>]

Where <query> is the search query and <page> is the page number of the results (optional).

Here is some sample JavaScript code that demonstrates how to make a request to the Inspire API to fetch publications:

const apiKey = "<insert api key here>";
const query = "find publications authored by John Doe";
const endpoint = `https://inspirehep.net/api/literature?q=${query}`;

fetch(endpoint, { headers: { Authorization: `Bearer ${apiKey}` } })
  .then((response) => response.json())
  .then((data) => console.log(data));

Fetching Authors

To fetch authors, make a GET request to the following endpoint:

https://inspirehep.net/api/authors?q=<query>[&p=<page>]

Where <query> is the search query and <page> is the page number of the results (optional).

Here is some sample JavaScript code that demonstrates how to make a request to the Inspire API to fetch authors:

const apiKey = "<insert api key here>";
const query = "find authors with the family name Doe";
const endpoint = `https://inspirehep.net/api/authors?q=${query}`;

fetch(endpoint, { headers: { Authorization: `Bearer ${apiKey}` } })
  .then((response) => response.json())
  .then((data) => console.log(data));

Fetching Fields

To fetch the list of fields we can query for, make a GET request to the following endpoint:

https://inspirehep.net/api/literature/fields

Here is some sample JavaScript code that demonstrates how to make a request to the Inspire API to fetch the list of fields:

const apiKey = "<insert api key here>";
const endpoint = "https://inspirehep.net/api/literature/fields";

fetch(endpoint, { headers: { Authorization: `Bearer ${apiKey}` } })
  .then((response) => response.json())
  .then((data) => console.log(data));

Conclusion

In this tutorial, we learned how to use the Inspire API to fetch publications, authors and a list of fields that we can query for. With the help of the sample JavaScript code provided, you can easily get started with the Inspire API. Please refer to the API documentation for more endpoints and parameters that you can use to search and retrieve data from Inspire.

Related APIs in Science