Setting flespi token and region via API

This article describes how to configure flespi integration settings using the Remote API. These settings correspond to the flespi settings section on the Security tab in the user settings of the monitoring system. The flespi token is required for sending commands to flespi-type devices, or some flespi-based integrations, such as OEM or tachograph data streaming.

The flespi integration settings are stored as custom properties of the top account user item. The item/update_custom_property method is used to manage the following custom properties: flespi_token (flespi Master token), flespi_token_dc (data center region code), and flespi_region (full region configuration in JSON format).

This method works both for Wialon Hosting and Wialon Local. The only difference is the request host: https://hst-api.wialon.com for Wialon Hosting, or the URL of your monitoring site for Wialon Local.

These properties must be set on the top account user item, not on a unit or resource. The user performing the request must have the Edit not mentioned properties (ADF_ACL_ITEM_EDIT_OTHER, bit 0x80) access right to the top account user.

Step 1. Finding the top account user ID

Use the core/search_items request to find the system ID of the top account user.

Copied!
https://hst-api.wialon.com/wialon/ajax.html?svc=core/search_items&params={"spec":{"itemsType":"user","propName":"sys_name","propValueMask":"<top_account_name>","sortType":"sys_name"},"force":1,"flags":1,"from":0,"to":0}&sid=SESSION_IDENTIFIER

The system ID is returned in the id parameter of the response. Let’s assume it has a value of 600003506.

Step 2. Setting the flespi token

Use the item/update_custom_property request to set the flespi Master token.

Copied!
https://hst-api.wialon.com/wialon/ajax.html?svc=item/update_custom_property&params={"itemId":600003506,"name":"flespi_token","value":"YOUR_FLESPI_MASTER_TOKEN"}&sid=SESSION_IDENTIFIER
Parameter and its value Description
"itemId":600003506 The system ID of the top account user.
"name":"flespi_token" The custom property name for the flespi token.
"value":"YOUR_FLESPI_MASTER_TOKEN" The flespi Master token value. You can copy it from the Tokens tab on the flespi panel.

Response

Copied!
{
  "n": "flespi_token",
  "v": "YOUR_FLESPI_MASTER_TOKEN"
}

Step 3. Setting the data center region

Set the flespi data center region code.

Copied!
https://hst-api.wialon.com/wialon/ajax.html?svc=item/update_custom_property&params={"itemId":600003506,"name":"flespi_token_dc","value":"eu"}&sid=SESSION_IDENTIFIER
Parameter and its value Description
"name":"flespi_token_dc" The custom property name for the data center region.
"value":"eu" The region code. The data of flespi users is stored in the data center in the Netherlands (the eu region).

Response

Copied!
{
  "n": "flespi_token_dc",
  "v": "eu"
}

Step 4. Setting the flespi region configuration

Set the full region configuration. This property contains the endpoints and service URLs for the selected flespi region.

Copied!
https://hst-api.wialon.com/wialon/ajax.html?svc=item/update_custom_property&params={"itemId":600003506,"name":"flespi_region","value":"{\"apps\":{\"login\":\"https://flespi.io/login\"},\"cdn\":\"https://cdn.flespi.io\",\"default\":true,\"gw\":\"gw.flespi.io\",\"gw-ftp\":\"{channel-address}:21\",\"gw-ip\":\"185.213.2.30\",\"media\":\"https://media.flespi.io\",\"mqtt\":\"mqtt.flespi.io:8883\",\"mqtt-ws\":\"mqtt.flespi.io:443\",\"name\":\"eu\",\"registration-allowed\":true,\"rest\":\"https://flespi.io\"}"}&sid=SESSION_IDENTIFIER

The flespi_region value for the eu region contains the following configuration:

Key Value Description
apps.login https://flespi.io/login flespi login page URL.
cdn https://cdn.flespi.io CDN URL for flespi resources.
default true Marks this region as default.
gw gw.flespi.io flespi gateway address.
gw-ip 185.213.2.30 flespi gateway IP address.
gw-ftp {channel-address}:21 flespi FTP gateway address pattern.
media https://media.flespi.io Media server URL.
mqtt mqtt.flespi.io:8883 MQTT broker address (TLS).
mqtt-ws mqtt.flespi.io:443 MQTT over WebSocket address.
name eu Region name.
registration-allowed true Shows whether new account registration is allowed in this region.
rest https://flespi.io flespi REST API base URL.

Verifying the configuration

To verify the flespi settings, use the core/search_item request with the flag 0x00000002 (2) to retrieve the custom properties of the user item.

Copied!
https://hst-api.wialon.com/wialon/ajax.html?svc=core/search_item&params={"id":600003506,"flags":3}&sid=SESSION_IDENTIFIER

The response includes the prp object containing all custom properties, where you can verify the flespi_token, flespi_token_dc, and flespi_region values.

Removing flespi settings

To remove a flespi setting from a top account user, use the same item/update_custom_property method with an empty value:

Copied!
https://hst-api.wialon.com/wialon/ajax.html?svc=item/update_custom_property&params={"itemId":600003506,"name":"flespi_token","value":""}&sid=SESSION_IDENTIFIER

After removal, the property no longer appears in the prp object returned by core/search_item.

Error codes

Error code Description
4 Wrong input parameters.
6 Internal error while updating the property.
7 Item not found, or the current user has no Edit not mentioned properties (ADF_ACL_ITEM_EDIT_OTHER) access right to the item (top account user).

If you find a mistake in the text, please select it and press Ctrl+Enter.

Report a mistake

Your message was sent. Thank you!

An error occurred while submitting the form