Skip to content

Search Parent Benchmarks of Product

Daniel Cronqvist edited this page Dec 11, 2020 · 1 revision

Search Parent Benchmarks of Product - HTTP POST

Endpoint: https://co2.dcronqvist.se/benchmarks/get/parents

Example cURL POST:

$ curl -d '{"product": "accumulator", "search": "latest"}' -H "Content-Type: application/json" -X POST http://localhost:5000/benchmarks/get/parents

Expected payload format (EPF)

The following rules are applied to all keys in the payload using the EPF as a sample:

  1. Keys with arrays of specified types specify which types that are allowed for that specific key.
  2. Keys with specific values only allow that specific value in the payload.
  3. Keys that contain objects are recursively checked using rule 1 and 2.
{
    "product": ["str"],
    "search": ["str"] # must be either "latest" or "all".
}

The field product should contain the _id field of a product in the database.

Responses

200 OK

On successfully specifying an ID of a product that exists, you will be met with a response of the following format, where response is an array of all the benchmarks for the parents of the specified product. If you specified search: "latest", then the list of benchmarks that you receive will be the latest benchmarks for the parents. If you instead specify search: "all", you'll get all benchmarks for all parents.

{
    "response": [ 
        {
            "_id": "accumulator-2020-12-04-10:57:00",
            "date": "2020-12-04",
            "product": "accumulator",
            "kg_per_unit": 0.43,
            "unit": "litre",
            "self_impact": {
                "co2": 0.51,
                "measurement_error": 0.06,
                "energy_sources": [
                    "wind",
                    "nuclear"
                ]
            },
            "chain_impact": {
                "co2": 5904.338,
                "measurement_error": 0
            },
            "sub_products": [
                {
                    "product": "iron-plate",
                    "transport": 7,
                    "unit_amount": 2
                },
                {
                    "product": "battery",
                    "transport": 108,
                    "unit_amount": 5
                }
            ],
            "latest_benchmark": true
        }
    ],
    "status_code": 200,
    "status": "200 OK"
}

400 Bad Request

If you receive a 400 BAD REQUEST, you either have missed a key or have specified a disallowed type for a specific key.

{
    "response": "ERROR: Missing key 'search'",
    "status_code": 400,
    "status": "400 BAD REQUEST"
}

405 Method Not Allowed

If you receive a 405 METHOD NOT ALLOWED, you are trying to access this POST endpoint by using some other HTTP method than POST.

{
    "response": null, 
    "status": "405 METHOD NOT ALLOWED", 
    "status_code": 405
}