Daily Indices

Learn how to retrieve all daily indices and their metadata.

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:

Press + to interact
http://dataservice.accuweather.com/indices/v1/daily

Request parameters

Parameter

Type

Category

Description

API_KEY

string

required

This is our API key.

This is a query parameter.

language

string

optional

This is the language in which we have to return the results. Its default value is en-us.

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.

Press + to interact
// Importing libraries here
import fetch from "node-fetch";
// Define API key here
const API_KEY = '{{API_KEY}}';
// Define endpoint URL here
const url = new URL(`http://dataservice.accuweather.com/indices/v1/daily`);
// Define header parameters here
const headerParameters = {
contentType: 'application/json',
};
// Define query parameters here
const queryParameters = new URLSearchParams({
apikey: API_KEY,
});
// Setting API call options
const options = {
method: 'GET',
headers: headerParameters,
};
// Function to make API call
async function getAllIndices() {
try {
url.search = queryParameters;
const response = await fetch(url, options);
// Custom function for printing the API response
printResponse(response);
} catch (error) {
// Custom function for printing the error message
printError(error);
}
}
// Calling function to make API call
getAllIndices();

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 using fetch and handle any exception if it occurs. The custom functions printResponse() and printError() 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

Name

string

This is the name of the index.

ID

integer

This is the ID of the index.

This value may be null.

Ascending

boolean

This is the order of the index values.

If this is set to true, the best value is 10 and the poorest is 0. If false, then the best value is 0 and the poorest is 10.

Description

string

This is the description of the index type.