Skip to content
Quadrollopo edited this page Oct 6, 2021 · 8 revisions

Adding a new Item

Requests:

POST /v2/items

If you want to manually assign a code use a PUT request instead

PUT /v2/items/{CODE}

If some items don't have a code, the server will try to generate one for each item.

You must use the session cookie to authenticate this request.
The request body should look like this:

{
  "parent": "SomeLocation",
  "features": {
    "brand": "Dill",
    "model": "XP-S92",
    "type": "case"
  },
  "contents": []
}

It's also possible to add a tree of items. In that case, if you want to specify a code for inner items, you should use the "code" parameter.
The "code" parameter is not allowed for outer items.

{
  "parent": "SomeLocation",
  "features": {
    "model": "XP-S92",
    "brand": "Dill",
    "type": "case"
  },
  "contents": [
    {
      "features": {
        "type": "motherboard",
        "brand": "Dell",
        "model": "F00-B4R"
      },
      "contents": [
        {
          "features": {
            "type": "cpu",
            "brand": "Intel",
            "model": "Core 3 Trio E3800",
            "frequency-hertz": "2800000000"
          },
          "contents": []
        }
      ]
    },
    {
      "code": "ASD",
      "features": {
        "type": "psu",
        "brand": "Gamma Electronics",
        "model": "ASD-400W"
      },
      "contents": []
    }
  ]
}

Responses contain the item code as the only data:

{"status": "success", "data": "PC42"}

or you may use the ?loopback parameter to request a copy of the entire item, e.g. do a POST /v2/items?loopback or a PUT /v2/items/CODE?loopback.

In any case, the response contains a Location: header with the URL of the newly added item, e.g.:

Location: /v2/items/PC42

Response codes:
201 - Item created
400 - Bad request (malformed JSON, validation failed, location does not exist, etc...)
401 - The user is not authenticated or session has expired
403 - The user doesn't have permission to add new items
404 - Item code contains invalid characters. Yes this is a bug and will be fixed someday

Clone this wiki locally