Agent

[!info] Overview The Agent REST API manages payment agents (initiators) in the pkbillms billing system. Agents are entities authorized to initiate payment transactions through API integration with authentication and IP filtering capabilities.

📋 Table of Contents


Quick Reference

[!abstract] API Configuration

  • Base URL: /api

  • Entity Name: pkbillmsAgent

  • Controller: AgentResource

  • Framework: Spring Boot + JHipster

  • Auth: Required (Spring Security)

  • Content-Type: application/json

Endpoints Summary

Method
Endpoint
Description
Status

POST

/api/agents

Create new agent

201

POST

/api/agents/save-with-user

Create agent with user account

201

PUT

/api/agents/{id}

Full update

200

PATCH

/api/agents/{id}

Partial update

200

GET

/api/agents

Get all with criteria

200

GET

/api/agents/simple

Get simple key-value list

200

GET

/api/agents/{id}

Get by ID

200

GET

/api/agents/count

Count by criteria

200

DELETE

/api/agents/{id}

Soft delete agent

204

DELETE

/api/agents/hard/{id}

Hard delete agent

204


Data Models

Agent DTO Structure

[!note] Data Transfer Object Represents a payment agent with API authentication and multilingual support.

Field Specifications

Field
Type
Required
Max/Range
DB Column
Description

id

Long

❌ Auto

-

id

Primary key

shortName

String

64

short_name

Display name

amountRatio

Integer

-

amount_ratio

Precision (1 or 100)

apiKey

String

64

api_key

API authentication key

currencies

Set

64 chars

currencies

Allowed currency codes

ipAddresses

Set

32 chars

ip_addresses

IP whitelist

logo

byte[]

LOB

logo

Logo image binary

logoContentType

String

-

logo_content_type

MIME type

ord

Integer

-

ord

Display order

active

Boolean

-

active

Active/Inactive

phoneNumber

String

32

phone_number

Contact phone

inn

String

32

inn

Tax ID (INN/VAT)

orgName

String

64

org_name

Organization name

email

String

4-254

email

Email (unique)

state

AgentState

ENUM

state

Agent state

titles

Set

-

rel_agent__title

Multilingual titles

AgentState Enum

DetailedAgentDTO

[!note] Extended DTO for User Creation Used when creating an agent with an associated user account.

Audit Fields (Inherited)

[!success] Auto-managed These fields are automatically populated by the system.

Field
Type
Description

createdBy

String

Creator username

createdDate

Instant

Creation timestamp

lastModifiedBy

String

Last modifier

lastModifiedDate

Instant

Last modification


API Endpoints

Create Agent

POST /api/agents

Creates a new payment agent entity.

Request

Headers:

Body:

[!warning] Validation Rules

  • id must be null (auto-generated)

  • shortName, amountRatio, apiKey, currencies, active, titles are required

  • email must be unique if provided

  • currencies and ipAddresses are stored as comma-separated values

  • String fields must respect max length

Response

✅ Success (201 Created):

❌ Error (400 - ID exists):


Create Agent with User

[!example] POST /api/agents/save-with-user Creates a new agent with an associated user account in one transaction.

Request

Headers:

Body:

[!warning] User Creation Rules

  • User login must be unique

  • Password must meet security requirements

  • Authorities are assigned to the user

  • User is automatically linked to the agent

Response

✅ Success (201 Created):

[!info] Use Case This endpoint is useful for:

  • Onboarding new agents

  • Creating agent accounts with system access

  • Automated agent provisioning


Update Agent

[!example] PUT /api/agents/{id} Completely updates an existing agent.

Path Parameters

  • id (Long) - Agent identifier

Request

Headers:

Body:

[!warning] Validation

  • Body id must not be null

  • Path id must match body id

  • Agent must exist in database

  • Email must be unique (if changed)

Response

✅ Success (200 OK):

❌ Errors:

Status
Detail
Message

400

Invalid id

error.idnull

400

Invalid ID

error.idinvalid

400

Entity not found

error.idnotfound


Partial Update

[!example] PATCH /api/agents/{id} Updates only specified fields. Null fields are ignored.

Path Parameters

  • id (Long) - Agent identifier

Request

Headers:

Body (Example - toggle active and update state):

[!tip] Partial Update Behavior

  • Only non-null fields are updated

  • Other fields remain unchanged

  • Perfect for status toggles or single field updates

  • API keys can be rotated without changing other data

Response

✅ Success (200 OK):


Get All Agents

[!example] GET /api/agents Retrieves paginated list with filtering criteria.

Query Parameters

Pagination:

  • page - Page number (0-indexed, default: 0)

  • size - Items per page (default: 20)

  • sort - Sort criteria (e.g., shortName,asc)

  • unPaged - Boolean for unpaged results

Filters (AgentCriteria):

  • id.equals, id.in

  • shortName.contains, shortName.equals

  • active.equals - Filter by status

  • state.equals, state.in - Filter by state

  • email.contains

  • inn.equals

  • apiKey.equals - Find by API key

Example Requests

Response

✅ Success (200 OK):


Get Simple Agents

[!example] GET /api/agents/simple Retrieves simplified key-value list for dropdowns and selection lists.

