title: Create JIRA Issue with REST API via PowerShell
body: <p>I'm trying to create a JIRA issue via Powershell.</p>
  
  <p>Here's my code.</p>
  
  <pre><code>function ConvertTo-Base64($string) {
  $bytes  = [System.Text.Encoding]::UTF8.GetBytes($string);
  $encoded = [System.Convert]::ToBase64String($bytes);
  return $encoded;
  }
  
  function Get-HttpBasicHeader([string]$username, [string]$password, $Headers = @{}) {
      $b64 = ConvertTo-Base64 "$($username):$($Password)"
      $Headers["Authorization"] = "Basic $b64"
      $Headers["X-Atlassian-Token"] = "nocheck"
      return $Headers
  }
  
  $restapiuri = "https://baseurl/rest/api/2/issue/"
  $headers = Get-HttpBasicHeader "user" "password"
  
  $body = ('
  {
      "fields":
      {
          "project":
          {
              "id": "10402"
          },
  
          "summary": "Test",
  
          "description": "Test",
  
          "duedate": "2019-05-11",
  
          "issuetype":
          {
              "id": "3"
          },
  
          "reporter":
          {
              "name": "user"
          },
  
          "priority":
          {
              "id": "10101"
          },
  
          "customfield_11403": "Test",
  
          "security":
          {
              "id": "11213"
          },
  
          "components":
          [
              {           
                  "id": "10805"
              }
          ]
      }
  }')
  
  Invoke-RestMethod -uri $restapiuri -Headers $headers -Method POST -ContentType "application/json" -Body $body
  </code></pre>
  
  <p>The JSON part of it runs fine as I've tried it using Postman and the issue got created.</p>
  
  <p>In Powershell however, I always get a 400 bad request returned. Does anyone got any ideas why this might be?</p>
  
  <p>Thanks!</p>
  
  <p>EDIT: code sample according to answer</p>
  
  <pre><code>$body = @{
  
      "fields" = @{
  
          "project" = @{
  
              "id" = "10402";
          }
  
          "summary" = "Test";
  
          "description" = "Test";
  
          "duedate" = "2019-05-11";
  
          "issuetype" = @{
  
              "id" = "3";
          }
  
          "reporter" = @{
  
              "name" = "user";
          }
  
          "priority" = @{
  
              "id" = "10101";
          }
  
          "customfield_11403" = "Test";
  
          "security" = @{
  
              "id" = "11213";
          }
      }
  }
  </code></pre>