Skip to content

Search Benchmarks for Product by date

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

Search Benchmarks for Product by date - HTTP POST

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

Example cURL POST:

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

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"],
    "date": ["str"] # format 2020-12-06
}

The field product should contain the _id field of a product in the database, and the field date should contain a date that follows the format YYYY-MM-DD.

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 benchmarks that were created on that date.

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