Daily Indices
Learn how to retrieve all daily indices and their metadata.
We'll cover the following
In this lesson, we'll learn how to retrieve a list of all daily indices and their metadata.
List all daily indices
We make a GET request to the following URL to get a list of all daily indices and their metadata:
http://dataservice.accuweather.com/indices/v1/daily
Request parameters
Parameter | Type | Category | Description |
| string | required | This is our API key. This is a query parameter. |
| string | optional | This is the language in which we have to return the results. Its default value is This is a query parameter. |
You can try adding the optional parameter language
to the queryParameters
object on lines 16–18 to get results in a language of your choice.
Click the "Run" button to see the output.
// Importing libraries hereimport fetch from "node-fetch";// Define API key hereconst API_KEY = '{{API_KEY}}';// Define endpoint URL hereconst url = new URL(`http://dataservice.accuweather.com/indices/v1/daily`);// Define header parameters hereconst headerParameters = {contentType: 'application/json',};// Define query parameters hereconst queryParameters = new URLSearchParams({apikey: API_KEY,});// Setting API call optionsconst options = {method: 'GET',headers: headerParameters,};// Function to make API callasync function getAllIndices() {try {url.search = queryParameters;const response = await fetch(url, options);// Custom function for printing the API responseprintResponse(response);} catch (error) {// Custom function for printing the error messageprintError(error);}}// Calling function to make API callgetAllIndices();
Let's take a quick look at the code given in the widget above:
Line 8: We define the endpoint URL.
Lines 16–18: We define the query parameters.
Lines 27–38: We define a custom function
getAllIndices()
to make an API call usingfetch
and handle any exception if it occurs. The custom functionsprintResponse()
andprintError()
are used to print the API response and errors, respectively.Line 41: We invoke the
getAllIndices()
function.
The output of the code above displays all daily indices as a list of objects. For each of these index objects, it provides its metadata that comprises the attributes given in the table below. In case of failure, an appropriate error message is displayed.
Response fields
Parameter | Type | Description |
| string | This is the name of the index. |
| integer | This is the ID of the index. This value may be null. |
| boolean | This is the order of the index values. If this is set to |
| string | This is the description of the index type. |