PhoneNumbersClient Class
- java.
lang. Object - com.
azure. communication. phonenumbers. PhoneNumbersClient
- com.
public final class PhoneNumbersClient
Synchronous client for Communication service phone number operations.
Instantiating a synchronous Phone Numbers Client
PhoneNumbersClient phoneNumberClient = new PhoneNumbersClientBuilder()
.endpoint(endpoint)
.credential(keyCredential)
.httpClient(httpClient)
.buildClient();
Method Summary
Methods inherited from java.lang.Object
Method Details
beginPurchasePhoneNumbers
public SyncPoller<PhoneNumberOperation,PurchasePhoneNumbersResult> beginPurchasePhoneNumbers(String searchId)
Starts the purchase of the phone number(s) in the search result associated with a given id.
This function returns a Long Running Operation poller that allows you to wait indefinitely until the operation is complete.
Code Samples
PollResponse<PhoneNumberOperation> purchaseResponse =
phoneNumberClient.beginPurchasePhoneNumbers(searchId).waitForCompletion();
System.out.println("Purchase phone numbers is complete: " + purchaseResponse.getStatus());
Parameters:
Returns:
beginPurchasePhoneNumbers
public SyncPoller<PhoneNumberOperation,PurchasePhoneNumbersResult> beginPurchasePhoneNumbers(String searchId, Boolean agreeToNotResell)
Starts the purchase of the phone number(s) in the search result associated with a given id. This function returns a Long Running Operation poller that allows you to wait indefinitely until the operation is complete.
Code Samples
PollResponse<PhoneNumberOperation> purchaseResponse =
phoneNumberClient.beginPurchasePhoneNumbers(searchId).waitForCompletion();
System.out.println("Purchase phone numbers is complete: " + purchaseResponse.getStatus());
Parameters:
Returns:
beginPurchasePhoneNumbers
public SyncPoller<PhoneNumberOperation,PurchasePhoneNumbersResult> beginPurchasePhoneNumbers(String searchId, Boolean agreeToNotResell, Context context)
Starts the purchase of the phone number(s) in the search result associated with a given id. This function returns a Long Running Operation poller that allows you to wait indefinitely until the operation is complete.
Code Samples
PollResponse<PhoneNumberOperation> purchaseResponse = phoneNumberClient
.beginPurchasePhoneNumbers(searchId, Context.NONE).waitForCompletion();
System.out.println("Purchase phone numbers is complete: " + purchaseResponse.getStatus());
Parameters:
Returns:
beginPurchasePhoneNumbers
public SyncPoller<PhoneNumberOperation,PurchasePhoneNumbersResult> beginPurchasePhoneNumbers(String searchId, Context context)
Starts the purchase of the phone number(s) in the search result associated with a given id.
This function returns a Long Running Operation poller that allows you to wait indefinitely until the operation is complete.
Code Samples
PollResponse<PhoneNumberOperation> purchaseResponse = phoneNumberClient
.beginPurchasePhoneNumbers(searchId, Context.NONE).waitForCompletion();
System.out.println("Purchase phone numbers is complete: " + purchaseResponse.getStatus());
Parameters:
Returns:
beginReleasePhoneNumber
public SyncPoller<PhoneNumberOperation,ReleasePhoneNumberResult> beginReleasePhoneNumber(String phoneNumber)
Starts the update of capabilities for a purchased phone number.
This function returns a Long Running Operation poller that allows you to wait indefinitely until the operation is complete.
Code Samples
PollResponse<PhoneNumberOperation> releaseResponse =
phoneNumberClient.beginReleasePhoneNumber("+18001234567").waitForCompletion();
System.out.println("Release phone number is complete: " + releaseResponse.getStatus());
Parameters:
Returns:
beginReleasePhoneNumber
public SyncPoller<PhoneNumberOperation,ReleasePhoneNumberResult> beginReleasePhoneNumber(String phoneNumber, Context context)
Starts the update of capabilities for a purchased phone number.
This function returns a Long Running Operation poller that allows you to wait indefinitely until the operation is complete.
Code Samples
PollResponse<PhoneNumberOperation> releaseResponse = phoneNumberClient
.beginReleasePhoneNumber("+18001234567", Context.NONE).waitForCompletion();
System.out.println("Release phone number is complete: " + releaseResponse.getStatus());
Parameters:
Returns:
beginReservationPurchase
public SyncPoller<PhoneNumberOperation,PurchaseReservationResult> beginReservationPurchase(String reservationId)
Starts the purchase of all phone numbers in the reservation. Starts a long running operation to purchase all of the phone numbers in the reservation. Purchase can only be started for active reservations that at least one phone number. If any of the phone numbers in the reservation is from a country where reselling is not permitted, do not resell agreement is required. The response will include an 'Operation-Location' header that can be used to query the status of the operation.
Code Samples
PollResponse<PhoneNumberOperation> purchaseResponse =
phoneNumberClient.beginPurchasePhoneNumbers(searchId).waitForCompletion();
System.out.println("Purchase phone numbers is complete: " + purchaseResponse.getStatus());
Parameters:
Returns:
beginReservationPurchase
public SyncPoller<PhoneNumberOperation,PurchaseReservationResult> beginReservationPurchase(String reservationId, Boolean agreeToNotResell)
Starts the purchase of all phone numbers in the reservation. Starts a long running operation to purchase all of the phone numbers in the reservation. Purchase can only be started for active reservations that at least one phone number. If any of the phone numbers in the reservation is from a country where reselling is not permitted, do not resell agreement is required. The response will include an 'Operation-Location' header that can be used to query the status of the operation.
Parameters:
Returns:
beginReservationPurchase
public SyncPoller<PhoneNumberOperation,PurchaseReservationResult> beginReservationPurchase(String reservationId, Boolean agreeToNotResell, Context context)
Starts the purchase of all phone numbers in the reservation. Starts a long running operation to purchase all of the phone numbers in the reservation. Purchase can only be started for active reservations that at least one phone number. If any of the phone numbers in the reservation is from a country where reselling is not permitted, do not resell agreement is required. The response will include an 'Operation-Location' header that can be used to query the status of the operation.
Parameters:
Returns:
beginReservationPurchase
public SyncPoller<PhoneNumberOperation,PurchaseReservationResult> beginReservationPurchase(String reservationId, Context context)
Starts the purchase of all phone numbers in the reservation. Starts a long running operation to purchase all of the phone numbers in the reservation. Purchase can only be started for active reservations that at least one phone number. If any of the phone numbers in the reservation is from a country where reselling is not permitted, do not resell agreement is required. The response will include an 'Operation-Location' header that can be used to query the status of the operation.
Parameters:
Returns:
beginSearchAvailablePhoneNumbers
public SyncPoller<PhoneNumberOperation,PhoneNumberSearchResult> beginSearchAvailablePhoneNumbers(String countryCode, PhoneNumberType phoneNumberType, PhoneNumberAssignmentType assignmentType, PhoneNumberCapabilities capabilities)
Starts the search for available phone numbers to purchase.
This function returns a Long Running Operation poller that allows you to wait indefinitely until the operation is complete.
Code Samples
PhoneNumberCapabilities capabilities = new PhoneNumberCapabilities()
.setCalling(PhoneNumberCapabilityType.INBOUND)
.setSms(PhoneNumberCapabilityType.INBOUND_OUTBOUND);
SyncPoller<PhoneNumberOperation, PhoneNumberSearchResult> poller = phoneNumberClient
.beginSearchAvailablePhoneNumbers("US", PhoneNumberType.TOLL_FREE,
PhoneNumberAssignmentType.APPLICATION, capabilities);
PollResponse<PhoneNumberOperation> response = poller.waitForCompletion();
String searchId = "";
if (LongRunningOperationStatus.SUCCESSFULLY_COMPLETED == response.getStatus()) {
PhoneNumberSearchResult searchResult = poller.getFinalResult();
searchId = searchResult.getSearchId();
System.out.println("Searched phone numbers: " + searchResult.getPhoneNumbers());
System.out.println("Search expires by: " + searchResult.getSearchExpiresBy());
System.out.println("Phone number costs:" + searchResult.getCost().getAmount());
}
Parameters:
Returns:
beginSearchAvailablePhoneNumbers
public SyncPoller<PhoneNumberOperation,PhoneNumberSearchResult> beginSearchAvailablePhoneNumbers(String countryCode, PhoneNumberType phoneNumberType, PhoneNumberAssignmentType assignmentType, PhoneNumberCapabilities capabilities, PhoneNumberSearchOptions searchOptions, Context context)
Starts the search for available phone numbers to purchase.
This function returns a Long Running Operation poller that allows you to wait indefinitely until the operation is complete.
Code Samples
PhoneNumberCapabilities capabilities = new PhoneNumberCapabilities()
.setCalling(PhoneNumberCapabilityType.INBOUND)
.setSms(PhoneNumberCapabilityType.INBOUND_OUTBOUND);
PhoneNumberSearchOptions searchOptions = new PhoneNumberSearchOptions().setAreaCode("800").setQuantity(1);
SyncPoller<PhoneNumberOperation, PhoneNumberSearchResult> poller = phoneNumberClient
.beginSearchAvailablePhoneNumbers("US", PhoneNumberType.TOLL_FREE,
PhoneNumberAssignmentType.APPLICATION, capabilities, searchOptions, Context.NONE);
PollResponse<PhoneNumberOperation> response = poller.waitForCompletion();
String searchId = "";
if (LongRunningOperationStatus.SUCCESSFULLY_COMPLETED == response.getStatus()) {
PhoneNumberSearchResult searchResult = poller.getFinalResult();
searchId = searchResult.getSearchId();
System.out.println("Searched phone numbers: " + searchResult.getPhoneNumbers());
System.out.println("Search expires by: " + searchResult.getSearchExpiresBy());
System.out.println("Phone number costs:" + searchResult.getCost().getAmount());
}
Parameters:
Returns:
beginUpdatePhoneNumberCapabilities
public SyncPoller<PhoneNumberOperation,PurchasedPhoneNumber> beginUpdatePhoneNumberCapabilities(String phoneNumber, PhoneNumberCapabilities capabilities)
Update capabilities of a purchased phone number.
This function returns a Long Running Operation poller that allows you to wait indefinitely until the operation is complete.
Code Samples
PhoneNumberCapabilities capabilities = new PhoneNumberCapabilities();
capabilities
.setCalling(PhoneNumberCapabilityType.INBOUND)
.setSms(PhoneNumberCapabilityType.INBOUND_OUTBOUND);
SyncPoller<PhoneNumberOperation, PurchasedPhoneNumber> poller = phoneNumberClient
.beginUpdatePhoneNumberCapabilities("+18001234567", capabilities);
PollResponse<PhoneNumberOperation> response = poller.waitForCompletion();
if (LongRunningOperationStatus.SUCCESSFULLY_COMPLETED == response.getStatus()) {
PurchasedPhoneNumber phoneNumber = poller.getFinalResult();
System.out.println("Phone Number Calling capabilities: " + phoneNumber.getCapabilities().getCalling());
System.out.println("Phone Number SMS capabilities: " + phoneNumber.getCapabilities().getSms());
}
Parameters:
Returns:
beginUpdatePhoneNumberCapabilities
public SyncPoller<PhoneNumberOperation,PurchasedPhoneNumber> beginUpdatePhoneNumberCapabilities(String phoneNumber, PhoneNumberCapabilities capabilities, Context context)
Update capabilities of a purchased phone number.
This function returns a Long Running Operation poller that allows you to wait indefinitely until the operation is complete.
Code Samples
PhoneNumberCapabilities capabilities = new PhoneNumberCapabilities();
capabilities
.setCalling(PhoneNumberCapabilityType.INBOUND)
.setSms(PhoneNumberCapabilityType.INBOUND_OUTBOUND);
SyncPoller<PhoneNumberOperation, PurchasedPhoneNumber> poller = phoneNumberClient
.beginUpdatePhoneNumberCapabilities("+18001234567", capabilities, Context.NONE);
PollResponse<PhoneNumberOperation> response = poller.waitForCompletion();
if (LongRunningOperationStatus.SUCCESSFULLY_COMPLETED == response.getStatus()) {
PurchasedPhoneNumber phoneNumber = poller.getFinalResult();
System.out.println("Phone Number Calling capabilities: " + phoneNumber.getCapabilities().getCalling());
System.out.println("Phone Number SMS capabilities: " + phoneNumber.getCapabilities().getSms());
}
Parameters:
Returns:
browseAvailableNumbers
public PhoneNumbersBrowseResult browseAvailableNumbers(BrowsePhoneNumbersOptions browsePhoneNumbersOptions)
Browses for available phone numbers to purchase. Browses for available phone numbers to purchase. The response will be a randomized list of phone numbers available to purchase matching the browsing criteria. This operation is not paginated. Since the results are randomized, repeating the same request will not guarantee the same results.
Parameters:
Returns:
browseAvailableNumbersWithResponse
public Response<PhoneNumbersBrowseResult> browseAvailableNumbersWithResponse(BrowsePhoneNumbersOptions browsePhoneNumbersOptions, Context context)
Browses for available phone numbers to purchase. Browses for available phone numbers to purchase. The response will be a randomized list of phone numbers available to purchase matching the browsing criteria. This operation is not paginated. Since the results are randomized, repeating the same request will not guarantee the same results.
Parameters:
Returns:
createOrUpdateReservation
public PhoneNumbersReservation createOrUpdateReservation(CreateOrUpdateReservationOptions reservationOptions)
Updates a reservation by its ID. Adds and removes phone numbers from the reservation with the given ID. The response will be the updated state of the reservation. Phone numbers can be reserved by including them in the payload. If a number is already in the reservation, it will be ignored. To remove a phone number, set it explicitly to null in the request payload. This operation is idempotent. If a reservation with the same ID already exists, it will be updated, otherwise a new one is created. Only reservations with 'active' status can be updated. Updating a reservation will extend the expiration time of the reservation to 15 minutes after the last change, up to a maximum of 2 hours from creation time. Partial success is possible, in which case the response will have a 207 status code.
Parameters:
Returns:
createOrUpdateReservationWithResponse
public Response<PhoneNumbersReservation> createOrUpdateReservationWithResponse(CreateOrUpdateReservationOptions reservationOptions, Context context)
Creates or updates a reservation by its ID. Adds and removes phone numbers from the reservation with the given ID. The response will be the updated state of the reservation. Phone numbers can be reserved by including them in the payload. If a number is already in the reservation, it will be ignored. To remove a phone number, set it explicitly to null in the request payload. This operation is idempotent. If a reservation with the same ID already exists, it will be updated, otherwise a new one is created. Only reservations with 'active' status can be updated. Updating a reservation will extend the expiration time of the reservation to 15 minutes after the last change, up to a maximum of 2 hours from creation time. Partial success is possible, in which case the response will have a 207 status code.
Parameters:
Returns:
deleteReservation
public void deleteReservation(String reservationId)
Deletes a reservation by its ID. Deletes the reservation with the given ID. Any phone number in the reservation will be released and made available for others to purchase. Only reservations with 'active' status can be deleted.
Parameters:
deleteReservationWithResponse
public Response<Void> deleteReservationWithResponse(String reservationId, Context context)
Deletes a reservation by its ID. Deletes the reservation with the given ID. Any phone number in the reservation will be released and made available for others to purchase. Only reservations with 'active' status can be deleted.
Parameters:
Returns:
getPurchasedPhoneNumber
public PurchasedPhoneNumber getPurchasedPhoneNumber(String phoneNumber)
Gets information about a purchased phone number.
Code Samples
PurchasedPhoneNumber phoneNumber = phoneNumberClient.getPurchasedPhoneNumber("+18001234567");
System.out.println("Phone Number Value: " + phoneNumber.getPhoneNumber());
System.out.println("Phone Number Country Code: " + phoneNumber.getCountryCode());
Parameters:
Returns:
getPurchasedPhoneNumberWithResponse
public Response<PurchasedPhoneNumber> getPurchasedPhoneNumberWithResponse(String phoneNumber, Context context)
Gets information about a purchased phone number with response.
Code Samples
Response<PurchasedPhoneNumber> response = phoneNumberClient
.getPurchasedPhoneNumberWithResponse("+18001234567", Context.NONE);
PurchasedPhoneNumber phoneNumber = response.getValue();
System.out.println("Phone Number Value: " + phoneNumber.getPhoneNumber());
System.out.println("Phone Number Country Code: " + phoneNumber.getCountryCode());
Parameters:
Returns:
getReservation
public PhoneNumbersReservation getReservation(String reservationId)
Gets a reservation by its ID. PhoneNumbersReservationInternal internalReservation = client.getReservation(reservationId); return mapToPhoneNumbersReservation(internalReservation); Retrieves the reservation with the given ID, including all of the phone numbers associated with it.
Parameters:
Returns:
getReservationWithResponse
public Response<PhoneNumbersReservation> getReservationWithResponse(String reservationId, Context context)
Gets a reservation by its ID. Retrieves the reservation with the given ID, including all of the phone numbers associated with it.
Parameters:
Returns:
listAvailableCountries
public PagedIterable<PhoneNumberCountry> listAvailableCountries()
Gets the list of the available countries.
Returns:
listAvailableCountries
public PagedIterable<PhoneNumberCountry> listAvailableCountries(Context context)
Gets the list of the purchased phone numbers with context.
Parameters:
Returns:
listAvailableGeographicAreaCodes
public PagedIterable<PhoneNumberAreaCode> listAvailableGeographicAreaCodes(String countryCode, PhoneNumberAssignmentType assignmentType, String locality, String administrativeDivision)
Gets the list of the available Geographic area codes for a given country and locality.
Parameters:
Returns:
listAvailableGeographicAreaCodes
public PagedIterable<PhoneNumberAreaCode> listAvailableGeographicAreaCodes(String countryCode, PhoneNumberAssignmentType assignmentType, String locality, String administrativeDivision, Context context)
Gets the list of the available Geographic area codes for a given country and locality.
Parameters:
Returns:
listAvailableLocalities
public PagedIterable<PhoneNumberLocality> listAvailableLocalities(String countryCode, String administrativeDivision)
Gets the list of the available localities. I.e. cities, towns.
Parameters:
Returns:
listAvailableLocalities
public PagedIterable<PhoneNumberLocality> listAvailableLocalities(String countryCode, String administrativeDivision, Context context)
Gets the list of the available localities. I.e. cities, towns.
Parameters:
Returns:
listAvailableLocalities
public PagedIterable<PhoneNumberLocality> listAvailableLocalities(String countryCode, String administrativeDivision, PhoneNumberType phoneNumberType)
Gets the list of the available localities. I.e. cities, towns.
Parameters:
Returns:
listAvailableLocalities
public PagedIterable<PhoneNumberLocality> listAvailableLocalities(String countryCode, String administrativeDivision, PhoneNumberType phoneNumberType, Context context)
Gets the list of the available localities. I.e. cities, towns.
Parameters:
Returns:
listAvailableMobileAreaCodes
public PagedIterable<PhoneNumberAreaCode> listAvailableMobileAreaCodes(String countryCode, PhoneNumberAssignmentType assignmentType, String locality)
Gets the list of the available Mobile area codes for a given country and locality.
Parameters:
Returns:
listAvailableMobileAreaCodes
public PagedIterable<PhoneNumberAreaCode> listAvailableMobileAreaCodes(String countryCode, PhoneNumberAssignmentType assignmentType, String locality, Context context)
Gets the list of the available Mobile area codes for a given country and locality.
Parameters:
Returns:
listAvailableOfferings
public PagedIterable<PhoneNumberOffering> listAvailableOfferings(String countryCode, PhoneNumberType phoneNumberType, PhoneNumberAssignmentType assignmentType)
Gets the list of the available phone number offerings for the given country.
Parameters:
Returns:
listAvailableOfferings
public PagedIterable<PhoneNumberOffering> listAvailableOfferings(String countryCode, PhoneNumberType phoneNumberType, PhoneNumberAssignmentType assignmentType, Context context)
Gets the list of the available phone number offerings for the given country.
Parameters:
Returns:
listAvailableTollFreeAreaCodes
public PagedIterable<PhoneNumberAreaCode> listAvailableTollFreeAreaCodes(String countryCode)
Gets the list of the available Toll-Free area codes for a given country.
Parameters:
Returns:
listAvailableTollFreeAreaCodes
public PagedIterable<PhoneNumberAreaCode> listAvailableTollFreeAreaCodes(String countryCode, Context context)
Gets the list of the available Toll-Free area codes for a given country.
Parameters:
Returns:
listPurchasedPhoneNumbers
public PagedIterable<PurchasedPhoneNumber> listPurchasedPhoneNumbers()
Gets the list of the purchased phone numbers.
Code Samples
PagedIterable<PurchasedPhoneNumber> phoneNumbers = phoneNumberClient.listPurchasedPhoneNumbers();
PurchasedPhoneNumber phoneNumber = phoneNumbers.iterator().next();
System.out.println("Phone Number Value: " + phoneNumber.getPhoneNumber());
System.out.println("Phone Number Country Code: " + phoneNumber.getCountryCode());
Returns:
listPurchasedPhoneNumbers
public PagedIterable<PurchasedPhoneNumber> listPurchasedPhoneNumbers(Context context)
Gets the list of the purchased phone numbers with context.
Code Samples
PagedIterable<PurchasedPhoneNumber> phoneNumbers = phoneNumberClient.listPurchasedPhoneNumbers(Context.NONE);
PurchasedPhoneNumber phoneNumber = phoneNumbers.iterator().next();
System.out.println("Phone Number Value: " + phoneNumber.getPhoneNumber());
System.out.println("Phone Number Country Code: " + phoneNumber.getCountryCode());
Parameters:
Returns:
listReservations
public PagedIterable<PhoneNumbersReservation> listReservations()
Lists all reservations. Retrieves a paginated list of all phone number reservations. Note that the reservations will not be populated with the phone numbers associated with them.
Returns:
listReservations
public PagedIterable<PhoneNumbersReservation> listReservations(Integer maxPageSize)
Lists all reservations. Retrieves a paginated list of all phone number reservations. Note that the reservations will not be populated with the phone numbers associated with them.
Parameters:
Returns:
listReservations
public PagedIterable<PhoneNumbersReservation> listReservations(Integer maxPageSize, Context context)
Lists all reservations. Retrieves a paginated list of all phone number reservations. Note that the reservations will not be populated with the phone numbers associated with them.
Parameters:
Returns:
searchOperatorInformation
public OperatorInformationResult searchOperatorInformation(List<String> phoneNumbers)
Searches for operator information for a given list of phone numbers.
Parameters:
Returns:
searchOperatorInformationWithResponse
public Response<OperatorInformationResult> searchOperatorInformationWithResponse(List<String> phoneNumbers, OperatorInformationOptions requestOptions, Context context)
Searches for operator information for a given list of phone numbers.
Parameters:
Returns: