createThing method

Future<CreateThingResponse> createThing({
  1. required String thingName,
  2. AttributePayload? attributePayload,
  3. String? billingGroupName,
  4. String? thingTypeName,
})

Creates a thing record in the registry. If this call is made multiple times using the same thing name and configuration, the call will succeed. If this call is made with the same thing name but different configuration a ResourceAlreadyExistsException is thrown.

May throw InvalidRequestException. May throw ThrottlingException. May throw UnauthorizedException. May throw ServiceUnavailableException. May throw InternalFailureException. May throw ResourceAlreadyExistsException. May throw ResourceNotFoundException.

Parameter thingName : The name of the thing to create.

You can't change a thing's name after you create it. To change a thing's name, you must create a new thing, give it the new name, and then delete the old thing.

Parameter attributePayload : The attribute payload, which consists of up to three name/value pairs in a JSON document. For example:

{"attributes":{"string1":"string2"}}

Parameter billingGroupName : The name of the billing group the thing will be added to.

Parameter thingTypeName : The name of the thing type associated with the new thing.

Implementation

Future<CreateThingResponse> createThing({
  required String thingName,
  AttributePayload? attributePayload,
  String? billingGroupName,
  String? thingTypeName,
}) async {
  ArgumentError.checkNotNull(thingName, 'thingName');
  _s.validateStringLength(
    'thingName',
    thingName,
    1,
    128,
    isRequired: true,
  );
  _s.validateStringLength(
    'billingGroupName',
    billingGroupName,
    1,
    128,
  );
  _s.validateStringLength(
    'thingTypeName',
    thingTypeName,
    1,
    128,
  );
  final $payload = <String, dynamic>{
    if (attributePayload != null) 'attributePayload': attributePayload,
    if (billingGroupName != null) 'billingGroupName': billingGroupName,
    if (thingTypeName != null) 'thingTypeName': thingTypeName,
  };
  final response = await _protocol.send(
    payload: $payload,
    method: 'POST',
    requestUri: '/things/${Uri.encodeComponent(thingName)}',
    exceptionFnMap: _exceptionFns,
  );
  return CreateThingResponse.fromJson(response);
}