Query Parameters

  • Same criteria as [[#Get All Agents]]

  • Pagination supported

Example Request

Response

✅ Success (200 OK):

[!tip] Use Case Perfect for:

  • Dropdown selections in UI

  • Autocomplete fields

  • Report filters

  • Minimal data transfer


Get Single Agent

[!example] GET /api/agents/{id} Retrieves a single agent by ID with all relationships.

Path Parameters

  • id (Long) - Agent identifier

Request

Response

✅ Success (200 OK):

❌ Error (404 Not Found):


Count Agents

example GET /api/agents/count Returns count of agents matching criteria.

Query Parameters

Same filtering parameters as [[#Get All Agents]]

Example Requests

Response

✅ Success (200 OK):


Soft Delete Agent

DELETE /api/agents/{id}

Soft deletes an agent (marks as inactive, preserves data).

Path Parameters

  • id (Long) - Agent identifier

Request

Response

✅ Success (204 No Content):

[!info] Soft Delete Behavior

  • Agent is not permanently deleted

  • Typically sets active = false or similar flag

  • Historical data is preserved

  • Agent can be reactivated

  • Transactions remain linked


Hard Delete Agent

[!example] DELETE /api/agents/hard/{id} Permanently deletes an agent from the database.

Path Parameters

  • id (Long) - Agent identifier

Request

Response

✅ Success (204 No Content):

[!danger] Hard Delete Warning Permanently deletes:

  • Agent entity

  • Associated I18n titles

  • May fail if agent has dependent relationships (AgentRecipients, Deposits)

Use with extreme caution! This cannot be undone.


Examples

Example 1: Create Agent for Branch Office

[!example]- Setup Branch Agent Request:

Example 2: Create Agent with User Account

[!example]- Onboard New Agent with Login Request:

Example 3: Rotate API Key

[!example]- Update API Key for Security Request:

Response:

Example 4: Suspend Agent

[!example]- Temporarily Suspend Agent Request:


Error Handling

Error Response Format

[!failure] RFC 7807 Problem Details All errors follow standardized format.

HTTP Status Codes

Code
Type
Description
Common Causes

400

Bad Request

Invalid request

Validation failure, ID mismatch, duplicate email

401

Unauthorized

Auth required

Missing/invalid token

403

Forbidden

Access denied

Insufficient permissions

404

Not Found

Resource missing

Invalid ID, deleted entity

409

Conflict

Resource conflict

Duplicate shortName, email already exists

500

Server Error

Internal error

Database error, exception

Validation Error Example

[!bug] Field Validation Errors


Validation Rules

Required Fields

[!check] Mandatory Fields

  • shortName - Display name

  • amountRatio - Amount precision

  • apiKey - API authentication key

  • currencies - Allowed currencies

  • active - Active status

  • titles - At least one title required

Field Constraints

Field
Rules
Error Messages

id

Null for POST

"A new agent cannot already have an ID"

id

Not null for PUT/PATCH

"Invalid id"

shortName

@NotNull, @Size(max=64)

"must not be null", "size must be between 0 and 64"

amountRatio

@NotNull

"must not be null"

apiKey

@NotNull, @Size(max=64)

"must not be null", "size must be between 0 and 64"

currencies

@NotNull, @Size(max=64)

"must not be null", "size must be between 0 and 64"

ipAddresses

@Size(max=32)

"size must be between 0 and 32"

active

@NotNull

"must not be null"

phoneNumber

@Size(max=32)

"size must be between 0 and 32"

inn

@Size(max=32)

"size must be between 0 and 32"

orgName

@Size(max=64)

"size must be between 0 and 64"

email

@Size(min=4, max=254), unique

"size must be between 4 and 254", "must be unique"

titles

@NotNull, not empty

"must not be null", "must not be empty"

Business Rules

[!info] Business Validation

  • shortName should be unique (recommended)

  • email must be unique if provided

  • apiKey should be cryptographically secure (64 chars recommended)

  • currencies contains ISO 4217 numeric currency codes

  • ipAddresses contains valid IPv4/IPv6 addresses

  • amountRatio typically 1 (sum) or 100 (tiyin)

  • At least one title must be provided


Security & Authentication

API Key Authentication

[!abstract] Agent API Key System

The apiKey field is used to authenticate agents when making API requests:

Key Format:

  • Length: Up to 64 characters

  • Recommended format: sk_live_{environment}_{random}

  • Example: sk_live_production_abc123xyz789

Security Best Practices:

Key Rotation:

IP Address Filtering

[!info] IP Whitelist Configuration

Agents can restrict API access to specific IP addresses:

Format:

  • Stored as Set in database

  • Converted to comma-separated values

  • Supports both IPv4 and IPv6

Example Configuration:

Currency Restrictions

[!tip] Multi-Currency Support

Agents can be restricted to specific currencies:

Currency Codes (ISO 4217):

  • 860 - UZS (Uzbekistan Sum)

  • 840 - USD (US Dollar)

  • 978 - EUR (Euro)

  • 643 - RUB (Russian Ruble)

Example:

Multilingual Support

[!tip] I18n Integration

Agents support multiple languages through I18n titles:

Example:

Display Logic:


🔧 cURL Command Reference

Create

Create with User

Update

Partial Update

Get All

Get Simple

Get Single

Count

Soft Delete

Hard Delete

Last updated