Implements
Implemented by
Index
Properties
additionalHeaders
Additional HTTP headers for the request, as an object containing key/value pairs.
{
'Authorization': 'Bearer ...',
'Accept': 'application/json',
}
Type declaration
-
[key: string]: string
data
Payload sent to the target device
dataType
HTTP Content-Type header
deviceId
Device ID of the target device.
headers
List of HTTP headers for the request.
method
HTTP method to perform
path
URI path on the target device
Optional port
Port number on the target device. Default is port 80.
protocol
Protocol to use when sending this command
requestId
Request ID from the associated EXECUTE
intent.
Request to send a local device command over HTTP. Commands are sent to the device using DeviceManager.send.
Example GET request:
const command = new DataFlow.HttpRequestData(); command.requestId = request.requestId; command.deviceId = 'device-id'; command.method = Constants.HttpOperation.GET; command.port = 80; command.path = '/endpoint/control?state=on';
Example POST request:
const postData = { on: true, }; const command = new DataFlow.HttpRequestData(); command.requestId = request.requestId; command.deviceId = 'device-id'; command.method = Constants.HttpOperation.POST; command.port = 80; command.path = '/endpoint/control'; command.dataType = 'application/json'; command.data = JSON.stringify(postData);
Handle the response
If the command succeeds, DeviceManager.send returns an HttpResponseData result, which contains the HttpResponse.
const command = new DataFlow.HttpRequestData(); ... localHomeApp.getDeviceManager() .send(command) .then((result: DataFlow.CommandSuccess) => { const httpResult = result as DataFlow.HttpResponseData; const responseBody = httpResult.httpResponse.body; }) .catch((err: IntentFlow.HandlerError) => { // Handle command error });