Skip to main content

Division

Division is a store which owns the brand. There are two types of division such as main and sub

The users of main divisions are able to perform actions for both their and its sub-divisions.

  1. create, update, list, approve, cancel or reject quotation
  2. create, list quotation comment
  3. create order from a quotation
  4. create, update, list, delete quotation discount

The users of sub-divisions are able to perform their quotations only.

  1. create, list, approve, cancel or reject, approve pending quotation

A division has a monthly limit field. If this limit is exceeded, the division cannot create new quotations.

When the main division creates a new quotation, the total is calculated by adding the total amount of its quotations, the total amount of quotations from its sub-divisions, and the amount of the new quotation being created. If this cumulative total exceeds the main division's monthly limit, the new quotation cannot be created.

When a sub-division creates a new quotation, the total is calculated by adding the total amount of its quotations and the amount of the new quotation being created.

When a division is created country_id, city_id, township_id, district_id, phone_number, address should be matched with Commerce data otherwise exception occurs when creating an order.

List My Divisions

Example Request

curl --location {host}/api/v1/my-divisions/' \
--header 'Authorization: Token {Token}'

Example Response (200 OK)

{
"count": 1,
"next": null,
"previous": null,
"results": [
{
"id": 2,
"name": "M Shop",
"division_type": "sub",
"parent": 1,
"erp_code": "MUZO1",
"country_id": 1,
"city_id": 34,
"township_id": 17,
"district_id": 1,
"address": "Teknopark B2 417 selamam",
"phone_number": "05XXXXXXXXX",
"fax_number": "5554443322",
"is_active": true,
"latitude": null,
"longitude": null,
"monthly_order_limit": "0.00",
"current_balance": "0.00",
"current_balance_last_update": null,
"extra_data": {}
}
]
}

List All My Divisions

This method allows users to retrieve a list of their divisions. Depending on the association, it retrieves either all child divisions linked to the main division or the associated division along with its parent division.

Example Request

curl --location '{B2B_Backend_URL}/api/v1/my-divisions/all/' \
--header 'Authorization: Token {token}'

Example Response (200 OK)

{
"count": 2,
"next": null,
"previous": null,
"results": [
{
"id": 533,
"name": "Sub",
"division_type": "sub",
"parent": 87,
"erp_code": "erp2",
"country_id": 40,
"city_id": 142,
"township_id": 203,
"district_id": 204,
"address": "test",
"phone_number": "05999999999",
"fax_number": "123123",
"is_active": true,
"latitude": null,
"longitude": null,
"monthly_order_limit": "0.00",
"current_balance": "0.00",
"current_balance_last_update": null,
"extra_data": {}
},
{
"id": 87,
"name": "Main",
"division_type": "main",
"parent": null,
"erp_code": "erp1",
"country_id": 40,
"city_id": 40,
"township_id": 40,
"district_id": 40,
"address": "test",
"phone_number": "05999999999",
"fax_number": "123123",
"is_active": true,
"latitude": null,
"longitude": null,
"monthly_order_limit": "9999999999999.00",
"current_balance": "0.00",
"current_balance_last_update": null,
"extra_data": {}
}
]
}

List Divisions

Example Request

curl --location '{host}/api/v1/divisions/' \
--header 'Authorization: Token {Token}'

Example Response (200 OK)

{
"count": 4,
"next": null,
"previous": null,
"results": [
{
"id": 6,
"name": "Example1 Shop",
"division_type": "sub",
"parent": 1,
"erp_code": "EXAM1-1",
"country_id": 1,
"city_id": 34,
"township_id": 17,
"district_id": 1,
"address": "Example address street 20",
"phone_number": "05XXXXXXXXX",
"fax_number": "5554443322",
"is_active": true,
"latitude": null,
"longitude": null,
"monthly_order_limit": "0.00",
"current_balance": "0.00",
"current_balance_last_update": null,
"extra_data": {}
}
...
]
}

You can also use the following filters to list divisions for both above API.

  • name,
  • erp_code with case-insensitive,
  • has_parent with is null operator,
  • current_balance_min,
  • current_balance_max,
  • current_balance_last_update_before,
  • current_balance_last_update_after,
  • parent,
  • division_type,
  • city_id,
  • country_id phone_number,
  • is_active,
  • user

Example Request

curl --location {host}/api/v1/divisions/?current_balance_max=20&name=muz&%3Fcurrent_balance_min=0&has_parent=true&is_active=true&city_id=34&phone_number=05XXXXXXXXX&country_id=1&is_active=true&user=1' \
--header 'Authorization: Token {Token}'

Example Response (200 OK)

{
"count": 1,
"next": null,
"previous": null,
"results": [
{
"id": 2,
"name": "M Shop",
"division_type": "sub",
"parent": 1,
"erp_code": "MUZO1",
"country_id": 1,
"city_id": 34,
"township_id": 17,
"district_id": 1,
"address": "Teknopark B2 417 selamam",
"phone_number": "05XXXXXXXXX",
"fax_number": "5554443322",
"is_active": true,
"latitude": null,
"longitude": null,
"monthly_order_limit": "0.00",
"current_balance": "20.00",
"current_balance_last_update": null,
"extra_data": {}
}
]
}

Get Division

Example Request

curl --location '{host}/api/v1/divisions/1/' \
--header 'Authorization: Token {Token}'

Example Response (200 OK)

{
"id": 1,
"name": "Akinon Shop",
"division_type": "main",
"parent": null,
"erp_code": "AKI01",
"country_id": 1,
"city_id": 47,
"township_id": 17,
"district_id": 20,
"address": "Teknopark B2 417 selamam",
"phone_number": "05XXXXXXXXX",
"fax_number": "5554443322",
"is_active": true,
"latitude": null,
"longitude": null,
"monthly_order_limit": "99999999913455.00",
"current_balance": "0.00",
"current_balance_last_update": null,
"extra_data": {}
}

