Invoke Service¶
Service invocation API for the device.
This API can execute cached commands or instant commands. When executing instant commands, the API response data is returned after the device returns the service invocation results. If the device does not return the service invocation results within the specified service execution timeout period, the EnOS service invocation will wait for the timeout and then return the response data.
When executing cached commands, the data will be returned directly after being cached.
Operation Permissions¶
Required Authorization |
Required Operation Permission |
---|---|
Asset |
Control |
Request Format¶
POST https://{apigw-address}/connect-service/v2.1/commands?action=invokeService
Request Parameters (URI)¶
Note
Use one of the following methods to specify the device:
Include
assetId
in the requestInclude
productKey
+deviceKey
in the request
Name |
Location (Path/Query) |
Mandatory/Optional |
Data Type |
Description |
---|---|---|---|---|
orgId |
Query |
Mandatory |
String |
The organization ID which the asset belongs to. How to get orgId>> |
assetId |
Query |
Optional (See Note above) |
String |
The asset ID. How to get assetId>> |
productKey |
Query |
Optional (See Note above) |
String |
The product key. To be used with |
deviceKey |
Query |
Optional (See Note above) |
String |
The device key. To be used with |
serviceId |
Query |
Mandatory |
String |
The ID of the invoked service. |
pendingTtl |
Query |
Optional |
Integer |
The cache storage time. Its unit is seconds and its range is [0 - 172800 (i.e. 48 hours)], which is 0 by default. If the pendingTtl is 0, it indicates that the commands will be executed immediately. |
timeout |
Query |
Optional |
Integer |
The timeout period of the service execution in seconds. Its range is [1-60] with a default value of 30 seconds. |
Request Parameters (Body)¶
Name |
Mandatory/Optional |
Data Type |
Description |
---|---|---|---|
inputData |
Optional |
Map (Key is of String type and the Value is of String, Number, Array or Object type) |
The input parameter for service invocation. The key is the parameter identifier, and the value data type will be as per defined in the |
Response Parameters¶
Name |
Data Type |
Description |
---|---|---|
data |
Service Invocation Return Struct |
The service invocation results. For details, see Service Invocation Return Struct. |
Service Invocation Return Struct ¶
Name |
Data Type |
Description |
---|---|---|
commandId |
String |
The command ID. |
outputData |
Map (Key is of String type and the Value is of String, Number, Array or Object type) |
If the request’s pendingTtl is 0 (i.e. the requested commands are executed immediately), the device service invocation results are returned, where the value data type will be as per defined in the |
Error Codes¶
For the description of error codes, see Error Codes.
Samples¶
Request Sample¶
url: https://{apigw-address}/connect-service/v2.1/commands?action=invokeService&deviceKey=yourDeviceKey&pendingTtl=1000&productKey=yourProductKey&serviceId=identifier&orgId=yourOrgId&timeout=30
method: POST
requestBody:
{
"inputData":{
"canshu2":22.2,
"canshu1":11
}
}
Return Sample¶
{
"code": 0,
"msg": "Success",
"submsg": null,
"requestId": "7d863d517eae4f18a2776452eb1305bb",
"data": {
"commandId": "2078724684846989312",
"outputData": {
}
}
}
Java SDK Sample¶
package com.envisioniot.enos.api.sample.connect_service.command;
import com.envision.apim.poseidon.config.PConfig;
import com.envision.apim.poseidon.core.Poseidon;
import com.envisioniot.enos.connect_service.v2_1.service.InvokeServiceRequest;
import com.envisioniot.enos.connect_service.v2_1.service.InvokeServiceResponse;
import com.google.common.collect.ImmutableMap;
public class InvokeService {
public static void main(String[] args) {
String appKey = "yourAppKey";
String appSecret = "yourAppSecret";
String serverUrl = "yourServerUrl";
String orgId = "yourOrgId";
String productKey = "yourProductKey";
String deviceKey = "yourDeviceKey";
String serviceIdentifier = "yourServiceIdentifier";
InvokeServiceRequest request = new InvokeServiceRequest();
request.setOrgId(orgId);
request.setProductKey(productKey);
request.setDeviceKey(deviceKey);
request.setServiceId(serviceIdentifier);
request.setInputData(ImmutableMap.of("parameter_1", 22.2, "parameter_2", 11));
request.setPendingTtl(3600L); // e.g. pending TTL is 1 hour
request.setTimeout(30); // timeout is 30 seconds
InvokeServiceResponse response = Poseidon.config(PConfig.init().appKey(appKey).appSecret(appSecret).debug())
.url(serverUrl)
.getResponse(request, InvokeServiceResponse.class);
}
}