RecordApi¶
The RecordApi allows you to list, query and insert records in an IL2 chain. To get an instance of the RecordApi, you can use the following example:
from pyil2 import IL2Client
client = IL2Client(
host='https://il2.node:32032/',
cert_filepath='rest.api.pfx',
cert_password='Str0ngPassword'
)
api = client.api('record')
To list the records in a chain, you can use the code bellow:
records = api.list_records('UHtr...REDACTED...vXRY')
It is also possible to make some queries using the InterlockQL:
# Query records that use the app 8 (JSON Documents)
records = api.list_records(
chain_id='UHtr...REDACTED...vXRY',
query="USE APP #8\nEVERYTHING"
)
It is also possible to insert records using the RecordApi, however, you will need to know the payload format in bytes for each app. We highly recommend to use the APIs designed specifically for each application.
The list of methods are described as follows:
- class pyil2.api.RecordApi(client: IL2Client)¶
Bases:
BaseApi
API class for the record requests.
- Parameters:
client (
pyil2.IL2Client
) – IL2Client to be used to send requests.
- base_url¶
Base path of the requests.
- Type:
str
- add_record(chain_id: str, new_record: NewRecordModel) RecordModel | ErrorDetailsModel ¶
Add a new record using raw bytes. The payload must be in the correct application ID format in Base64.
Note: Use this method only if you know the payload format. We highly recommend to use the applications APIs to insert records.
- Parameters:
chain_id (str) – Chain ID.
new_record (
pyil2.models.record.NewRecordModel
) – Model with the description of the new record.
- Returns:
Added record model.
- Return type:
- get_record_at(chain_id: str, serial: int) RecordModel | ErrorDetailsModel ¶
Get a record by serial number.
- Parameters:
chain_id (str) – Chain ID.
serial (int) – Record serial number.
- Returns:
Record in a chain.
- Return type:
- get_record_at_as_json(chain_id: str, serial: int) RecordAsJsonModel | ErrorDetailsModel ¶
Get a record with the payload as JSON by serial number.
- Parameters:
chain_id (str) – Chain ID.
serial (int) – Record serial number.
- Returns:
Record in a chain with the payload as JSON.
- Return type:
- list_records(chain_id: str, first_serial: int = None, last_serial: int = None, last_to_first: bool = False, ommit_payload: bool = False, page: int = 0, size: int = 10) ListModel[RecordModel] | ErrorDetailsModel ¶
Get a list of records in a chain.
- Parameters:
chain_id (str) – Chain ID.
first_serial (int) – Serial number of first record to read. Default: First in whole chain.
last_serial (int) – Serial number of last record to read. Default: Last in whole chain.
last_to_first (bool) – If True, return the items in reverse order.
ommit_payload (bool) – If True, ommits the payload in the response.
page (
int
) – Page to return.size (
int
) – Number of items per page.
- Returns:
List of records in a chain.
- Return type:
pyil2.models.base.ListModel
[pyil2.models.record.RecordModel
]
- list_records_as_json(chain_id: str, first_serial: int = None, last_serial: int = None, last_to_first: bool = False, page: int = 0, size: int = 10) ListModel[RecordAsJsonModel] | ErrorDetailsModel ¶
Get a list of records in a chain with the payload mapped to a JSON format.
- Parameters:
chain_id (str) – Chain ID.
first_serial (int) – Serial number of first record to read. Default: First in whole chain.
last_serial (int) – Serial number of last record to read. Default: Last in whole chain.
last_to_first (bool) – If True, return the items in reverse order.
page (
int
) – Page to return.size (
int
) – Number of items per page.
- Returns:
List of records in a chain with the payload as JSON.
- Return type:
pyil2.models.base.ListModel
[pyil2.models.record.RecordAsJsonModel
]
- query_records(chain_id: str, query: str, how_many: int = None, last_to_first: bool = False, ommit_payload: bool = False, page: int = 0, size: int = 10) ListModel[RecordModel] | ErrorDetailsModel ¶
Query records in a chain using the InterlockQL language.
- Parameters:
chain_id (str) – Chain ID.
query (str) – Query in the InterlockQL language.
how_many (int) – How many records to return. If ommited or 0 returns all.
last_to_first (bool) – If True, return the items in reverse order.
ommit_payload (bool) – If True, ommits the payload in the response.
page (
int
) – Page to return.size (
int
) – Number of items per page.
- Returns:
List of records in a chain.
- Return type:
pyil2.models.base.ListModel
[pyil2.models.record.RecordModel
]
- query_records_as_json(chain_id: str, query: str, how_many: int = None, last_to_first: bool = False, page: int = 0, size: int = 10) ListModel[RecordAsJsonModel] | ErrorDetailsModel ¶
Query records with the payload as JSON in a chain using the InterlockQL language.
- Parameters:
chain_id (str) – Chain ID.
query (str) – Query in the InterlockQL language.
how_many (int) – How many records to return. If ommited or 0 returns all.
last_to_first (bool) – If True, return the items in reverse order.
page (
int
) – Page to return.size (
int
) – Number of items per page.
- Returns:
List of records in a chain with the payload as JSON.
- Return type:
pyil2.models.base.ListModel
[pyil2.models.record.RecordAsJsonModel
]