Rest API Inventory list - datawizio/pythonAPI GitHub Wiki

18. Resource /product-inventory/ (Inventory list, Collection, Read only)

Inventory list - is a list of all products remaining in client's shop network. With the help of /product-inventory/ you can get access to the list of inventory and to add information about inventory.

18.1. Inventory object structure

Field name Field type Size Required Read only Remark
date line yes yes date
shop_id line 50 yes yes has to correspond to shop id from the client's accounting application
product_id line 100 yes yes has to correspond to product id from the client's accounting application
qty number yes yes quantity
original_price number no yes price per itemу
stock_total_price number no yes cost of products left in storage is calculated qty*original_price

18.2. Available commands

To manage the /product-inventory/ resource, the following commands are used:

  • GET - to receive one page on a collection
  • POST - to view information about inventory
  • OPTIONS - meta information about an object structure
  • HEAD - similar to GET, but you receive only a heading of an response

18.2.1. GET /product-inventory/ - to receive one page of a collection.

Command type: GET http://api.datawiz.io/api/v1/product-inventory

Suffixes:

  • .json - to receive a response from a server in JSON format
  • .api - to receive a response from a server in HTML format (test platform)

Parameters:

  • format = json | api - similar to the stated above suffixes
  • page_size = {nn} - to establish a page size equal to {nn} objects
  • page = {n} - to load a page {n}
  • search = text - to show only the objects, which name contain "text"
  • ordering = name | identifier - to sort fields alphabetically (ascending)
  • ordering = -name | -identifier - to sort fields in the reverse order

Server's response:

The "collection" object consists of four fields (count, next, previous, results).

An example of an empty collection returned by server:

GET http://api.datawiz.io/api/v1/product-inventory/.json/?search=unknown-string

{
     "count": 0,
     "next": null,
     "previous": null,
     "results": [] 
}

Example of a 2-element collection:

GET http://api.datawiz.io/api/v1/product-inventory/?format=api&page_size=2:

HTTP 200 OK
Content-Type: application/json
Vary: Accept
Allow: GET, HEAD, OPTIONS
{
    "count": 11, 
    "next": "http://api.datawiz.io/api/v1/product-inventory/?page=2&page_size=2&format=api", 
    "previous": null, 
    "results": [
        {
            "date": "2016-06-07"
            "shop_id": "3", 
            "product_id": "6313"
            "qty": "1.0000"             
            "original_price": "45.6600"         
            "stock_total_price": "0.00"
        }, 
        {
            "date": "2016-06-07"
            "shop_id": "3", 
            "product_id": "6343"
            "qty": "2.0000"             
            "original_price": "46.6700"         
            "stock_total_price": "0.00"
        }
    ]
}

Error report:

In case of an error, server returns a response with a corresponding status and an error report in detail key and/or in field http.response.content:

HTTP 404 NOT FOUND 
Content-Type: application/json 
Vary: Accept 
Allow: GET, HEAD, OPTIONS, PATCH 
{
"detail": "Not found"
}

18.2.2 POST /product-inventory/ - to add information about inventory of one or several products

Command type: POST http://api.datawiz.io/api/v1/product-inventory/?format=json

Suffixes:

  • .json - to receive a response from a server in JSON format
  • .api - to receive a response from a server in HTML format (test platform)

Parameters:

  • format = json | api - similar to the stated above suffixes

Request data:

A request contains a JSON-object of dictionary type describing a new product inventory.

Important fields: date, product_id, shop_id, qty. The sequence of fields is not important.

Example of request to load information about product inventory:

POST http://api.datawiz.io/api/v1/product-inventory/.json

{
    "date": "2016-06-07"
    "shop_id": "3", 
    "product_id": "6343"
    "qty": "2.0000"             
    "original_price": "46.6700"         
    "stock_total_price": "0.00"
}

Server's response:

At a particular request processing the server returns 201 status code and a status of creation of the object.

Example of a server's response:

HTTP 201 CREATED
Content-Type: application/json
Vary: Accept
Location: http://api.datawiz.io/api/v1/product-inventory/124/
Allow: GET, POST, HEAD, OPTIONS
{
"updated": 0,
"inserted": 1
}

Conditions and constraints:

  • If an object with product_id, shop_id, date already exists on the server, the request will replace the object on server without notification.
  • stock_total_price should equal original_price*qty.
  • One can not add to server an object if there is no shop with an indicated shop_id
  • One can not add to server an object if there is no product with an indicated product_id

Error report:

In case of an error, server returns a response with a corresponding status and an error report next to the field, related to that error. If an error is not only about one field, but the whole object, the report will appear next to the key non_field_errors.

Example of server's response with an error ( qty field is empty):

HTTP 400 BAD REQUEST 
Content-Type: application/json 
Vary: Accept 
Allow: GET, POST, HEAD, OPTIONS 
{
     "qty": [
         "This field is required." 
     ] 
}

18.2.3. OPTIONS /product-inventory/ - meta information about an object structure

The following JSON structure returns at this command:

OPTIONS /api/v1/product-inventory/

HTTP 200 OK
Allow: GET, POST, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept
{
"name": "Product Inventory List",
"description": "",
"renders": [
"application/json",
"text/html"
],
"parses": [
"application/json",
"application/x-www-form-urlencoded",
"multipart/form-data"
],
"actions": {
"POST": {
"date": {
"type": "datetime",
"required": true,
"read_only": false,
"label": "Date"
},
"shop_id": {
"type": "string",
"required": true,
"read_only": false,
"label": "Shop id"
},
"product_id": {
"type": "string",
"required": true,
"read_only": false,
"label": "Product id"
},
"qty": {
"type": "decimal",
"required": true,
"read_only": false,
"label": "Qty"
},
"original_price": {
"type": "decimal",
"required": false,
"read_only": false,
"label": "Price"
},
"stock_total_price": {
"type": "decimal",
"required": false,
"read_only": false,
"label": "Total price"
}
}
}
}
⚠️ **GitHub.com Fallback** ⚠️