Create Main Division

Example Request

curl --location '{host}/api/v1/divisions/' \
--header 'Authorization: Token {Token}' \
--header 'Content-Type: application/json' \
--data '{
"name": "Example Shop",
"division_type": "main",
"erp_code": "EXAM1",
"country_id": 1,
"city_id": 34,
"township_id": 17,
"district_id": 1,
"phone_number": "05XXXXXXXXX",
"fax_number": "5554443322",
"address": "Example address street 20"
}'

Example Response (200 OK)

{
"id": 5,
"name": "Example Shop",
"division_type": "main",
"parent": null,
"erp_code": "EXAM1",
"country_id": 1,
"city_id": 34,
"township_id": 17,
"district_id": 1,
"address": "Example address street 20",
"phone_number": "05XXXXXXXXX",
"fax_number": "5554443322",
"is_active": true,
"latitude": null,
"longitude": null,
"monthly_order_limit": "0.00",
"current_balance": "0.00",
"current_balance_last_update": null,
"extra_data": {}
}

Example Response (400 Bad Request)

It occurs when the posted parent is not a main division:

{
"parent": [
"The type of division is not main."
]
}

Example Response (400 Bad Request)

It occurs when sending parent property with main division type

{
"parent": [
"The main division can not have parent."
]
}

Create Sub-Division

Example Request

curl --location {host}/api/v1/divisions/' \
--header 'Authorization: Token {Token}' \
--header 'Content-Type: application/json' \
--data '{
"name": "Example1 Shop",
"division_type": "sub",
"parent": 1,
"erp_code": "EXAM1-1",
"country_id": 1,
"city_id": 34,
"township_id": 17,
"district_id": 1,
"phone_number": "05XXXXXXXXX",
"fax_number": "5554443322",
"address": "Example address street 20"
}'

Example Response (200 OK)

{
"id": 6,
"name": "Example1 Shop",
"division_type": "sub",
"parent": 1,
"erp_code": "EXAM1-1",
"country_id": 1,
"city_id": 34,
"township_id": 17,
"district_id": 1,
"address": "Example address street 20",
"phone_number": "05XXXXXXXXX",
"fax_number": "5554443322",
"is_active": true,
"latitude": null,
"longitude": null,
"monthly_order_limit": "0.00",
"current_balance": "0.00",
"current_balance_last_update": null,
"extra_data": {}
}

Update Division

Example Request

curl --location --request PATCH '{host}/api/v1/divisions/6/' \
--header 'Authorization: Token {Token}' \
--header 'Content-Type: application/json' \
--data '{
"parent": 1
}'

Example Response (200 OK)

{
"id": 6,
"name": "Example1 Shop",
"division_type": "sub",
"parent": 1,
"erp_code": "EXAM1-1",
"country_id": 1,
"city_id": 34,
"township_id": 17,
"district_id": 1,
"address": "Example address street 20",
"phone_number": "05XXXXXXXXX",
"fax_number": "5554443322",
"is_active": true,
"latitude": null,
"longitude": null,
"monthly_order_limit": "0.00",
"current_balance": "0.00",
"current_balance_last_update": null,
"extra_data": {}
}

Example Response (400 Bad Request)

It occurs when the posted parent is not a main division:

{
"parent": [
"The type of division is not main."
]
}

Example Response (400 Bad Request)

It occurs when sending parent property with main division type:

{
"parent": [
"The main division can not have parent."
]
}

Deactivate Division

When a division is deactivated its users and Commerce users are deactivated as well. Users cannot perform actions when they are deactivated.

Example Request

curl --location --request POST '{host}/api/v1/divisions/2/deactivate/' \
--header 'Authorization: Token {Token}'

Example Response (200 OK)

Empty body.

Activate Division

When a division is activated its users are activated as well.

Example Request

curl --location --request POST '{host}/api/v1/divisions/2/activate/' \
--header 'Authorization: Token {Token}'

Example Response (200 OK)

Empty body.

Export My Divisions

Exports divisions as a file. Returns a cache key to track the export status.

Request Parameters

ParameterDescription
fieldsSpecifies the fields to be included in the export file. Available fields: name, division_type, erp_code, is_active, country_id, city_id, township_id, district_id, address, phone_number, fax_number, latitude, longitude, monthly_order_limit, current_balance, current_balance_last_update, extra_data
formatSpecifies the file format for the export. Acceptable values are csv and xls. The default is xls.
status_cache_keyA query parameter to track the status of the file export using the cache key returned from the initial request.

Example Request

curl --location '{B2B_Backend_URL}/api/v1/my-divisions/?fields=name&fields=erp_code&fields=division_type&fields=address' \
--header 'Authorization: Token {token}'

Example Response (200 OK)

{
"cache_key": "beacaa8ba65571e3840e28a11f17481e"
}

Export File Status

Checks the status of an export file using the cache key obtained from the export request. Provides information on whether the file is ready for download.

Example Request

curl --location '{B2B_Backend_URL}/api/v1/my-divisions/?status_cache_key=8381f01436160bb756c805c5e3c25358' \
--header 'Authorization: Token {token}'

Example Response

{
"is_ready": true,
"url": "{url}/export_file/beacaa8ba65571e3840e28a11f17481e.xls",
"status": "completed"
}

Response Parameters

FieldDescription
is_readyIndicates whether the file is ready for download (true or false).
urlThe URL to download the exported file once it is ready.
statusProvides the current status of the export process (e.g., waiting, completed).