-
Notifications
You must be signed in to change notification settings - Fork 0
Create Product
Daniel Cronqvist edited this page Dec 11, 2020
·
5 revisions
Endpoint: https://co2.dcronqvist.se/products/create
Example cURL POST:
$ curl -X POST -d '{ "_id": "IKEA-BILLY", "kg_per_unit": 25, "unit": "piece", "type": "product", "tags": ["Furniture"], "type_description": "Assembly", "prod_name": "IKEA Billy Shelf", "benchmark": { "self_impact": { "co2": 5.1, "measurement_error": 0.05, "energy_sources": ["Solar", "Nuclear", "Wind"] }, "date": "2020-12-01-00:05:32", "sub_products": [] } }' -H "Content-Type: application/json" https://co2.dcronqvist.se/products/create
The following rules are applied to all keys in the payload using the EPF as a sample:
- Keys with arrays of specified types specify which types that are allowed for that specific key.
- Keys with specific values only allow that specific value in the payload.
- Keys that contain objects are recursively checked using rule 1 and 2.
{
'_id': ["str"], # e.g. "IKEA-BILLY-5"
'type': "product", # will always be product
'tags': ["list:str"], # e.g. ["furniture", "shelf", "wood"]
'type_description': ["str"], # "Assembly"
'prod_name': ["str"], # e.g. "Billy Shelf"
'kg_per_unit': ["float", "int"], # e.g. 12.81
'unit': ["str"],
'benchmark': {
"self_impact": {
"co2": ["float", "int"], # e.g. 292.62
"measurement_error": ["float"], # e.g. 0.05 -> 5% error margin
"energy_sources": ["list:str"] # e.g. ["Solar", "Nuclear", "Wind"]
},
"date": ["str"], # e.g. "2020-11-30-22:50:51"
"sub_products": [
{
"product": ["str"],
"unit_amount": ["float", "int"],
"transport": ["int"]
}
]
}
}
On successfully creating a new product, you will be met with the exact same object as you requested, together with a 200 OK
.
{
"response": {
'_id': ["str"], # e.g. "IKEA-BILLY-5"
'type': "product", # will always be product
'tags': ["list:str"], # e.g. ["furniture", "shelf", "wood"]
'type_description': ["str"], # "Assembly"
'prod_name': ["str"], # e.g. "Billy Shelf"
'kg_per_unit': ["float", "int"], # e.g. 12.81
'unit': ["str"],
'benchmark': {
"self_impact": {
"co2": ["float", "int"], # e.g. 292.62
"measurement_error": ["float"], # e.g. 0.05 -> 5% error margin
"energy_sources": ["list:str"] # e.g. ["Solar", "Nuclear", "Wind"]
},
"date": ["str"], # e.g. "2020-11-30-22:50:51"
"sub_products": [
{
"product": ["str"],
"unit_amount": ["float", "int"],
"transport": ["int"]
}
]
}
},
"status_code": 200,
"status": "200 OK"
}
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 '_id'",
"status_code": 400,
"status": "400 BAD REQUEST"
}
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
}
- Create Product
- Search Product by ID
- Search Product by Tags
- Get all tags used on Products
- Get all Product ID's
- Regex Search Product ID's
- Regex Search Product names