The Guardian

The Guardian

News

Access all the content the Guardian creates, categorised by tags and section. Our API stores all articles, images, audio and videos dating back to 1999. All accessible with a single open platform key. Free instant access for developers We believe in the open source community. That's why any non-profit project can use our content for free. Commercial packages available We're always looking to collaborate with new partners and create new ways to distribute our content. Request a commercial key and our team will be in touch to discuss your needs.

Visit API

📚 Documentation & Examples

Everything you need to integrate with The Guardian

🚀 Quick Start Examples

The Guardian Javascript Examplejavascript
// The Guardian API Example
const response = await fetch('http://open-platform.theguardian.com/', {
    method: 'GET',
    headers: {
        'Content-Type': 'application/json'
    }
});

const data = await response.json();
console.log(data);

Introduction to The Guardian's Open Platform API

The Guardian's Open Platform API provides developers with access to a wealth of content from one of the world's leading news organizations. The API offers a wide range of data, from article and video content to galleries and live blogs, that can be used to enrich your own application or website.

One of the main advantages of The Guardian API is its ease of use. To access the content you just need to register for a free API key. Once you have your key, you're ready to start exploring the API and retrieving data in a variety of formats.

Using the API with JavaScript

The Guardian API supports a variety of programming languages, but JavaScript is perfect for web developers who want to create dynamic content for their users. Here are some example codes using JavaScript to interact with The Guardian API.

Load Latest Headline

This code retrieves the latest headline from The Guardian's home page and displays it on your site.

$.getJSON("http://content.guardianapis.com/search?order-by=newest&show-fields=headline,byline&api-key=[YOUR API KEY HERE]", function (data) {
    var headline = data.response.results[0].fields.headline;
    var byline = data.response.results[0].fields.byline;
    $('#latest_headline').html("<h3>" + headline + "</h3><p>" + byline + "</p>");
});

Retrieve Article Content

This code retrieves the full content of a specific article from The Guardian and inserts it into a div with the id of "article_content".

$.getJSON("http://content.guardianapis.com/[ARTICLE ID]?show-fields=body&api-key=[YOUR API KEY HERE]", function (data) {
    var article = data.response.content.fields.body;
    $('#article_content').html(article);
});

Search for Content

This code searches The Guardian's database for articles that match a specific search term and displays them on your site.

$.getJSON("http://content.guardianapis.com/search?q=[SEARCH TERM]&show-fields=headline,byline&api-key=[YOUR API KEY HERE]", function (data) {
    var articles = "<ul>";
    $.each(data.response.results, function (i, result) {
        articles += "<li>" + "<h3>" + result.fields.headline + "</h3><p>" + result.fields.byline + "</p></li>";
    });
    articles += "</ul>";
    $('#search_results').html(articles);
});

Conclusion

The Guardian's Open Platform API is a powerful resource for developers who want to incorporate news content into their own sites and applications. With a little bit of JavaScript code, you can easily retrieve the latest headlines, full article content, and search results from The Guardian's extensive database of news and information. Get started today by registering for your free API key!

📊 30-Day Uptime History

Daily uptime tracking showing online vs offline minutes

Jun 8Jun 10Jun 12Jun 14Jun 16Jun 18Jun 20Jun 22Jun 24Jun 26Jun 28Jun 30Jul 2Jul 4Jul 704008001440Minutes
Online
Offline

Related APIs in News