title: Invoke-RestMethod - how to pass "ETag does not represent the latest state of the resource."
body: <h3>Question</h3>
  
  <p>How to pass the exception having the following message?</p>
  
  <blockquote>
    <p>Invoke-RestMethod : {"Message":"ETag does not represent the latest state of the resource."}</p>
  </blockquote>
  
  <p>Seeing the <a href="https://github.com/projectkudu/kudu/wiki/REST-API" rel="nofollow noreferrer">reference</a>, I think "passing <code>If-Match: "*" header</code>" should be a key, but don't know how to do this. </p>
  
  <blockquote>
    <p>Note: when updating or deleting a file, ETag behavior will apply. You can pass a If-Match: "*" header to disable the ETag check.</p>
  </blockquote>
  
  <h3>To do</h3>
  
  <ul>
  <li>Putting the file "sample1.html" to specific directory of the website</li>
  <li>In a Runbook of Azure Automation account</li>
  </ul>
  
  <hr>
  
  <h3>Code</h3>
  
  <pre><code># Kudu auth information creation
  $WebSiteName = Get-AutomationVariable -Name 'WebApps_name'
  # Example: "WebApps04"
  $username = Get-AutomationVariable -Name 'WebApps_deploy_username'
  $password = Get-AutomationVariable -Name 'WebApps_deploy_password'
  # Above are set by "Asset - Variable" of in Azure Automation account
  
  $base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username,$password)))
  $userAgent = "powershell/1.0"
  
  # Add-content dummy HTML file
  $Filename = "sample1.html"
  $a = "&lt;HTML&gt;&lt;BODY&gt;Sample HTML Data " + $WebSiteName + "&lt;/BODY&gt;&lt;/HTML&gt;"
  $a | add-content $Filename
  
  # Get-Content full path of HTML file
  $b = get-content $Filename
  $filepath = ($b).PSPath
  
  # PUT HTML file $filepath as $Filename, by Kudu REST API
  $apiUrl = "https://" + $WebSiteName + ".scm.azurewebsites.net/api/vfs/site/wwwroot/" + $Filename
  Write-Output "putting ..."
  
  Invoke-RestMethod `
      -Uri $apiUrl `
      -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} `
      -UserAgent $userAgent `
      -Method PUT `
      -InFile $filePath `
      -ContentType "text/html"
  
  Write-Output "This run is finished."
  </code></pre>
  
  <hr>
  
  <h3>Output</h3>
  
  <pre><code>putting ...
  
  Invoke-RestMethod : {"Message":"ETag does not represent the latest state of the resource."}
  At line:30 char:1
  + Invoke-RestMethod `
  + ~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], 
  WebException
      + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
  
  This run is finished.
  </code></pre>