Search for a virtual number using .NET
Use this guide to create a .NET application for use with the Numbers API and search for an available Sinch virtual number.
Note:
Before you can get started, you need the following already set up:
- All Numbers API prerequisite steps.
- .NET 6.0 SDK or later and a familiarity with how to create a new app.
Steps:
- Set up your .NET Core application.
- Search for an available virtual number for SMS, Voice or both.
Set up your .NET application
- Create a new folder where you want your app project. Then, open a terminal or command prompt to that location.
- Create a new .NET console app with the following command:
dotnet new console
- Add the
Newtonsoft.Json
nuget package.dotnet add package Newtonsoft.Json
Modify your application
- Open the
Program.cs
file in your project folder. Replace all of the code with the "Search for a virtual number" code. - Save the file.
Search for an available virtual number
Fill in your parameters
- Replace the following values in the
Program.cs
file:
Parameter | Your value |
---|---|
YOUR_username | your client_id or key_id found in the Sinch Sinch Customer Dashboard. |
YOUR_password | Your client_secret or key_secret . This is generated upon new key creation. Generate a new key if you have lost your secret key. |
YOUR_ProjectID | The project ID found in the Customer Dashboard. |
regionCode | The two letter abbreviation of the country for which you'd like a number. ISO 3166–1 alpha–2. |
type | The type of number you would like to rent. Available options are: MOBILE , LOCAL , or TOLL_FREE . Note that 10DLC numbers should be set to LOCAL . |
- Save the file.
Build and run your project
- Before executing your code, you must first compile your application. Execute the following command:
dotnet build
- Now you can execute the code. Run the following command:
dotnet run
Response
These steps should return a JSON list of numbers available to rent.
{
"availableNumbers": [
{
"phoneNumber": "+12089087284",
"regionCode": "US",
"type": "LOCAL",
"capability": ["SMS"],
"setupPrice": {
"currencyCode": "USD",
"amount": "0.00"
},
"monthlyPrice": {
"currencyCode": "USD",
"amount": "2.00"
},
"paymentIntervalMonths": 1
}
]
}
Next steps
Copy thephoneNumber
you would like to use and rent your virtual number using the Numbers API.Additional resources
- Explore the API specification to test more endpoints.
- Prefer a UI to search for a number? Follow the entire number searching and renting process in the Customer Dashboard.