Skip to main content

AutoNumber using Numbering API

The GetAutoNumber API can be used to generate unique numbers automatically in a certain format.

GetAutoNumber API​

/api/v0/applications/:app-id/datastores/:datastore-id/fields/:field-id/autonum

URL Params

app-id      : Application ID (Specify the display ID set in the admin panel)
datastore-id : Data store ID (specify display ID set in the admin panel)
field-id : Field ID for auto-numbered items (specify display ID set on the admin panel)

Query Params

- branch_key    : Specify the branch number code    (Optional)
- zero_padding : Add zeros to the number e.g.)1 -> 0001
- digit : Specify the number of digits e.g.)5 -> 00001

If you want to get a branch number for each department or product, use branch_key to operate on each branch number

Configuration of AutoNumber fields​

The numbering API (GetAutoNumber) supports auto-numbered fields. To use the numbering API, you must add and configure an auto number type field.

  1. Create an auto number type field using "add a new field" on the admin panel
  2. Set the Field ID in "field settings"

Configuring auto number type fields

Examples of required IDs

- app-id :    TestApp
- datastore-id : TODO-SAMPLE
- field-id : AutoNum1

GetAutoNumber API call example​

GetAutoNumber

GET https://api.hexabase.io/api/v0/applications/TestApp/datastores/TODO-SAMPLE/fields/AutoNum1/autonum

Types of numbering

Default(no parameter specified)=>   Prefix+Sequential number
branch_key (Specify branch number) => Prefix + branch number + Sequential number (within branch number)

Request example

... fields/AutoNum1/autonum?branch_key=SUBCODE_&zero_padding=true&digit=3

Response example

{
"has_error": false,
"result": {
"number": 4,
"value": "PREFIX_SUBCODE_004"
}
}

Numbering API use cases​

The value is updated every time you get it with the numbering API. To keep the obtained value, store it in another field.

The field to be stored can be a Text type field. It is not necessary to store them in auto number fields.

"value": Get “A001"​

GET /autonum?branch_key=A&zero_padding=true&digit=3

Sequential numbering by year and month​

GET /autonum?branch_key=202011&zero_padding=true&digit=5

Numbering API use cases

How the numbering API works​

The numbering API will be numbered in the order in which the API is executed. The number management table has the following logical structure. The automatically assigned numbers are transaction-managed using MySQL to prevent duplicates. At this time, if the branch number is changed, it will be reset.

Field IDBranch number codeNumber
AutoNum1NULL0
AutoNum1SUBCODE_4
AutoNum120201112
FieldBNULL10001
FieldCD101345
FieldCD102234
:
: