Skip to main content

If you’re new to APIs or simply starting your journey with NewsData.io then this article will be extremely helpful for you. In this article, we’ll walk you through your maiden (first) API request, ensuring a smooth entry into news data retrieval.

There are 3 ways to make your first request to NewsData.io News API. Please find the ways below:

    • Through software like browsers, Postman, and cURL
    • Through NewsData.io dashboard
    • Through NewsData.io Python clients

Steps to access the first request (Postman)

      1. Account Creation: Sign up for an account on NewsData.io to obtain your unique API key. This key serves as your passport to access the API’s functionalities.
      2. Choosing the Endpoint: The documentation provides a variety of endpoints, each catering to specific types of news data. For your first request, the “News” endpoint is an excellent starting point. This endpoint retrieves the latest news articles across various sources. Similarly, you can use the archive endpoint (which allows you to fetch historical news, only available in paid plans), crypto endpoint (to get crypto-related news, only available in corporate plan), and news source endpoint (to get information of 100 random news domains).
      3. Constructing the API Request URL: Start by constructing the API request URL by combining the base URL (provided in the documentation) with the chosen endpoint. This forms the foundation of your API call.
      4. Adding Query Parameters: Query parameters are the building blocks of an effective API request. In the case of the “News” endpoint, you can use parameters like “country,” “category,” or “q” (keywords) to tailor your results. These parameters narrow down your search to specific criteria, making your results more relevant.
      5. Including Your API Key: Authentication is paramount in API usage. Append your API key to the URL as a parameter, ensuring that NewsData.io recognizes your request as authorized.
      6. Making the API Request: Depending on your programming environment, you can use tools like cURL, Python, or API client software to send your request. Once dispatched, you await the response.

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

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

This would be the base parameter that users have to enter. Apart from that you can further add more parameters and advance search options that NewsData.io provides which is q, qInTitle, qInMeta, News Archive, Crypto, News Sources, and so on.

Let’s understand the first request with an example by taking up the query of Chandrayaan.

The news article retrieval request would be:

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

As shown above, this query will fetch all the relevant articles on Chandrayaan.

Accessing First Request Through 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 enter the query for example your query is https://newsdata.io/api/1/news?apikey=YOUR_API_KEY&q=pizza
      3. cURL will extract all the data of your following query in JSON format.

This request will look for the most recent news articles containing the keyword “pizza.” The apikey argument is required in all queries and is used to authenticate your account. Additional parameters, such as language, category, domain name, and so on, can be used to refine your search.

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

This request will look for English-language news stories with the keyword “pizza” that were published between 19 January 2023 to 25 January 2023. After submitting your request, you will receive a JSON response containing the news articles that meet your search parameters.

Accessing News Articles Through NewData.io Dashboard

You can also access the news articles through our dashboard which is exclusively offered by us. To know how you can extract the articles without any coding requirements follow the steps below:

1. Account Creation: Sign up for an account on NewsData.io to obtain your unique API key. This key serves as your access to the API’s functionalities.

2. Navigate To your Homepage: After creating your account. Go to your NewsData.io homepage and you can search your query from there as shown in image below.

3. Go To Dashboard: Click on “Dashboard” top right corner and you will be redirected to the NewsData.io dashboard. In which all you have to do is enter your query For example I have added the query “Ronaldo”. The API will fetch all the articles containing the query “Ronaldo”.

Users can also perform advanced search filters such as:

      • Date Range: Date Range filter allows the users to filter the data on the basis of date. For free users the past 48 hours data will be fetched and for paid users basic users can request up to past 6 months of data. The professional plan users can retrieve 1 year of historical data and for corporate 2 years of historical data. Users can also request up to 5 years of historical data by contacting us at contact@newsdata.io
      • Country: This filter option would help you to filter articles on the basis of country-specific. For example, if have set the country to Russia then the API would fetch me the news of entered keyword only of Russia.
      • Category: NewsData.io provides 12 different types of categories by which you can filter out the data on the basis of categories such as sports, politics, science, etc.
      • Language: You can filter out the news articles on the basis of 77 different languages so you won’t have to face a linguistic barrier.

So fetching the data from the dashboard was quite easy but limits in some of the features and parameters.

First request through Python

To make first request from Python client start by installing the “newsdataapi” using pip command

pip install newsdataapi

This command will install newsdataapi to your Python library.

from newsdataapi import NewsDataAPIClient

This command will import newsdataapi to your Python library.

api = NewsDataApiClient(apikey=’YOUR_API_KEY’)

(For API key authorization, Initialize the client with your API key )

response = api.news_api() print(response)

Within the brackets () you can enter any parameter that NewsData.io offers like q, timeframe, category, etc.

response = api.news_api(q='pizza')
print(response)

This command will fetch all the articles related to pizza.

To know more about Python client request we have dedicated blog to make you understand more briefly.

Conclusion

Your first API request with NewsData.io marks the beginning of an exciting journey into the world of accessing real-time news data. With the knowledge gained from this article, you’re ready to navigate the API, construct your requests, and receive valuable insights into the ever-evolving world of news.

 Whether you’re a developer, researcher, or simply curious, this inaugural step paves the way for a deeper understanding of APIs and their limitless potential.

Leave a Reply