title: Powershell v5.1 Invoke-RestMethod Error Parsing Body
body: <p>I'm a beginner with Powershell who's trying to send a PUT request to Microsoft Azure to create an Application Insights log query. I'm able to get this working in Postman, but not in a powershell script. This is the error that I'm getting when running the script:</p>
  <p><strong>Invoke-RestMethod : {&quot;code&quot;:&quot;Unexpected character encountered while parsing value: S. Path '', line 0, position 0.&quot;,&quot;message&quot;:&quot;Unexpected character encountered while parsing value: S. Path '', line 0, position 0.&quot;,&quot;innererror&quot;:{&quot;diagnosticcontext&quot;:&quot;f2843c54-dad7-49b5-92ab-e1dadd40e145&quot;,&quot;time&quot;:&quot;2020-07-24T19:59:45.7979293Z&quot;}}</strong><br/>
  <strong>At C:\Users\thophan\source\Update-AiLogQueries.ps1:58 char:9</strong><br/>
  <strong>+         Invoke-RestMethod -Method Put -Uri $uri -Header $header -Body ...</strong><br/>
  <strong>+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</strong><br/>
  <strong>+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException</strong><br/>
  <strong>+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand</strong><br/></p>
  <p>From looking at the Microsoft documentation, it looks like it's supposed to be able to take in a hashtable for the body, and I'm quite certain my syntax looks exactly the same as the one from the exameple, so I'm not sure what's going on. Below is an excerpt from my script:</p>
  <pre><code>$scope = &quot;shared&quot;
  $header = @{
      &quot;Authorization&quot; = &quot;Bearer $token&quot;
  }
  $uri = &quot;https://management.azure.com/subscriptions/$subscriptionId/resourceGroups/$rgName/providers/microsoft.insights/components/$aiName/analyticsItems/item?api-version=2020-02-02-preview&quot;
  $difference = Compare-Object -ReferenceObject $localQueryList.value -DifferenceObject $response
  if ($difference -ne $null)
  {
      $difference.ForEach(
      {
          $body = @{
              Scope = $scope
              Type = &quot;query&quot;
              Name = $_.InputObject.Name
              Content = $_.InputObject.Content
          }
  
          Invoke-RestMethod -Method Put -Uri $uri -Header $header -Body $body
      })
  }
  </code></pre>
  <p>UPDATE: Here is the documentation that I was looking at, as requested.
  <a href="https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-restmethod?view=powershell-5.1" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-restmethod?view=powershell-5.1</a></p>