createCalculatedAttributeDefinition method

Future<CreateCalculatedAttributeDefinitionResponse> createCalculatedAttributeDefinition({
  1. required AttributeDetails attributeDetails,
  2. required String calculatedAttributeName,
  3. required String domainName,
  4. required Statistic statistic,
  5. Conditions? conditions,
  6. String? description,
  7. String? displayName,
  8. Filter? filter,
  9. Map<String, String>? tags,
  10. bool? useHistoricalData,
})

Creates a new calculated attribute definition. After creation, new object data ingested into Customer Profiles will be included in the calculated attribute, which can be retrieved for a profile using the GetCalculatedAttributeForProfile API. Defining a calculated attribute makes it available for all profiles within a domain. Each calculated attribute can only reference one ObjectType and at most, two fields from that ObjectType.

May throw AccessDeniedException. May throw BadRequestException. May throw InternalServerException. May throw ResourceNotFoundException. May throw ThrottlingException.

Parameter attributeDetails : Mathematical expression and a list of attribute items specified in that expression.

Parameter calculatedAttributeName : The unique name of the calculated attribute.

Parameter domainName : The unique name of the domain.

Parameter statistic : The aggregation operation to perform for the calculated attribute.

Parameter conditions : The conditions including range, object count, and threshold for the calculated attribute.

Parameter description : The description of the calculated attribute.

Parameter displayName : The display name of the calculated attribute.

Parameter filter : Defines how to filter incoming objects to include part of the Calculated Attribute.

Parameter tags : The tags used to organize, track, or control access for this resource.

Parameter useHistoricalData : Whether historical data ingested before the Calculated Attribute was created should be included in calculations.

Implementation

Future<CreateCalculatedAttributeDefinitionResponse>
    createCalculatedAttributeDefinition({
  required AttributeDetails attributeDetails,
  required String calculatedAttributeName,
  required String domainName,
  required Statistic statistic,
  Conditions? conditions,
  String? description,
  String? displayName,
  Filter? filter,
  Map<String, String>? tags,
  bool? useHistoricalData,
}) async {
  final $payload = <String, dynamic>{
    'AttributeDetails': attributeDetails,
    'Statistic': statistic.value,
    if (conditions != null) 'Conditions': conditions,
    if (description != null) 'Description': description,
    if (displayName != null) 'DisplayName': displayName,
    if (filter != null) 'Filter': filter,
    if (tags != null) 'Tags': tags,
    if (useHistoricalData != null) 'UseHistoricalData': useHistoricalData,
  };
  final response = await _protocol.send(
    payload: $payload,
    method: 'POST',
    requestUri:
        '/domains/${Uri.encodeComponent(domainName)}/calculated-attributes/${Uri.encodeComponent(calculatedAttributeName)}',
    exceptionFnMap: _exceptionFns,
  );
  return CreateCalculatedAttributeDefinitionResponse.fromJson(response);
}