Report a Phone Call verification code with .NET 6.0
Now that you've initiated a verification request and received a code, it's time to report that code in order to verify the identity of the user.
In this guide you will learn:
What you need to know before you start
Before you can get started, you need the following already set up:
- Set all Verification API configuration settings.
- ASP.NET Core 6.0 or later SDK and ASP.NET Core Runtime and a familiarity with how to create an app.
- A mobile handset that can receive calls.
Set up your ASP.NET Core 6.0 application
Create a new project folder and open a command prompt. Execute the following command to create a new ASP.NET Core 6.0 console application:
dotnet new console
This creates a new console application and project.
Modify your application
In your project folder, open theProgram.cs
file and paste the provided "Program.cs" code into the file, replacing all the existing content.This code makes a PUT request to the Verification API /verifications/number endpoint which uses the _to
parameter to verify that a code sent to that number is valid.Fill in your parameters
Before you can run the code, you need to update some values so you can connect to your Sinch account. Update the following parameters with your own values:
Parameter | Your value |
---|---|
_key | The application key found on your Sinch dashboard. |
_secret | The application secret found on your Sinch dashboard. |
_to | This should be the number of the mobile handset you are using for this guide. |
_code | This is the code which was received by the mobile handset in the initiate verification guide. These codes are only valid for 10 minutes, so ensure you have initiated a verification within the last ten minutes so you can successfully match the code! |
Note:
When your account is in trial mode, you can only call your verified numbers. If you want to call any number, you need to upgrade your account!
Save the file.
Report your verification request
Now you can execute the code and report your verification code. Run the following command:
dotnet run
If the code was correct, your console will show a success result in the response from Sinch. You can test this by entering an incorrect code and seeing the failed result response.
Troubleshooting tip
If after running your app you receive a 5000 error response, you may have forgotten to save your file after adding your authentication values. This is an easy mistake to make! Try saving the file and running the app again.