Skip to content

Search all Benchmarks for Product

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

Search all Benchmarks for Product - HTTP POST

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

Example cURL POST:

$ curl -d '{"product": "accumulator"}' -H "Content-Type: application/json" -X POST https://co2.dcronqvist.se/benchmarks/get/all

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"]
}

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 ever created for that product. Be careful with this endpoint as the more benchmarks that are created for a product, the larger the array that is returned will be.

{
    "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 'product'",
    "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
}