title: Authorizing an Azure REST API Request
body: <p>I am trying to write a local console application which will swap an Azure Web App slot using the <a href="https://docs.microsoft.com/en-us/rest/api/" rel="nofollow noreferrer">Azure REST API</a>. Using the following code I get a 401 (Unauthorized) response:</p>
  
  <pre><code>public async Task Swap(string subscription, string resourceGroup, string site, string slot) 
  {
      var client = new HttpClient();
  
      var url =
          $"https://management.azure.com/subscriptions/{subscription}/resourceGroups/{resourceGroup}/providers/Microsoft.Web/sites/{site}/applySlotConfig?api-version=2016-08-01";
  
      var data = new {preserveVnet = true, targetSlot = slot};
  
      var message = new HttpRequestMessage
      {
          RequestUri = new Uri(url),
          Method = HttpMethod.Post,
          Content = new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json")
      };
  
      var response = await client.SendAsync(message);
  
      Console.WriteLine(response.StatusCode);
  } 
  </code></pre>
  
  <p>I know I need to put in some kind of credentials but what I have found seems to apply to apps using Azure AD for authentication. This will be a publicly accessible web app with anonymous authentication.</p>