Rest API Suppliers of products - datawizio/pythonAPI GitHub Wiki

19. Resource /suppliers/ (Suppliers of products, Collection, Read only)

Suppliers of products - is a list of all suppliers who worked or are still working with client. With the help of /Suppliers/ you can get access to the list of suppliers of products. And to add new suppliers to the catalog.

19.1. Suppliers object structure

Field name Field type Size Required Read only Remark
supplier_id line 100 yes no Supplier identifier, that has to correspond to product supplier id
name line 200 yes no supplier name
supplier_code line 50 no no code of supplier
phone line 25 no no phone number of supplier
commodity_credit_days number no yes number of days for delayed payment
address line 50 no no Supplier address

19.2. Available commands

To manage the /suppliers/ resource, the following commands are used:

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

19.2.1. GET /suppliers/ - to receive one page of a collection.

Command type: GET http://api.datawiz.io/api/v1/suppliers

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/suppliers/.json/?search=unknown-string

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

Example of a 2-element collection:

GET http://api.datawiz.io/api/v1/suppliers/?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/suppliers/?page=2&page_size=2&format=api", 
    "previous": null, 
    "results": [
        {
            "supplier_id": "supplier-1",
            "name": "Vasya",
            "supplier_code": "11111",
            "phone": null,
            "commodity_credit_days": 2,
            "address": null
        }, 
        {
            "supplier_id": "supplier-2",
            "name": "Roma",
            "supplier_code": "12345",
            "phone": null,
            "commodity_credit_days": 0,
            "address": null
        }
    ]
}

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"
}

19.2.2 POST /suppliers/ - to add information about suppliers

Command type: POST http://api.datawiz.io/api/v1/suppliers/?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 information about suppliers. Important fields: supplier_id, name. The sequence of fields is not important.

Example of request to load information about product suppliers:

POST http://api.datawiz.io/api/v1/suppliers/.json

{
    "supplier_id": "supplier-1",
    "name": "Vasya",
    "supplier_code": "11111",
    "phone": null,
    "commodity_credit_days": 0,
    "address": null
}

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/suppliers/124/
Allow: GET, POST, HEAD, OPTIONS
{
"updated": 0,
"inserted": 1
}

Conditions and constraints:

  • If an object with supplier_id already exists on the server, the request will replace the object on server without notification.
  • One can not add to server an object if there is no product with an indicated supplier_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 ( name field is empty):

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

19.2.3. OPTIONS /suppliers/ - meta information about an object structure

The following JSON structure returns at this command:

OPTIONS /api/v1/suppliers/

HTTP 200 OK
Allow: GET, POST, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept
{
"name": "Supplier List",
"description": "this is my text. You can see this text on the REST-page",
"renders": [
"application/json",
"text/html"
],
"parses": [
"application/json",
"application/x-www-form-urlencoded",
"multipart/form-data"
],
"actions": {
"POST": {
"supplier_id": {
"type": "string",
"required": true,
"read_only": false,
"label": "Supplier id",
"max_length": 12
},
"name": {
"type": "string",
"required": true,
"read_only": false,
"label": "Name",
"max_length": 200
},
"supplier_code": {
"type": "string",
"required": false,
"read_only": false,
"label": "Supplier code",
"max_length": 50
},
"phone": {
"type": "string",
"required": false,
"read_only": false,
"label": "Phone",
"max_length": 25
},
"commodity_credit_days": {
"type": "integer",
"required": false,
"read_only": false,
"label": "Commodity credit days"
},
"address": {
"type": "string",
"required": false,
"read_only": false,
"label": "Address",
"max_length": 50
}
}
}
}
⚠️ **GitHub.com Fallback** ⚠️