# How to fetch data on waste generated in Switzerland

This tutorial will guide you through the process of querying the waste produced in Switzerland in 2021 using the Plasteax API. We will cover how to structure the request and extract relevant data following two approaches:

* Command Line (`curl` command)
* Python (`requests` module)

To retrieve waste data for Switzerland, you need to send a **GET request** with the appropriate query parameters.

**API endpoint**

```
https://2oqef6q7rg.execute-api.eu-west-3.amazonaws.com/plasteax/datasets
```

{% hint style="warning" %}
The provided URL is a testing API accessing a database with mock data. To get access to real Plasteax data, use the URL giving access to the real dataset.
{% endhint %}

## Using the Command Line

Run the following command in your terminal:

```bash
curl -s "https://2oqef6q7rg.execute-api.eu-west-3.amazonaws.com/plasteax/datasets?country=CHE&year=2021&polymer=All%20polymers&category=All%20packaging" | jq .
```

The `-s` flag enables silent mode, hiding progress information. Use piping (`|`) with the command `| jq .` to format JSON output for better readability. Using `jq` is optional, but not doing so results in a less readable output.

{% hint style="info" %}
You might need to install the `jq` command in case this is not already present in your system. We refer to [this page](https://jqlang.org/) for more details regarding the installation of jq.
{% endhint %}

You may notice that we appended to the API's url the following string:

```
?country=CHE&year=2021&polymer=All%20polymers&category=All%20packaging
```

The string begins with a `?` followed by the values of the parameters that one wants to filter through. Each parameter is separated by `&` , and for values containing a space (like `All packaging` or `All polymers`) it is necessary to replace the space character with `%20`.

The resulting output will provide all the waste metrics related to the queried plastic types, in this case looking like:

{% code overflow="wrap" %}

```bash
{
  "pagination": {
    "total-items": 1
  },
  "elements": [
    {
      "country": "CHE",
      "category": "All packaging",
      "polymer": "All polymers",
      "year": 2021,
      "production_and_import": {
        "amount": 0.1641169957,
        "unit": "kt"
      },
      "export": {
        "amount": 0.2541901517,
        "unit": "kt"
      },
      "added_stock": {
        "amount": 0.7775922097,
        "unit": "kt"
      },
      "waste_import": {
        "amount": 0.8221494483,
        "unit": "kt"
      },
      "reexport_of_waste_import": {
        "amount": 0.0227327712,
        "unit": "kt"
      },
      "recycling_of_waste_import": {
        "amount": 0.3095788595,
        "unit": "kt"
      },
      "proper_disposal_of_waste_import": {
        "amount": 0.080751776,
        "unit": "kt"
      },
      "improper_disposal_of_waste_import": {
        "amount": 0.0229187221,
        "unit": "kt"
      },
      "waste_produced_in_the_country": {
        "amount": 0.0324434147,
        "unit": "kt"
      },
      "domestic_recycling_of_collected": {
        "amount": 0.8705851923,
        "unit": "percent"
      },
      "export_of_collected": {
        "amount": 0.2905947668,
        "unit": "percent"
      },
      "incineration_and_energy_recovery": {
        "amount": 0.6945896879,
        "unit": "percent"
      },
      "sanitary_landfill": {
        "amount": 0.5443557105,
        "unit": "percent"
      },
      "improperly_disposed": {
        "amount": 0.2169245555,
        "unit": "percent"
      },
      "littering": {
        "amount": 0.5919855952,
        "unit": "percent"
      },
      "uncollected_excluding_littering": {
        "amount": 0.7726378055,
        "unit": "percent"
      },
      "total": {
        "amount": 0.2947628798,
        "unit": "percent"
      },
      "collected": {
        "amount": 0.420612656,
        "unit": "percent"
      },
      "mismanaged_including_littering": {
        "amount": 0.0795666505,
        "unit": "percent"
      },
      "leaked_to_ocean_and_waterways": {
        "amount": 0.9158901908,
        "unit": "percent"
      }
    }
  ]
}
```

{% endcode %}

To extract information about a specific metric, e.g. the waste produced in the country, we can rely again on the `jq` command. By running the command

```
curl -s "https://2oqef6q7rg.execute-api.eu-west-3.amazonaws.com/plasteax/datasets?country=CHE&year=2021&polymer=All%20polymers&category=All%20packaging" | jq ".elements[0].waste_produced_in_the_country"
```

we finally obtain the desired output:

```
{
  "amount": 0.0324434147,
  "unit": "kt"
}
```

## Using Python

Run the following script from a Jupiter note or a Python shell:

```python
import requests

# Define url and desired parameters
url = 'https://2oqef6q7rg.execute-api.eu-west-3.amazonaws.com/plasteax/datasets'
params = {
    'country': 'CHE',
    'year': '2021',
    'polymer': 'All polymers',
    'category': 'All packaging'
}

# Get the data from the Plasteax database
response = requests.get(url, params=params)

# Store the output in a JSON format
output = response.json()

# Extract info about waste generated
result = output['elements'][0]['waste_produced_in_the_country']
print(result)

```

The resulting output provides the volume of waste generated in Switzerland in 2021 across all polymer types and packaging categories:&#x20;

```python
{'amount': 0.0324434147, 'unit': 'kt'}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.plasteax.earth/tutorials/tutorial-1-get-the-domestic-waste-generated-in-switzerland.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
