Fetching Data
Anatomy of a Request
To learn how the data endpoint works, let's break down the anatomy of an example API request. In this case we're looking at the products exported by Spain in 2023:
1. Root URL
This is the root URL for the API. It will be the same for all requests. This will return a JSON object with a list of records. If you prefer a different format, you can change the extension to
.csv
, .xlsx
, or .parquet
.2. Cube (or dataset)
This is the dataset you want to query. You can find the list of all available datasets by querying the cubes endpoint.
3. Drilldowns
This is the drilldown you want to add to your query. Drilldowns represent the columns (or dimensions) that you want to see in the response. You can find the list of all available drilldowns for this specific cube (or dataset) by querying the trade_i_baci_a_22 cube endpoint.
4. Measures
This is the measure you want to add to your query. Measures represent the columns (or metrics) that you want to see in the response. You can find the list of all available measures for this specific cube (or dataset) by querying the trade_i_baci_a_22 cube endpoint. It is important to note that measures will automatically be aggregated by the cube's default aggregation function.
5. Include (or filter)
These are the filters you want to add to your query. Any column (or dimensions) availble to the specified cube can be used to filter the response. Multiple filters can be added by separating them with a semicolon. Filters take 2 parameters: the column name and the value you want to filter by. To find the available values for a specific column, you can query the members endpoint for that cube along with the level parameter. For example, to find the available values for the Exporter Country column, you can query the 'Exporter Country' members endpoint for the
trade_i_baci_a_22
cube.6. Limit and Offset
This is the limit you want to add to your query where the first number is the limit and the second number is the offset. It is used to limit the number of records returned in the response.
7. Token
This is the token you want to add to your query. It is used to authenticate your request. You can find your token by signing in and clicking the Account link in the top right corner of the page.