Rest API List of category managers - datawizio/pythonAPI GitHub Wiki

24. Resource /category-managers/ (List of category managers, Collection)

List of category managers - is the list of category managers working in shop network. With the help of /category-managers/ resource one can get access to the list of category managers and add new category managers.

24.1. Category-manager object structure:

Field name Field type Size Required Read only Remark
url URL no yes url of this object
identifier line 200 yes no category manager identifier
shops list 100 yes no shop, where category manager works
categories list yes no categories and products that the manager is responsible for (you can set only category or only products)
products list yes no
name line 100 yes no category manager name
date_from date no no date when the category manager started to work

24.2. Available commands

To manage the /category-managers/ resource, the following commands are used:

  • GET - to receive one page on a collection
  • POST - to add new category manager
  • OPTIONS - meta information about an object structure

24.2.1. GET /category-managers/ - to receive one page of a collection.

Command type: GET http://api.datawiz.io/api/v1/category-managers

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

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

Example of a 2-element collection:

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

HTTP 200 OK
Content-Type: application/json
Vary: Accept
Allow: GET, OPTIONS
{
    "count": 3, 
    "next": "http://api.datawiz.io/api/v1/category-managers/?page=2&page_size=2&format=api", 
    "previous": null, 
    "results": [
        {
            "url": "http://api.datawiz.io/api/v1/category-managers/CATEGORY-ID-DPLD-2FQF-ZQSN/",
            "manager_id": "CATEGORY-ID-DPLD-2FQF-ZQSN",
            "shops": [
                "9856d0f5-0929-11e5-80d8-7054d2c57800"
            ],
            "categories": [
                "99fdc926-5e2b-11e6-bfc8-00505600b73b"
            ],
            "name": "Vasya",
            "date_from": null
        },
        {
            "url": "http://api.datawiz.io/api/v1/category-managers/CATEGORY-ID-PGEK-DZFY-4FU2/",
            "manager_id": "CATEGORY-ID-PGEK-DZFY-4FU2",
            "shops": [],
            "categories": [],
            "name": "Vasya",
            "date_from": 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, OPTIONS, PATCH 
{
"detail": "Not found"
}

24.2.2 POST /category-managers/ - to add one or several category managers

Command type: POST http://api.datawiz.io/api/v1/category-managers/?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 new category manager.

Important fields: identifier, shops, categories, products, name and date_from. The sequence of fields is not important.

Example of a request to add new category manager:

POST http://api.datawiz.io/api/v1/category-managers/.json

{
    "identifier": "124", 
    "shops": ["Shop1", "Shop2"],
    "categories": ["alcoholic_drinks"], 
    "name": "Aleksandr", 
    "date_from": "2016-11-10", 
}

Server's response:

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

Example of a server's response:

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

Conditions and constraints:

  • If an object with manager_id already exists on the server, the request will replace the object on server without notification.
  • The name field can not be empty.
  • The identifier field can not be empty.
  • The date_from field can not be empty.
  • The shops field can not be empty.
  • categories and products fields can not be sent simultaneously.

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

24.2.3. OPTIONS /category-managers/ - meta information about an object structure The following JSON structure returns at this command:

OPTIONS /api/v1/category-managers/

HTTP 200 OK 
Content-Type: application/json 
Vary: Accept 
Allow: GET, HEAD, OPTIONS 
{
"name": "Category Manager List",
"description": "",
"renders": [
"application/json",
"text/html"
],
"parses": [
"application/json",
"application/x-www-form-urlencoded",
"multipart/form-data"
],
"actions": {
"POST": {
"url": {
"type": "field",
"required": false,
"read_only": true,
"label": "Url"
},
"categories": {
"type": "list",
"required": false,
"read_only": false,
"label": "Categories",
"child": {
"type": "integer",
"required": true,
"read_only": false
}
},
"products": {
"type": "list",
"required": false,
"read_only": false,
"label": "Products",
"child": {
"type": "string",
"required": true,
"read_only": false
}
},
"shops": {
"type": "list",
"required": true,
"read_only": false,
"label": "Shops",
"child": {
"type": "integer",
"required": true,
"read_only": false
}
},
"date_from": {
"type": "date",
"required": true,
"read_only": false,
"label": "Date from"
},
"identifier": {
"type": "string",
"required": true,
"read_only": false,
"label": "Identifier",
"max_length": 200
},
"name": {
"type": "string",
"required": true,
"read_only": false,
"label": "Name",
"max_length": 100
},
"categorymanageraccess": {
"type": "field",
"required": false,
"read_only": false,
"label": "Categorymanageraccess",
"child": {
"type": "nested object",
"required": false,
"read_only": false,
"children": {
"url": {
"type": "field",
"required": false,
"read_only": true,
"label": "Url"
},
"product_id": {
"type": "integer",
"required": true,
"read_only": false,
"label": "Product id"
},
"product_url": {
"type": "integer",
"required": false,
"read_only": true,
"label": "Product url"
},
"shop_id": {
"type": "integer",
"required": true,
"read_only": false,
"label": "Shop id"
},
"shop_url": {
"type": "integer",
"required": false,
"read_only": true,
"label": "Shop url"
}
}
}
}
}
}
}
⚠️ **GitHub.com Fallback** ⚠️