This repository is a specific implementation for the Connect IoT project based on the official NEAR REST API SERVER repository following its license, so if you use this code, keep in mind to check its protection. NOTE: RUNNING THE API MUST BE DONE ON A RASPBERRY PI.
When consuming the API, it is important to know that the route is /call and the HTTP method that is used is POST type.
Click on a route for more information and examples
| Route | Method | Description |
|---|---|---|
| CONNECT IOT CONTRACT | ||
/call |
POST | Performs a call to the smart contract, validating the method |
- NEAR Account (with access to private key or seed phrase)
- Node.js
- npm or Yarn
- API request tool such as Postman
- Create a file .env with the ID of the smart contract:
NEAR_CONTRACT_ID=dev-1659666583036-94152895119798
- Clone repository
https://github.com/MexbaliaMX/ConnectIoT-API.git- Install dependencies
npm install- Configure
near-api-server.config.jsonDefault settings:
{
"server_host": "0.0.0.0",
"server_port": 5000,
"rpc_node": "https://rpc.testnet.near.org",
"init_disabled": true
}- Start server
node appPerforms a call to the smart contract, validating the method.
Method: POST
Valid methods:
create_registrydelete_registryadd_device_to_registrydelete_device_from_registryset_device_dataget_device_dataset_device_data_paramget_device_data_paramset_device_metadataget_device_metadataset_device_metadata_paramget_device_metadata_param
| Parameter | Description |
|---|---|
account_id |
Account ID that will be performing the call and will be charged for gas and attached tokens / deposit. |
seed_phrase OR private_key |
Seed phrase OR private key of the account ID above. |
method |
A valid method for the ConnectIoT method. |
params |
Arguments the method of the contract takes. |
Note: Use near login to save your key pair to your local machine.
Example:
{
"account_id": "paulcruz.testnet",
"private_key": "5a92dJw8NtnwPZmHAuCt3M123pE1aD2wM5z7BkTasdnCxbEHX22Gei2jnoWjaGcZUk2ZZtPriMa25CLpcp96s7Mw",
"method": "get_device_metadata_param",
"params": {"registry_name": "my_registry", "device_name": "my_device", "param": "timestamp"}
}Example Response:
{
"data": "1659740812726"
}Example:
{
"account_id": "paulcruz.testnet",
"private_key": "5a92dJw8NtnwPZmHAuCt3M123pE1aD2wM5z7BkTasdnCxbEHX22Gei2jnoWjaGcZUk2ZZtPriMa25CLpcp96s7Mw",
"method": "get_device_metadata",
"params": {"registry_name": "my_registry", "device_name": "my_device", "param": "timestamp"}
}Example Response:
{
"read_type": "streaming",
"timestamp": "1659740812726",
"area": "west"
}Reach out via website or send an email to info@mexbalia.com