Package: azure-communication-administration
Azure Communication Administration Package client library for PythonThis package has been deprecated. Please useazure-communication-identityandazure-communication-phonenumbersinstead.The requested features were implemented in the new libraries. See change log for more details.Getting startedPrerequisitesPython 2.7, or 3.5 or later is required to use this package.You must have anAzure subscriptionInstall the packageInstall the Azure Communication Administration client library for Python withpip:pipinstallazure-communication-administrationKey conceptsCommunicationIdentityClientCommunicationIdentityClientprovides operations for:Create/delete identities to be used in Azure Communication Services. Those identities can be used to make use of Azure Communication offerings and can be scoped to have limited abilities through token scopes.Create/revoke scoped user access tokens to access services such as chat, calling, sms. Tokens are issued for a valid Azure Communication identity and can be revoked at any time.CommunicationPhoneNumberClientInitializing Phone Number Client# You can find your endpoint and access token from your resource in the Azure Portalimportosfromazure.communication.administrationimportPhoneNumberAdministrationClientconnection_str=os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING')phone_number_administration_client=PhoneNumberAdministrationClient.from_connection_string(connection_str)Phone plans overviewPhone plans come in two types; Geographic and Toll-Free. Geographic phone plans are phone plans associated with a location, whose phone numbers' area codes are associated with the area code of a geographic location. Toll-Free phone plans are phone plans not associated location. For example, in the US, toll-free numbers can come with area codes such as 800 or 888.All geographic phone plans within the same country are grouped into a phone plan group with a Geographic phone number type. All Toll-Free phone plans within the same country are grouped into a phone plan group.Searching and Acquiring numbersPhone numbers search can be search through the search creation API by providing a phone plan id, an area code and quantity of phone numbers. The provided quantity of phone numbers will be reserved for ten minutes. This search of phone numbers can either be cancelled or purchased. If the search is cancelled, then the phone numbers will become available to others. If the search is purchased, then the phone numbers are acquired for the Azure resources.Configuring / Assigning numbersPhone numbers can be assigned to a callback URL via the configure number API. As part of the configuration, you will need an acquired phone number, callback URL and application id.ExamplesThe following section provides several code snippets covering some of the most common Azure Communication Services tasks, including:Create/delete Azure Communication Service identitiesCreate/revoke scoped user access tokensCommunication Phone numberGet Countriesphone_number_administration_client=PhoneNumberAdministrationClient.from_connection_string(connection_str)supported_countries=phone_number_administration_client.list_all_supported_countries()forsupported_countryinsupported_countries:print(supported_country)Get Phone Plan GroupsPhone plan groups come in two types, Geographic and Toll-Free.phone_number_administration_client=PhoneNumberAdministrationClient.from_connection_string(connection_str)phone_plan_groups_response=phone_number_administration_client.list_phone_plan_groups(country_code='<country code>')forphone_plan_groupinphone_plan_groups_response:print(phone_plan_group)Get Phone PlansUnlike Toll-Free phone plans, area codes for Geographic Phone Plans are empty. Area codes are found in the Area Codes API.phone_number_administration_client=PhoneNumberAdministrationClient.from_connection_string(connection_str)phone_plans_response=phone_number_administration_client.list_phone_plans(country_code='<country code>',phone_plan_group_id='<phone plan group id>')forphone_planinphone_plans_response:print(phone_plan)Get Location OptionsFor Geographic phone plans, you can query the available geographic locations. The locations options are structured like the geographic hierarchy of a country. For example, the US has states and within each state are cities.phone_number_administration_client=PhoneNumberAdministrationClient.from_connection_string(connection_str)location_options_response=phone_number_administration_client.get_phone_plan_location_options(country_code='<country code>',phone_plan_group_id='<phone plan group id>',phone_plan_id='<phone plan id>')print(location_options_response)Get Area CodesFetching area codes for geographic phone plans will require the the location options queries set. You must include the chain of geographic locations traversing down the location options object returned by the GetLocationOptions API.phone_number_administration_client=PhoneNumberAdministrationClient.from_connection_string(connection_str)all_area_codes=phone_number_administration_client.get_all_area_codes(location_type="NotRequired",country_code='<country code>',phone_plan_id='<phone plan id>')print(all_area_codes)Create Searchfromazure.communication.administrationimportCreateSearchOptionsphone_number_administration_client=PhoneNumberAdministrationClient.from_connection_string(connection_str)searchOptions=CreateSearchOptions(area_code='<area code>',description="testsearch20200014",display_name="testsearch20200014",phone_plan_ids=['<phone plan id>'],quantity=1)search_response=phone_number_administration_client.create_search(body=searchOptions)print(search_response)Get search by idphone_number_administration_client=PhoneNumberAdministrationClient.from_connection_string(connection_str)phone_number_search_response=phone_number_administration_client.get_search_by_id(search_id='<search id>')print(phone_number_search_response)Purchase Searchphone_number_administration_client=PhoneNumberAdministrationClient.from_connection_string(connection_str)phone_number_administration_client.purchase_search(search_id='<search id to purchase>')TroubleshootingThe Azure Communication Service Identity client will raise exceptions defined inAzure Core.Next stepsMore sample codePlease take a look at thesamplesdirectory for detailed examples of how to use this library to manage identities and tokens.Provide FeedbackIf you encounter any bugs or have suggestions, please file an issue in theIssuessection of the projectContributingThis project welcomes contributions and suggestions.  Most contributions require you to agree to a
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visithttps://cla.microsoft.com.When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the
PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.This project has adopted theMicrosoft Open Source Code of Conduct.
For more information see theCode of Conduct FAQor contactopencode@microsoft.comwith any additional questions or comments.