Skip to content

list_available_phone_numbers

list_available_phone_numbers(
    iso_country_code: IsoCountryCode,
    number_capabilities: NumberCapabilityList,
    number_type: SearchableNumberType,
    *,
    config_overrides: Optional[PinpointSMSVoiceV2ClientConfig] = None,
    registration_id: Optional[RegistrationIdOrArn] = None,
    number_preference: Optional[NumberPreferenceList] = None,
    next_token: Optional[NextToken] = None,
    max_results: Optional[ListAvailablePhoneNumbersMaxResults] = None,
) -> ListAvailablePhoneNumbersResult

Retrieves a list of phone numbers that are available to request, based on the country, capabilities, and number type that you specify. You can optionally provide a number preference to return only numbers that match a specific digit pattern.

If no numbers match your search, this operation returns an empty list rather than an error. This operation currently supports only TEN_DLC number types in the US.

Parameters:

  • iso_country_code (IsoCountryCode) –

    The two-character code, in ISO 3166-1 alpha-2 format, for the country or region in which to search for available phone numbers. This operation currently supports only US.

  • number_capabilities (NumberCapabilityList) –

    The capabilities to filter by, such as SMS. Only phone numbers that support all of the specified capabilities are returned.

  • number_type (SearchableNumberType) –

    The type of phone number to search for.

  • registration_id (Optional[RegistrationIdOrArn], default: None ) –

    The registration associated with the request. A registration is required for regulated number types. You can specify either:

    • The unique identifier of the registration.

    • The Amazon Resource Name (ARN) of the registration.

  • number_preference (Optional[NumberPreferenceList], default: None ) –

    An optional selection preference used to return only phone numbers that match a specific digit pattern, such as numbers that start with, end with, or contain a particular sequence. You can specify at most one preference. Number preferences apply only to TEN_DLC numbers in the US.

  • next_token (Optional[NextToken], default: None ) –

    The token returned from a previous request to retrieve the next page of results.

  • max_results (Optional[ListAvailablePhoneNumbersMaxResults], default: None ) –

    The maximum number of results to return per page. If you don't specify a value, the default is 10.

Raises:

  • AccessDeniedException –

    The request was denied because you don't have sufficient permissions to access the resource.

  • ConflictException –

    Your request has conflicting operations. This can occur if you're trying to perform more than one operation on the same resource at the same time or it could be that the requested action isn't valid for the current state or configuration of the resource.

  • InternalServerException –

    The API encountered an unexpected error and couldn't complete the request. You might be able to successfully issue the request again in the future.

  • ResourceNotFoundException –

    A requested resource couldn't be found.

  • ThrottlingException –

    An error that occurred because too many requests were sent during a certain amount of time.

  • ValidationException –

    A validation exception for a field.

  • UnknownServiceError –

    The service returned an error code this client does not model.

Examples:

ListAvailablePhoneNumbers Search for available TEN_DLC phone numbers in the US that start with a specific area code.

