# Send a fax with ASP.NET You can quickly see how the Fax API works by sending yourself a fax using the Fax API. In this guide you will learn: 1. How to [set up](#set-up-your-aspnet-core-60-application) your ASP.NET console application. 2. How to [send](#send-your-first-fax) a fax to your phone number. ## What you need to know before you start Before you can get started, you need the following already set up: * Set all Fax API [configuration settings](/docs/fax/getting-started). * [ASP.NET 6.0](https://dotnet.microsoft.com/en-us/download/dotnet/6.0) or later SDK and ASP.NET Runtime and a familiarity with how to create an app. ## Set up your ASP.NET application Create a new project folder and open a command prompt. Execute the following command to create a new ASP.NET console application: ```shell dotnet new console ``` This creates a new console application and project. ## Modify your application 1. Open the `Program.cs` file in your project folder. Replace everything in the file with the following code: ```csharp Fax fax = new Fax("to_number", "YOUR_content_url", "YOUR_callback_url"}); sms.sendFax(fax, "YOUR_project_id", "YOUR_access_key", "YOUR_access_secret"); Console.ReadLine(); ``` 1. Next, create a new file in the project folder named `Fax.cs`. Populate that file with the "Fax.cs" code found on this page. Fax.cs using System.Text; using Newtonsoft.Json; public class Fax { public string to { get; set; } public string url { get; set; } public string callbackUrl { get; set; } public Fax(string to, string url, string callbackUrl) { this.to = to; this.url = url; this.callbackUrl = callbackUrl; } public async void sendFax(Fax fax, string projectId, string accessKey, string accessSecret) { using (var client = new HttpClient()) { var base64String = Convert.ToBase64String(Encoding.ASCII.GetBytes(accessKey + ":" + accessSecret)); client.DefaultRequestHeaders.Add("Authorization", "Basic "+ base64String); string json = JsonConvert.SerializeObject(fax); var postData = new StringContent(json, Encoding.UTF8, "application/json"); var request = await client.PostAsync("https://fax.api.sinch.com/v3/projects/" + projectId + "/faxes", postData); var response = await request.Content.ReadAsStringAsync(); Console.WriteLine(response); } } } This code sends a fax to a specified number using the Sinch Fax API. ### To In this example you want to fax a phone number. Change the value of the `to_number` parameter to the phone number you verified in your [dashboard](https://dashboard.sinch.com) in [E.164](https://community.sinch.com/t5/Glossary/E-164/ta-p/7537) format. Note: When your account is in trial mode, you can only send a fax to your [verified numbers](https://dashboard.sinch.com/numbers/verified-numbers). If you want to fax any number, you need to upgrade your account! ### Content URL The Fax API can send either files directly or the URL of a web page or other online [resource](/docs/fax/api-reference/filetypes). For the purposes of this tutorial, use a web page because it's the easiest way to get started. Change the value of `YOUR_content_url` to the URL of the web page. Note: You can use any URL on the Internet (including ones with basic authentication), and we'll pull it down and make it a fax. This might be useful to you if you're using a web framework for templates and creating fax files. If you are passing fax a secure URL (starting with `https://`), make sure that your SSL certificate (including your intermediate cert, if you have one) is installed properly, valid, and up-to-date. ### Callback URL If you provide a callback URL on your Fax service, the Fax API can send [notification events](/docs/fax/api-reference/fax/notifications/) to your server about your outgoing fax, such as when or if the fax was delivered. You can set that callback URL in your request body. Change the value of `YOUR_callback_url` to the URL of your server that's listening to incoming requests. ### Fill in your parameters Before you can run the code, you need to update some more values in the `Program.cs` file so you can connect to your Sinch account. Update the following parameters with your own values: | Parameter | Your value | | --- | --- | | `YOUR_project_id` | The project ID found on your Sinch [dashboard](https://stagingdashboard.sinch.com/settings/access-keys). | | `YOUR_access_key` | The access key found on your Sinch [dashboard](https://stagingdashboard.sinch.com/settings/access-keys). | | `YOUR_access_secret` | The access secret found on your Sinch [dashboard](https://stagingdashboard.sinch.com/settings/access-keys). **Note:** Access secrets are only available during initial key creation. | Save the file. ## Build your project Before executing your code, you must first compile your application. Execute the following command: ```shell dotnet build ``` ## Send your first fax Now you can execute the code and send your fax. Run the following command: ```shell dotnet run ``` You should receive a fax to the number you specified with the web page that you configured. 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. ## Additional resources - [API specification](/docs/fax/api-reference/fax)