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
 });

Implements

Implemented by

Index

Properties

additionalHeaders

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

data: string

Payload sent to the target device

dataType

dataType: string

HTTP Content-Type header

deviceId

deviceId: string

Device ID of the target device.

headers

headers: string
deprecated

use HttpRequestData.additionalHeaders

List of HTTP headers for the request.

method

HTTP method to perform

path

path: string

URI path on the target device

Optional port

port: undefined | number

Port number on the target device. Default is port 80.

protocol

protocol: Protocol

Protocol to use when sending this command

requestId

requestId: string

Request ID from the associated EXECUTE intent.