Rest API Documents to receive products - datawizio/pythonAPI GitHub Wiki
Documents to receive products - are delivery notes containing data about products supplied to the shop. Delivery note also includes product name, bar code, price, quantity. With the help of /receive-documents/
you can get access to the list of documents to receive products and to add new documents for receiving products.
Field name | Field type | Size | Required | Read only | Remark |
---|---|---|---|---|---|
document_id |
line | 50 | yes | no | Document identifier has to correspond to id from the client's accounting application |
url |
URL | no | yes | url of this object | |
supplier_id |
line | 50 | yes | no | supplier identifier |
supplier_url |
URL | no | yes | url of this object | |
document_number |
line | 50 | no | no | document number |
shop_id |
line | 50 | yes | no | shop identifier |
shop_url |
URL | no | yes | url of this object | |
order_id |
line | 50 | no | no | order identifier |
order_url |
URL | no | yes | url of this object | |
document_date |
time and date | yes | no | time and date of document formation | |
responsible |
line | 100 | yes | no | person responsible for receiving products |
products |
list | yes | no | array of products | |
items_qty |
number | yes | no | quantity of products | |
price_total |
number | yes | no | total cost of products in document |
Each product has some characteristics that can be shown in the next structure:
Field name | Field type | Size | Required | Read only | Remark |
---|---|---|---|---|---|
product_id |
line | 200 | yes | no | product identifier from the Catalog of products (see .[/products/ ]) |
product_url |
URL | no | yes | uproduct identifier url | |
qty |
число | yes | no | quantity | |
price |
число | yes | no | real product price (if the field is absent, or price *qty <> price_total , it calculates as price_total /qty ) |
|
price_total |
число | yes | no | total cost of the item (=price*quantity) |
To manage the /receive-documents/
resource, the following commands are used:
-
GET
- to receive one page on a collection -
POST
- to load documents to receive products -
OPTIONS
- meta information about an object structure -
HEAD
- similar to GET, but you receive only a heading of a response
Command type: GET http://api.datawiz.io/api/v1/receive-documents
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, whichname
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/receive-documents/.json/?search=unknown-string
{
"count": 0,
"next": null,
"previous": null,
"results": []
}
Example of a 2-element collection:
GET http://api.datawiz.io/api/v1/receive-documents/?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/receive-documents/?page=2&page_size=2&format=api",
"previous": null,
"results": [
{
"document_id": "r-document-1",
"url": "http://api.datawiz.io/api/v1/receive-documents/r-document-1/",
"supplier_id": "2",
"supplier_url": "http://api.datawiz.io/api/v1/suppliers/supplier-1/",
"document_number": "11221",
"shop_id": "863",
"shop_url": "http://api.datawiz.io/api/v1/shops/9856d0f5-0929-11e5-80d8-7054d2c57800/",
"order_id": "1414274",
"order_url": "http://api.datawiz.io/api/v1/purchase-documents/p-document-1/",
"document_date": "2016-01-01T00:00:00",
"responsible": "Petya",
"items_qty": "3.0000",
"price_total": "20.0000",
"products": [
{
"product_id": "a26f866b-1465-11e5-80cb-a01d4897e530",
"product_url": "http://api.datawiz.io/api/v1/products/a26f866b-1465-11e5-80cb-a01d4897e530/",
"qty": "3.0000",
"price": "10.0000",
"price_total": "20.0000"
}
]
},
{
"document_id": "r-document-1",
"url": "http://api.datawiz.io/api/v1/receive-documents/r-document-1/",
"supplier_id": "2",
"supplier_url": "http://api.datawiz.io/api/v1/suppliers/supplier-1/",
"document_number": "11221",
"shop_id": "863",
"shop_url": "http://api.datawiz.io/api/v1/shops/9856d0f5-0929-11e5-80d8-7054d2c57800/",
"order_id": "1414274",
"order_url": "http://api.datawiz.io/api/v1/purchase-documents/p-document-1/",
"document_date": "2016-01-01T00:00:00",
"responsible": "Petya",
"items_qty": "3.0000",
"price_total": "20.0000",
"products": [
{
"product_id": "a26f866b-1465-11e5-80cb-a01d4897e530",
"product_url": "http://api.datawiz.io/api/v1/products/a26f866b-1465-11e5-80cb-a01d4897e530/",
"qty": "3.0000",
"price": "10.0000",
"price_total": "20.0000"
}
]
},
]
}
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 string http.response.content:
HTTP 404 NOT FOUND
Content-Type: application/json
Vary: Accept
Allow: GET, HEAD, OPTIONS, PATCH
{
"detail": "Not found"
}
Command type: POST http://api.datawiz.io/api/v1/receive-documents/?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 documents to receive products.
Important fields: document_id
, supplier_id
, shop_id
, document_date
, responsible
, product_id
, qty
, price_total
, price
.
The sequence of fields is not important.
Example of request to load information about product inventory:
POST http://api.datawiz.io/api/v1/receive-documents/.json
{
"document_id": "r-document-1",
"supplier_id": "2",
"document_number": "11221",
"shop_id": "863",
"order_id": "1414274",
"document_date": "2016-01-01T00:00:00",
"responsible": "Petya",
"items_qty": "3.0000",
"price_total": "20.0000"
"products": [
{
"product_id": "3276889",
"qty": "10.0000",
"price": "20.0000",
"price_total": "200.0000"
}
]
}
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/receive-documents/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. -
price_total
should equalprice*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
- 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 (qty
field is empty):
HTTP 400 BAD REQUEST
Content-Type: application/json
Vary: Accept
Allow: GET, POST, HEAD, OPTIONS
{
"qty": [
"This field is required."
]
}
The following JSON structure returns at this command:
OPTIONS /api/v1/receive-documents/
HTTP 200 OK
Allow: GET, POST, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept
{
"name": "Receive Document 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": {
"document_id": {
"type": "string",
"required": true,
"read_only": false,
"label": "Document id",
"max_length": 50
},
"url": {
"type": "field",
"required": false,
"read_only": true,
"label": "Url"
},
"supplier_id": {
"type": "string",
"required": true,
"read_only": false,
"label": "Supplier id",
"max_length": 50
},
"supplier_url": {
"type": "field",
"required": false,
"read_only": true,
"label": "Supplier url"
},
"document_number": {
"type": "string",
"required": false,
"read_only": false,
"label": "Document number",
"max_length": 50
},
"shop_id": {
"type": "string",
"required": true,
"read_only": false,
"label": "Shop id",
"max_length": 50
},
"shop_url": {
"type": "field",
"required": false,
"read_only": true,
"label": "Shop url"
},
"order_id": {
"type": "string",
"required": false,
"read_only": false,
"label": "Order id",
"max_length": 50
},
"order_url": {
"type": "field",
"required": false,
"read_only": true,
"label": "Order url"
},
"document_date": {
"type": "datetime",
"required": true,
"read_only": false,
"label": "Document date"
},
"responsible": {
"type": "string",
"required": true,
"read_only": false,
"label": "Responsible",
"max_length": 100
},
"products": {
"type": "field",
"required": true,
"read_only": false,
"label": "Products",
"child": {
"type": "nested object",
"required": true,
"read_only": false,
"children": {
"product_id": {
"type": "string",
"required": true,
"read_only": false,
"label": "Product id"
},
"product_url": {
"type": "field",
"required": false,
"read_only": true,
"label": "Product url"
},
"qty": {
"type": "decimal",
"required": true,
"read_only": false,
"label": "Qty"
},
"price": {
"type": "decimal",
"required": true,
"read_only": false,
"label": "Price"
},
"price_total": {
"type": "decimal",
"required": true,
"read_only": false,
"label": "Price total"
}
}
}
},
"items_qty": {
"type": "decimal",
"required": true,
"read_only": false,
"label": "Items qty"
},
"price_total": {
"type": "decimal",
"required": true,
"read_only": false,
"label": "Price total"
}
}
}
}