HTTP request
An api service starts with the HTTP Request node, which you use to configure API request parameters and the Action for SDK calls. Each api service must contain exactly one HTTP Request node and end with an HTTP Response node. You can add other functional nodes between these two to implement your business logic. The resulting API can be called by external services or used for web visual development.
Prerequisites
The business service has been created. For more information, see Create a business service.
Configure the node
On the business logic editor page, from the list, drag the HTTP Request node onto the canvas and configure its properties.
| Parameter | Description |
| Node name | Supports Chinese characters, letters, digits, and underscores (_). The name can be up to 30 characters long. |
| Action | Specifies the value for the Action parameter in API calls. The value can contain uppercase and lowercase letters, and digits. |
| Account authentication | Select this option to require account authentication. This restricts service calls to signed-in accounts and is intended for use with web visual applications in IoT Studio. For more information about account authentication, see Account authentication. |
| Access control | If selected, an administrator must configure the roles allowed to call this service in the operations console. For more information, see Account. |
| Input parameter configuration | Configure the request parameters for the API call based on your business needs. Click + Add Input Parameter. The settings include the following:
|
Node output
The following example shows the output data from a successful call.
{
"code": 200,
"data": {
"parameterName1": parameterValue1,
"parameterName2": parameterValue2
},
"message": "success",
"localizedMsg": "Success"
}
See the node logs for output data from failed calls.
Using node output
You can reference output field values in subsequent nodes in the following ways:
- Reference specific parameter fields by using the query object.
For example, in a script node or a DingTalk robot node, you can use the
query.parameterNameformat to reference an API input parameter value.- DingTalk robot node: Select the Custom configuration method, set the message type to text, and configure the content. For example:
"content": "Check-in from {{query.cardId}}. Total check-ins: {{payload.calcul_result}}". - Script node: In a script, use the
query.parameterNameformat to reference an input parameter's value for data processing. For example, infor(let i=0;i, references the value of the input parameter.query.columncolumn
- DingTalk robot node: Select the Custom configuration method, set the message type to text, and configure the content. For example:
- Use this node's output as a data source for a subsequent node.
For example, when configuring a conditional or path selection node, you can select one of this node's request parameters as the data source.
In the Select Data Source dialog box, on the From Node tab, select the HTTP Request node and the corresponding input parameter, such as num, from the drop-down lists. Click OK.
Calling the API
After you publish an HTTP business service, in the business logic development workbench, click the Service Call Settings button
in the left navigation bar. On the API Call Method tab, obtain a call method from the Request Example section based on your requirements.
IoTApiClientBuilderParams builderParams = new IoTApiClientBuilderParams();
SyncApiGetClient syncClient = new SyncApiGetClient(builderParams);
Map<String, String> headers = new HashMap<>(8);
Map<String, String> querys = new HashMap<>(8);
// Set the API version.
querys.put("apiVer", "1.0.0");
querys.put("id", UUID.randomUUID().toString());
// If login is required, set the token for the current session.
querys.put("iotToken", "XXXXXXXXXX");
// Set parameters.
querys.put("action", "xxx");
// Request domain name, path, and request object.
String host = "xxx";
String path = "/xxx";
ApiResponse response = syncClient.doGet(host, path, true, headers, querys);
System.out.println(
"response code = " + response.getCode() + " response content = " + new String(response.getBody(),
"utf-8"));