Skip to content

Search Product by Tags

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

Search Product by Tags - HTTP POST

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

Example cURL POST:

$ curl -X POST -d '{ "tags": ["iron", "green"] }' -H "Content-Type: application/json" https://co2.dcronqvist.se/products/search/tags

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 tags which is an array of strings.

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

Responses

200 OK

On successfully specifying an array of tags which are of type str, you will be met with a response of the following format. The field response will contain an array of all the products that have all of the specified tags in the payload.

{
    "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 are no products that have all of the tags specified in the payload, you will receive a 404 NOT FOUND error.

{
    "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 tags or you have not specified the field tags to be an array of strings.

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