User

B2B API provides user actions from the /api/v1/users/ endpoint. It consists of several endpoints and includes endpoints for managing user accounts such as creating, updating profiles and accessing user-specific data.

Users can utilize the Omnitron token to access the B2B system as a superuser.

Create User

Used to create a user within the system. When a user is generated on the B2B platform, the same user is subsequently created on the Commerce platform using the /users/registration endpoint.

Endpoint: POST /api/v1/users/

Example Request

In order to create a new user in the system, a request is sent to the endpoint given above using the header specified below and with the request body parameters:

Property
Data Type
Required
Descriptions

first_name

string

True

The first name of the user.

last_name

string

True

The last name of the user.

email

string

True

The email of the user.

password

string

True

The password of the user.

phone_number

string

False

The phone number of the user.

division

integer

True

The division id of the user.

curl --location '{host}/api/v1/users/' \
--header 'Authorization: Token {TOKEN}' \
--header 'Content-Type: application/json' \
--data-raw '{
    "division": 1,
    "email": "[email protected]",
    "first_name": "firstname",
    "last_name": "lastname",
    "phone_number": "05XXXXXXXXX",
    "password": "123456"
}'

Example Response (200 OK)

{
    "id": 1,
    "email": "[email protected]",
    "first_name": "firstname",
    "last_name": "lastname",
    "phone_number": "05XXXXXXXXX",
    "division": 1,
    "password": "#hashedpassword#"
}

Update User

Used to update a user in the system. During the update process, the system first checks if the user is active. If the user is inactive, then verifies whether the division is active. If the division is active, the user is updated as active. However, if the division is not active, a DivisionNotActiveException error is thrown.

Following the update on the B2B side, updates on the Commerce platform using the /users/profile endpoint.

Path Parameter:

Property
Required
Descriptions

id

True

The user id of the user.

Body Parameters:

Property
Data Type
Required
Descriptions

first_name

string

False

The first name of the user.

last_name

string

False

The last name of the user.

phone_number

string

False

The phone number of the user.

division

integer

False

The division id of the user.

Example Request

curl --location --request PUT '{host}/api/v1/users/1/' \
--header 'Authorization: Token {TOKEN}' \
--header 'Content-Type: application/json' \
--data '{
    "division": 1,
    "first_name": "firstname",
    "last_name": "lastname",
    "phone_number": "5554443322"
}'

Example Response (200 OK)

{
    "id": 1,
    "first_name": "firstname",
    "last_name": "lastname",
    "phone_number": "5554443322",
    "division": 1
}

User List

This process is used to retrieve a list of all users in the system where the remote_id is not null.

Example Request

curl --location --request POST '{host}/api/v1/users/' \
--header 'Authorization: Token {TOKEN}' \

Query Parameters:

Property
Filter Type
Description

id

Exact

Filters users by the exact user ID.

is_active

Boolean

Filters users based on their activation status (True/False).

email

Case-insensitive Contain

Filters users with email containing the specified substring.

division

Exact

Filters users by the exact division id.

division_type

Enum

Filters users using a main, sub

first_name

Case-insensitive Contain

Filters users with the first name containing the specified substring.

last_name

Case-insensitive Contain

Filters users with the last name containing the specified substring.

phone_number

Case-insensitive Contain

Filters users with the phone number containing the specified substring.

Example Response (200 OK)

{
    "count": 1,
    "next": "{host}/api/v1/users/?limit=20&page=2",
    "previous": null,
    "results": [
        {
            "id": 1,
            "email": "[email protected]",
            "first_name": "firstname",
            "last_name": "lastname",
            "phone_number": "5554443322",
            "division": {
                "id": 1,
                "name": "Akinon Main Division",
                "division_type": "main"
            },
            "is_active": true,
            "shop_token": "########",
            "remote_id": 1,
            "date_joined": "2023-12-14T11:17:22.670111Z",
            "last_login": null
        }
    ]
}

User Detail

This operation is used to retrieve details of a specific user in the system.

Path Parameter:

Property
Required
Descriptions

id

True

The user id of the user.

Example Request

curl --location --request GET '{host}/api/v1/users/1/' \
--header 'Authorization: Token {TOKEN}' \

Example Response (200 OK)

{
    "id": 1,
    "email": "[email protected]",
    "first_name": "firstname",
    "last_name": "lastname",
    "phone_number": "5554443322",
    "division": {
        "id": 1,
        "name": "Akinon Main Division",
        "division_type": "main"
    },
    "is_active": true,
    "shop_token": "########",
    "remote_id": 1,
    "date_joined": "2023-12-14T11:17:22.670111Z",
    "last_login": null
}

Activate User

This process is used to activate users. First, it checks whether the division to which the user is affiliated is active. If the division is not active, a DivisionNotActiveException error is raised.

If the division is active, the user is activated. Subsequently, a request is sent to the /users/{user_id}/ endpoint on the Commerce side to notify that the user has been activated. The request body for this operation is {"is_active": true}.

Path Parameters:

Property
Required
Descriptions

id

True

The user id of the user.

Example Request

curl --location --request POST '{host}/api/v1/users/1/activate/' \
--header 'Authorization: Token {TOKEN}' \

Example Response (200 OK)

{}

Deactivate User

This process is used to deactivate users. After deactivating the user, a request is sent to the /users/{user_id}/ endpoint on the Commerce side to notify that the user has been deactivated. The request body for this operation is {"is_active": false}

Path Parameters:

Property
Required
Descriptions

id

True

The user id of the user.

Example Request

curl --location --request POST '{host}/api/v1/users/1/deactivate/' \
--header 'Authorization: Token {TOKEN}' \

Example Response (200 OK)

{}

Update Remote ID

This process is used to update user remote id users. A Celery task is initiated to send a request to the /users/?email={email} endpoint on the Commerce side. Subsequently, the task ensures the user's remote_id information is updated with the received id.

Path Parameters:

Property
Required
Descriptions

id

True

The user id of the user.

Example Request

curl --location --request POST '{host}/api/v1/users/1/update_remote_id/' \
--header 'Authorization: Token {TOKEN}' \

Example Response (200 OK)

{}

Last updated

Was this helpful?