title: Consume a Web API using a .Net Client App
body: <p>I have been following some tutorials (e.g., <a href="https://docs.microsoft.com/en-us/aspnet/web-api/overview/advanced/calling-a-web-api-from-a-net-client" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/aspnet/web-api/overview/advanced/calling-a-web-api-from-a-net-client</a>) and trying to retrieve a list of jobs and print them out in my .Net console app.</p>
  
  <p>The test data I am using is located at <a href="https://boards-api.greenhouse.io/v1/boards/vaulttec/jobs" rel="nofollow noreferrer">https://boards-api.greenhouse.io/v1/boards/vaulttec/jobs</a> and supplied it to <strong><code>client.BaseAddress</code></strong>.</p>
  
  <p>Since I am able to compile and run the tutorial succesfully, I simply used the same code and changed some of it to run the above test data (see below).</p>
  
  <pre><code>using System;
  using System.Net;
  using System.Net.Http;
  using System.Net.Http.Headers;
  using System.Threading.Tasks;
  
  namespace GreenhouseJobs
  {
  public class Job
  {
      public string Id { get; set; }
      public string Title { get; set; }
      public string Location { get; set; }
      public DateTime LastUpdated { get; set; }
  }
  
  class GreenhouseJobsClient
  {
      static HttpClient client = new HttpClient();
  
      static void ShowJob(Job job)
      {
          Console.WriteLine($"Id: {job.Id}\tTitle: " +
              $"{job.Title}\tLocation: {job.Location}\tLast Updated: {job.LastUpdated}");
      }
  
      static async Task&lt;Uri&gt; CreateJobAsync(Job job)
      {
          HttpResponseMessage response = await client.PostAsJsonAsync(
              "vaulttec/jobs", job);
          response.EnsureSuccessStatusCode();
  
          // return URI of the created resource.
          return response.Headers.Location;
      }
  
      static async Task&lt;Job&gt; GetJobAsync(string path)
      {
          Job job = null;
          HttpResponseMessage response = await client.GetAsync(path);
          if (response.IsSuccessStatusCode)
          {
              job = await response.Content.ReadAsAsync&lt;Job&gt;();
          }
          return job;
      }
  
      //static async Task&lt;Product&gt; UpdateProductAsync(Product product)
      //{
      //    HttpResponseMessage response = await client.PutAsJsonAsync(
      //        $"api/products/{product.Id}", product);
      //    response.EnsureSuccessStatusCode();
  
      //    // Deserialize the updated product from the response body.
      //    product = await response.Content.ReadAsAsync&lt;Product&gt;();
      //    return product;
      //}
  
      //static async Task&lt;HttpStatusCode&gt; DeleteProductAsync(string id)
      //{
      //    HttpResponseMessage response = await client.DeleteAsync(
      //        $"api/products/{id}");
      //    return response.StatusCode;
      //}
  
      static void Main()
      {
          RunAsync().GetAwaiter().GetResult();
          Console.ReadLine();
      }
  
      static async Task RunAsync()
      {
          // Update port # in the following line.
          client.BaseAddress = new Uri("https://boards-api.greenhouse.io/v1/boards/");
          client.DefaultRequestHeaders.Accept.Clear();
          client.DefaultRequestHeaders.Accept.Add(
              new MediaTypeWithQualityHeaderValue("application/json"));
  
          try
          {
              // Create a new product
              Job job = new Job
              {
                  Id = "323232",
                  Title = "Test",
                  Location = "Test",
                  LastUpdated = DateTime.Now
              };
  
              var url = await CreateJobAsync(job);
              Console.WriteLine($"Created at {url}");
  
              // Get the product
              job = await GetJobAsync(url.PathAndQuery);
              ShowJob(job);
  
              // Update the product
              //Console.WriteLine("Updating price...");
              //product.Price = 80;
              //await UpdateProductAsync(product);
  
              // Get the updated product
              //product = await GetProductAsync(url.PathAndQuery);
              //ShowProduct(product);
  
              // Delete the product
              //var statusCode = await DeleteProductAsync(product.Id);
              //Console.WriteLine($"Deleted (HTTP Status = {(int)statusCode})");
  
          }
          catch (Exception e)
          {
              Console.WriteLine(e.Message);
          }
  
          Console.ReadLine();
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>The problem is, when I run the app, it does not return anything. Error message: "Response status code does not indicate success: 404 (Not Found)".</p>