>>> client.list_available_phone_numbers(iso_country_code='US', number_capabilities=['SMS'], number_type='TEN_DLC', registration_id='reg-1234567890abcdef0', number_preference=[{'PreferenceType': ['StartsWith'], 'Filter': ['+1206']}], max_results=10)
Source code in docs_src/capo_pinpoint_sms_voice_v2/_services/pinpoint_sms_voice_v2.py
def list_available_phone_numbers(
    self,
    iso_country_code: "capo_pinpoint_sms_voice_v2.types.iso_country_code.IsoCountryCode",
    number_capabilities: "capo_pinpoint_sms_voice_v2.types.number_capability_list.NumberCapabilityList",
    number_type: "capo_pinpoint_sms_voice_v2.types.searchable_number_type.SearchableNumberType",
    *,
    config_overrides: Optional[PinpointSMSVoiceV2ClientConfig] = None,
    registration_id: Optional[
        "capo_pinpoint_sms_voice_v2.types.registration_id_or_arn.RegistrationIdOrArn"
    ] = None,
    number_preference: Optional[
        "capo_pinpoint_sms_voice_v2.types.number_preference_list.NumberPreferenceList"
    ] = None,
    next_token: Optional[
        "capo_pinpoint_sms_voice_v2.types.next_token.NextToken"
    ] = None,
    max_results: Optional[
        "capo_pinpoint_sms_voice_v2.types.list_available_phone_numbers_max_results.ListAvailablePhoneNumbersMaxResults"
    ] = None,
) -> "capo_pinpoint_sms_voice_v2.types.list_available_phone_numbers_result.ListAvailablePhoneNumbersResult":
    """<p>Retrieves a list of phone numbers that are available to request, based on the country, capabilities, and number type that you specify. You can optionally provide a number preference to return only numbers that match a specific digit pattern.</p> <p>If no numbers match your search, this operation returns an empty list rather than an error. This operation currently supports only <code>TEN_DLC</code> number types in the <code>US</code>.</p>

    Args:
        iso_country_code: <p>The two-character code, in ISO 3166-1 alpha-2 format, for the country or region in which to search for available phone numbers. This operation currently supports only <code>US</code>.</p>
        number_capabilities: <p>The capabilities to filter by, such as SMS. Only phone numbers that support all of the specified capabilities are returned.</p>
        number_type: <p>The type of phone number to search for.</p>
        registration_id: <p>The registration associated with the request. A registration is required for regulated number types. You can specify either:</p> <ul> <li> <p>The unique identifier of the registration.</p> </li> <li> <p>The Amazon Resource Name (ARN) of the registration.</p> </li> </ul>
        number_preference: <p>An optional selection preference used to return only phone numbers that match a specific digit pattern, such as numbers that start with, end with, or contain a particular sequence. You can specify at most one preference. Number preferences apply only to <code>TEN_DLC</code> numbers in the <code>US</code>.</p>
        next_token: <p>The token returned from a previous request to retrieve the next page of results.</p>
        max_results: <p>The maximum number of results to return per page. If you don't specify a value, the default is 10.</p>

    Raises:
        capo_pinpoint_sms_voice_v2.errors.access_denied_exception.AccessDeniedException: <p>The request was denied because you don't have sufficient permissions to access the resource.</p>
        capo_pinpoint_sms_voice_v2.errors.conflict_exception.ConflictException: <p>Your request has conflicting operations. This can occur if you're trying to perform more than one operation on the same resource at the same time or it could be that the requested action isn't valid for the current state or configuration of the resource.</p>
        capo_pinpoint_sms_voice_v2.errors.internal_server_exception.InternalServerException: <p>The API encountered an unexpected error and couldn't complete the request. You might be able to successfully issue the request again in the future.</p>
        capo_pinpoint_sms_voice_v2.errors.resource_not_found_exception.ResourceNotFoundException: <p>A requested resource couldn't be found.</p>
        capo_pinpoint_sms_voice_v2.errors.throttling_exception.ThrottlingException: <p>An error that occurred because too many requests were sent during a certain amount of time.</p>
        capo_pinpoint_sms_voice_v2.errors.validation_exception.ValidationException: <p>A validation exception for a field.</p>
        capo_pinpoint_sms_voice_v2.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        ListAvailablePhoneNumbers
        Search for available TEN_DLC phone numbers in the US that start with a specific area code.

        >>> client.list_available_phone_numbers(iso_country_code='US', number_capabilities=['SMS'], number_type='TEN_DLC', registration_id='reg-1234567890abcdef0', number_preference=[{'PreferenceType': ['StartsWith'], 'Filter': ['+1206']}], max_results=10)
    """

    def _handler(
        req: "OperationRequest[capo_pinpoint_sms_voice_v2.types.list_available_phone_numbers_request.ListAvailablePhoneNumbersRequest]",
    ) -> OperationResponse[
        "capo_pinpoint_sms_voice_v2.types.list_available_phone_numbers_result.ListAvailablePhoneNumbersResult"
    ]:
        import capo_pinpoint_sms_voice_v2._operations.pinpoint_sms_voice_v2.list_available_phone_numbers

        output, http_response = (
            capo_pinpoint_sms_voice_v2._operations.pinpoint_sms_voice_v2.list_available_phone_numbers.list_available_phone_numbers(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("ListAvailablePhoneNumbers")
    )
    input_: capo_pinpoint_sms_voice_v2.types.list_available_phone_numbers_request.ListAvailablePhoneNumbersRequest = {
        "iso_country_code": iso_country_code,
        "number_capabilities": number_capabilities,
        "number_type": number_type,
    }
    if registration_id is not None:
        input_["registration_id"] = registration_id
    if number_preference is not None:
        input_["number_preference"] = number_preference
    if next_token is not None:
        input_["next_token"] = next_token
    if max_results is not None:
        input_["max_results"] = max_results

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output