requestPhoneNumber method

Future<RequestPhoneNumberResult> requestPhoneNumber({
  1. required String isoCountryCode,
  2. required MessageType messageType,
  3. required List<NumberCapability> numberCapabilities,
  4. required RequestableNumberType numberType,
  5. String? clientToken,
  6. bool? deletionProtectionEnabled,
  7. bool? internationalSendingEnabled,
  8. String? optOutListName,
  9. String? poolId,
  10. String? registrationId,
  11. List<Tag>? tags,
})

Request an origination phone number for use in your account. For more information on phone number request see Request a phone number in the End User Messaging SMS User Guide.

May throw AccessDeniedException. May throw ConflictException. May throw InternalServerException. May throw ResourceNotFoundException. May throw ServiceQuotaExceededException. May throw ThrottlingException. May throw ValidationException.

Parameter isoCountryCode : The two-character code, in ISO 3166-1 alpha-2 format, for the country or region.

Parameter messageType : The type of message. Valid values are TRANSACTIONAL for messages that are critical or time-sensitive and PROMOTIONAL for messages that aren't critical or time-sensitive.

Parameter numberCapabilities : Indicates if the phone number will be used for text messages, voice messages, or both.

Parameter numberType : The type of phone number to request.

When you request a SIMULATOR phone number, you must set MessageType as TRANSACTIONAL.

Parameter clientToken : Unique, case-sensitive identifier that you provide to ensure the idempotency of the request. If you don't specify a client token, a randomly generated token is used for the request to ensure idempotency.

Parameter deletionProtectionEnabled : By default this is set to false. When set to true the phone number can't be deleted.

Parameter internationalSendingEnabled : By default this is set to false. When set to true the international sending of phone number is Enabled.

Parameter optOutListName : The name of the OptOutList to associate with the phone number. You can use the OptOutListName or OptOutListArn.

Parameter poolId : The pool to associated with the phone number. You can use the PoolId or PoolArn.

Parameter registrationId : Use this field to attach your phone number for an external registration process.

Parameter tags : An array of tags (key and value pairs) to associate with the requested phone number.

Implementation

Future<RequestPhoneNumberResult> requestPhoneNumber({
  required String isoCountryCode,
  required MessageType messageType,
  required List<NumberCapability> numberCapabilities,
  required RequestableNumberType numberType,
  String? clientToken,
  bool? deletionProtectionEnabled,
  bool? internationalSendingEnabled,
  String? optOutListName,
  String? poolId,
  String? registrationId,
  List<Tag>? tags,
}) async {
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.0',
    'X-Amz-Target': 'PinpointSMSVoiceV2.RequestPhoneNumber'
  };
  final jsonResponse = await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    // TODO queryParams
    headers: headers,
    payload: {
      'IsoCountryCode': isoCountryCode,
      'MessageType': messageType.value,
      'NumberCapabilities': numberCapabilities.map((e) => e.value).toList(),
      'NumberType': numberType.value,
      'ClientToken': clientToken ?? _s.generateIdempotencyToken(),
      if (deletionProtectionEnabled != null)
        'DeletionProtectionEnabled': deletionProtectionEnabled,
      if (internationalSendingEnabled != null)
        'InternationalSendingEnabled': internationalSendingEnabled,
      if (optOutListName != null) 'OptOutListName': optOutListName,
      if (poolId != null) 'PoolId': poolId,
      if (registrationId != null) 'RegistrationId': registrationId,
      if (tags != null) 'Tags': tags,
    },
  );

  return RequestPhoneNumberResult.fromJson(jsonResponse.body);
}