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
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
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
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
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:
beginSearchAvailablePhoneNumbers
public SyncPoller
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
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
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
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:
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
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:
listAvailableCountries
public PagedIterable
Gets the list of the available countries.
Returns:
listAvailableCountries
public PagedIterable
Gets the list of the purchased phone numbers with context.
Parameters:
Returns:
listAvailableGeographicAreaCodes
public PagedIterable
Gets the list of the available Geographic area codes for a given country and locality.
Parameters:
Returns:
listAvailableGeographicAreaCodes
public PagedIterable
Gets the list of the available Geographic area codes for a given country and locality.
Parameters:
Returns:
listAvailableLocalities
public PagedIterable
Gets the list of the available localities. I.e. cities, towns.
Parameters:
Returns:
listAvailableLocalities
public PagedIterable
Gets the list of the available localities. I.e. cities, towns.
Parameters:
Returns:
listAvailableOfferings
public PagedIterable
Gets the list of the available phone number offerings for the given country.
Parameters:
Returns:
listAvailableOfferings
public PagedIterable
Gets the list of the available phone number offerings for the given country.
Parameters:
Returns:
listAvailableTollFreeAreaCodes
public PagedIterable
Gets the list of the available Toll-Free area codes for a given country.
Parameters:
Returns:
listAvailableTollFreeAreaCodes
public PagedIterable
Gets the list of the available Toll-Free area codes for a given country.
Parameters:
Returns:
listPurchasedPhoneNumbers
public PagedIterable
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
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:
Applies to
Azure SDK for Java
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for