Skip to content

Search Product by ID

Daniel Cronqvist edited this page Dec 11, 2020 · 4 revisions

Search Product by ID - HTTP POST

Endpoint: https://co2.dcronqvist.se/products/search/id

Example cURL POST:

$ curl -X POST -d '{ "_id": ["accumulator", "steel-axe"] }' -H "Content-Type: application/json" https://co2.dcronqvist.se/products/search/id

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.

The payload should contain the field _id which is an array of strings.

{
    "_id": ["list:str"],
}

Responses

200 OK

On successfully specifying an array of id's that exist in the database, you will receive an array of all the products with the specified id's.

{
    "response": [ {
        "_id": ["str"], # e.g. "IKEA-BILLY-5"
        "type": "product", # will always be product
        "tags": ["list"], # e.g. ["furniture", "shelf", "wood"]
        "type_description": ["str"], # "Assembly"
        "prod_name": ["str"], # e.g. "Billy Shelf"
    }],
    "status_code": 200,
    "status": "200 OK"
}

404 Not Found

If there were no found products for the specified id's, then you will be met a 404 NOT FOUND.

{
    "response": "No products found.",
    "status_code": 404,
    "status": "404 NOT FOUND"
}

400 Bad Request

If you receive a 400 BAD REQUEST, you are either missing the field _id or you have not specified the field _id to be an array of strings.

{
    "response": "ERROR: On key '_id', expected 'str', got 'float'.",
    "status_code": 404,
    "status": "404 NOT FOUND"
}