InfoChain access interface
InfoChain allows JSON format requests for terminal users to inquiry stored data, or invoke modification . InfoChain requst format is flexible, developers are just required to provide a few mandatory items, define a few predefined items following InfoChain suggestion if necessary, and avoid to use some reserved items, the developer can define and explain the record items base on his business logic , like define a traditional database.
InfoChain accepts below types of requests:
1. CreateUser
Usage:
To create a user record for a user self.
Mandatory items:
Func: “CreateUser”
UserName: Unique user name who launched request
Password: User’s password. If this is not provided, then user must provide PassHash item
PassHash: User’s password hash string. If this is not provided, then user must provide Password item. When use Deliver.js or CommDeliver.js, Password item will be automatically converted to PassHash item. If Password item has not been converted to PassHash in the request string InfoChain received, InfoChain will do the conversion work. Developer can also create self defined password to hash function, just make sure the conversion result is unique and security
Predefined Items:
No
Reserved Items:
Client: Identification of the device deployed Deliver or CommDeliver app, automatically generated by Deliver or CommDeliver
ID: User’s ID in InfoChain, automatically generated by InfoChain
Datatype: Hard code as “User”, automatically generated by InfoChain
UserType:Hard code as “Common”,automatically generated by InfoChain
Request example:
{“Func”:”CreateUser”,”UserName”:”TestUser1”,”Password”:”11223344”,”Phone”:”81728826”,”Email”:”abc@xyz.com”}
This request is to create a user whose username is TestUser1,password is 11223344,phone is 81728826 and email is abc@xyz.com
2 QueryUser
Usage:
To query whole user record base on username and password
Mandatory items:
Func: “QueryUser”
UserName: Unique user name who launched request
Password(or PassHash): User’s password or password hash string. Refer to section 1
Predefined Items:
No
Reserved Items:
No
Request example:
{“Func”:”QueryUser”,”UserName”:”TestUser1”,”Password”:”11223344”}
This request is to query user TestUser1’s self user record details.
3. UpdateUser
Usage:
To update some user record items’ value, or add/delete user record items. If an item contained in a request, but not contained in original record, it will be added to this record. If a not reserved item contained in original record but not in request, it will be deleted from this record.
Mandatory items:
Func: “UpdateUser”
UserName: Unique user name who launched request
Password (or PassHash): Refer to section 1
ID: Id of the user record to be updated, it can be retrieved via QueryUser request
Predefined Items:
NewPassword(or NewPassHash): when user try to update self password setting via UpdateUser request, original password (or password hash) should be set to Password (or PassHash) item, new password (or password hash) should be set to NewPassword (or NewPassHash) item.
Reserved Items:
Client: Refer to section 1
ID: Refer to section 1
Datatype: Refer to section 1
Request example:
{“Func”:”UpdateUser”,”UserName”:”TestUser1”,”Password”:”11223344”,”Mobile”:”90218341”,”Email”:”aaa@xyz.com”,”NewPassword”:”12345678”}
This request try to change user TestUser1’s Email item from ‘abc@xyz.com’ to ‘aaa@xyz.com’, change the Password to ‘12345678’, remove the Phone item, and add the Mobile item
4. QueryUserHistory
Usage:
To query the user record change history
Mandatory items:
Func: “QueryUserHistory”
Key: ID of the user record to be checked
UserName: Unique user name who launched request
Password(or PassHash): User’s password or password hash string. Refer to section 1
Predifined Items:
None
Reserverd Items:
None
Request example:
{“Func”:”QueryUserHistory”,”Key”:”UR_202306121345901”,”UserName”:”TestUser2”,”Password”:”12345678”}
This request means user TestUser2 try to query a user with ID UR_202306121345901 (should be TestUser2 himself) whole change history. The response is a JSON list format string, contains every changed record of user UR_202306121345901.
5. CreateRecord
Usage:
To Create a common record in InfoChain
Mandatory items:
Func: “CreateRecord”
UserName: Unique user name who launched request
Password (or PassHash): Refer to section 1
RecordType: The record type can be indicated as Private, Protected or Public. The difference is :
A public record can be queried by any one, be updated by any registered user;
A protected record can be queried by registered user, be updated by the record creator and related users only;
A private record can only be queried and updated by the record creator and related users only.
Predefined Items:
RelatedUsers: Name(s) of other user(s) who can edit this record. If there are multiple related users, use “,” to split them, for example: “TestUser1,TestUser2;TestUser3”
Reserved Items:
Client: Refer to section 1
ID: Common record ID generated by InfoChain
Datatype: Hard code as “Record”,generated by InfoChain
Creator: InfoChain use Creator item to store the value of UserName item to record the this record’s creator
Request example:
{“Func”:”CreateRecord”,”RecordType”:”Protected”,”UserName”,”TestUser1”,”Password”:”12345678”,”Product_Name”:”P2P Chart Room”,”Product_Version”:”v1”,”LicenseNo”:”L34324252”,”RelatedUsers”:”TestUser2”}
This request means user TestUser1 try to create a protected record, to store a production’s information (Product name is “P2P Chart Room”,Product version is “v1”,License No is “L34324252”), this record has a related user TestUser2, who can edit this record also.
6. QueryRecord
Usage:
To query some record(s) by some conditions.
Mandatory items:
Func: “QueryRecord”
UserName: Unique user name who launched request. It is required if RecordType is not Public.
Password (or PassHash): Password (or password hash) of the user who launched request. It is required if RecordType is not Public
Predefined Items:
SearchClient: If want to use Client as a search condition, need to use SearchClient to represent to client to be searched
Reserved Items:
None
Request example:
{“Func”:”QueryRecord”,”RecordType”:”Public”,”Product_Type”:”Car”,”Product_Color”:”White”}
This request means anonymous user try to query all public records that Product_Type is Car and Product_Color is White.
{“Func”:”QueryRecord”,”RecordType”:”Protected”,”UserName”,”TestUser1”,”Password”:”12345678”}
This request means user TestUser1 try to query all protected record.
{“Func”:”QueryRecord”,”RecordType”:”Private”,”UserName”,”TestUser1”,”Password”:”12345678”,"Product_Name":"ProdABC"}
This request means user TestUser1 try to query private record(s) with Product_Name is ProdABC that created by him or related with him.
7. UpdateRecord
Usage:
To update one record according to record ID. For Public record, any registered user can update it; for Protected or Private record, only the record’s creator or related users can update it.
Mandatory items:
Func:”UpdateRecord”
ID: the ID of record to be updated, can be query via request QueryRecord
UserName: Unique user name who launched request
Password (or PassHash): Password (or password hash) of the user who launched request
Predefined Items:
RelatedUsers: Refer to section 5
Reserved Items:
Creator: Refer to section 5
ModifiedBy: InfoChain stores the request UserName item as ModifiedBy item, to record the user who launched this change
RecordType: user can not change a record’s RecordType. Refer to section 5
Datatype: refer to section 5
Request example:
{“Func”:”UpdateRecord”,”ID”:”RC_20230507102340739””UserName”,”TestUser2”,”Password”:”12345678”,”Product_Name”:”P2P Chart Room”,”Product_Version”:”v1.1”,”New_Feature”:”Added TLS protection”, ”LicenseNo”:”L34324252”, ”RelatedUsers”:”TestUser2,TestUser3”}
This request means user TestUser2 try to change the record that created in section 5, change item Product_Version to 1.1, change related users to TestUser2 and TestUser3, add an item New_Feature
8. QueryMultipleRecords
Usage:
To query multiple records in the same time
Mandatory items:
Func:”QueryMultipleRecords”
ParamList: A stringified JSON format array, each item is a QueryRecord request. In the request items, key "Func" can be ignored. Refer to section 6.
Note:
A ParamList item can be set as this format: "K1!K2":"?" , or "K1!K2@N":"?"
The first expression mains this item's value of key K1 is response's value of key K2 of previous request
The second expression mains this item's value of key K1 is response's value of key K2 of the N th executed request. N starts from 0.
Request example:
{“Func”:”QueryMultipleRequests”,"ParamList":"[{\"Product_Name\":\"P2P Chart Room\",\"Product_version\":\"v1.1\",\"UserName\":\"TestUser2\",\"Password\":\"12345678\"},{\"Customer\":\"Mike\",\"Age\":\"28\",\"UserName\":\"TestUser2\",\"Password\":\"12345678\"}] }"
This request means user TestUser2 try to query 2 type of records, the first record's Product_Name is "P2P Chart Room" and Product_Version is V1.1, the second record's Customer is "Mike" and Age is 28
{“Func”:”QueryMultipleRequests”,"ParamList":"[{\"Product_Name\":\"P2P Chart Room\",\"Product_version\":\"v1.1\",\"UserName\":\"TestUser2\",\"Password\":\"12345678\"},{\"ProductID!ID\":\"?\",\"Status\":\"Active\",\"UserName\":\"TestUser2\",\"Password\":\"12345678\"}] }"
This request means user TestUser2 try to query 2 type of records, the first record's Product_Name is "P2P Chart Room" and Product_Version is V1.1, the second record's key ProductID equal to the first record's ID, and Status is "Active"
9. UpdateMultipleRecords
Usage:
To query or modify multiple records in the same time
Mandatory items:
Func:”UpdateMultipleRecords”
ParamList: A stringified JSON format array, each item is a QueryRecord request. In the request items. Refer to section 6.
Note:
A ParamList item can be set as this format: "K1!K2":"?" , or "K1!K2@N":"?". Refer to section 8.
Request example:
{“Func”:”UpdateMultipleRequests”,"ParamList":"[{\"Func\":\"CreateRecord\",\"Product_Name\":\"P2P Meeting Room\",\"Product_version\":\"v1.2\",\"UserName\":\"TestUser2\",\"Password\":\"12345678\"},{\"Func\":\"UpdateRecord\",\"Customer\":\"Mike\",\"Status\":\"Active\",\"UserName\":\"TestUser2\",\"Password\":\"12345678\"}] }"
This request means user TestUser2 try to Create a record, set the record's Product_Name as "P2P Chart Meeting Room" and Product_Version is V1.1, then update a record,set its Customer as "Mike" and Status as "Active"
{“Func”:”UpdateMultipleRequests”,"ParamList":"[{\"Func\":\"QueryRecord\",\"Profit_Type\":\"House\",\"Address\":\"ST7,No3\",\"UserName\":\"TestUser2\",\"Password\":\"12345678\"},
{\"Func\":\"QueryRecord\",\"Product_Type\":\"Car\",\"Type\":\"T001\",\"UserName\":\"TestUser2\",\"Password\":\"12345678\"},{\"Func\":\"UpdateRecord\",\"ID\":\"UC_202310310391\",\"BuyerName!Owner@0\":\"?\",\"Payable!Price@1\":\"?\",\"Status\":\"Shipment\",\"UserName\":\"TestUser2\",\"Password\":\"12345678\"}] }"
This request means user TestUser2 try to query 2 records, the first record's Profit_Type is "House" and Address is "ST7,No3", the second record's Product_Type is "Car" and Type is "T001", then update record UC_202310310391, set its BuyName as the first record's value of field of Owner, set it's Payable as the second record's value of field "Price",set it's Status as "Shipment"
10. QueryRecordHistory
Usage:
To query the common record change history
Mandatory items:
Func: “QueryRecordHistory”
Key: ID of the common record to be checked
UserName: Unique user name who launched request
Password(or PassHash): User’s password or password hash string. Refer to section 1
Predifined Items:
None
Reserverd Items:
None
Request example:
{“Func”:”QueryRecordHistory”,”Key”:”RC_20230507102340739”,”UserName”:”TestUser2”,”Password”:”12345678”}
This request means user TestUser2 try to query the change history list of common record with ID RC_20230507102340739 . The response is a JSON list format string, contains every changed record of the record RC_20230507102340739.
©2023