associateEntityToThing method

Future<void> associateEntityToThing({
  1. required String entityId,
  2. required String thingName,
  3. int? namespaceVersion,
})

Associates a device with a concrete thing that is in the user's registry.

A thing can be associated with only one device at a time. If you associate a thing with a new device id, its previous association will be removed.

May throw InvalidRequestException. May throw ResourceNotFoundException. May throw InternalFailureException. May throw ThrottlingException.

Parameter entityId : The ID of the device to be associated with the thing.

The ID should be in the following format.

urn:tdm:REGION/ACCOUNT ID/default:device:DEVICENAME

Parameter thingName : The name of the thing to which the entity is to be associated.

Parameter namespaceVersion : The version of the user's namespace. Defaults to the latest version of the user's namespace.

Implementation

Future<void> associateEntityToThing({
  required String entityId,
  required String thingName,
  int? namespaceVersion,
}) async {
  ArgumentError.checkNotNull(entityId, 'entityId');
  _s.validateStringLength(
    'entityId',
    entityId,
    0,
    160,
    isRequired: true,
  );
  ArgumentError.checkNotNull(thingName, 'thingName');
  _s.validateStringLength(
    'thingName',
    thingName,
    1,
    128,
    isRequired: true,
  );
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.1',
    'X-Amz-Target': 'IotThingsGraphFrontEndService.AssociateEntityToThing'
  };
  await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    // TODO queryParams
    headers: headers,
    payload: {
      'entityId': entityId,
      'thingName': thingName,
      if (namespaceVersion != null) 'namespaceVersion': namespaceVersion,
    },
  );
}