Skip to main content

In this article, we’ll walk you through the process of making your first API request.

Initial Steps

The data retrieval process begins with below mentioned steps:

1. Account Creation

Sign up for an account on NewsData.io to obtain your unique API key.

2. Choosing the Endpoint

A variety of endpoints are provided, each catering to specific types of news data.

For instance, the “latest” endpoint retrieves the latest news articles across various sources.

3. Constructing the API Request URL

To construct the API request URL combine the base URL with the chosen endpoint. This forms the foundation of your API call.

https://newsdata.io/api/1/latest?apikey=Your_API_KEY&q=YOUR_QUERY

4. Adding Query Parameters

Query parameters are the building blocks of an effective API request. They help narrow down your search to specific criteria, making your results more relevant.

For instance, In the “latest” endpoint, you can use parameters like “country,” “category,” or “q” (keywords) to tailor your results.

5. Including API Key

Insert your API key to the URL as a parameter, ensuring NewsData.io recognizes your request as authorized.

6. Making the API Request

You can use tools like cURL, Python, or API client software to send your request. Once dispatched, you await the response.

First API Request With Postman

Let’s understand how users can make the first request with Postman.

Given below is the base parameter that users have to enter:

https://newsdata.io/api/1/latest?apikey=YOUR_API_KEY

You can further add more parameters and advance search options provided like q, qInTitle, qInMeta, etc.

To help you understand better, here is an example with the query of football.

The news article retrieval request would be;

https://newsdata.io/api/1/latest?apikey=YOUR_API_KEY&q=football

Making first API request with Postman

This query will fetch all the relevant articles on football.

First API Request With cURL

To extract data using cURL, follow these steps:

1. Install cURL on your desktop.
2. Construct the Curl command by writing “curl” and then entering the query.
For example;

curl https://newsdata.io/api/1/latest?apikey=YOUR_API_KEY&q=pizza

3. cURL will extract all the data of your query in JSON format.

cURL first API request

Additional parameters, such as language, category, and domain name, can also be used.

To help you understand better, given below is an example.
The given request will look for news stories in English language with the keyword “pizza” published between January 19, 2023, and January 25, 2023.

https://newsdata.io/api/1/archive?apikey=YOUR_API_KEY&q=pizza&language=en&from_date=2023-01-19&to_date=2023-01-25

FIrst API request with cURL

After submitting your request, you will receive a JSON response containing the news articles that meet your search parameters.

First API Request Through NewData.io Dashboard

To learn how to extract the articles without coding, follow the steps below:

1. Account Creation: Sign up for an account on NewsData.io to obtain your unique API key.
API request sign-in

2. Searching your Query: After account creation, go back to your NewsData.io homepage.

3. Click on “Dashboard” at the top right corner. You will then be redirected to the NewsData.io dashboard. Here, you can fetch data using the search bar(as shown below) as displayed on your screen.

For example, you have added the query “Ronaldo.”. The API will fetch all the related articles.

Users can also use advanced search filters, such as:

  • Date Range: This allows users to filter the data based on date.

NOTE: For free users, the data from the past 48 hours and for paid basic users, up to the past 6 months, can be fetched.
For the professional plan, users can retrieve 1 year of historical data, and for the corporate plan, they can retrieve 2 years of historical data.

NOTE: Users can also request up to 5 years of historical data by contacting us at contact@newsdata.io.

  • Country: This helps filter articles based on country-specific.
    For example, if you set the country to Russia, then the API would fetch keyword-related news from Russia only.
  • Category: NewsData.io provides 12 different types of categories. You can filter the data based on categories such as sports, politics, science, etc.
  • Language: You can filter the news articles based on 77 different languages. This prevents linguistic barriers.
    First API request with Newsdata.io Dashboard
    So fetching the data from the dashboard was quite easy, but there were limits to some of the features and parameters.

First API Request With Python

To make the first request from a Python client, follow the steps below:

  • Obtain API Key
    The first step is obtaining your unique API key by registering for an account. This serves as the authentication token for your requests.
  • Install ‘newsdataapi’
    “pip install newsdataapi”This command will install newsdataapi to your Python library.
  • Import ‘NewsDataApiClient’ package to your program.
    from newsdataapi import NewsDataAPIClientThis command will import the ‘NewsDataApiClient’ package to your program.
  • For API key authorization, Initialize the client with your API key
    api = NewsDataApiClient(apikey='YOUR_API_KEY')
  • Within the brackets (), you can enter any parameter like q, timeframe, category, etc.
    response = api.news_api() print(response)
  • This command will fetch all the articles related to pizza.
    response = api.news_api(q='pizza') print(response)
First API request with Postman

Click here to learn more about Python client requests.

Leave a Reply