Preface:
I am very new to Powershell and webrequests. I may miss something very obvious, or have not understood the solutions others have posted in questions about similar issues.
Purpose:
Access to our Atlassian instance is controlled through groups in Azure AD.
I have a small script that will create a group for a new project or Confluence space in AAD.
I want to extend this script to also create the new project/space, and have a "one stop shop" script.
I want this to work in Powershell, in order to simplify the excecution of scripts for those who will be using it.
Code:
$user = [System.Text.Encoding]::UTF8.GetBytes("MY-EMAIL:MY-TOKEN")
$headers =@{
Authorization="Basic " + [System.Convert]::ToBase64String($user)
Accept="application/json"
}
$projectTypeKey = "service_desk"
$projectTemplateKey = "com.atlassian.servicedesk:itil-v2-service-desk-project"
$Projectname = "Ninja Project"
$body =@{
"key" = $key
"name" = $ProjectName
"leadId" = "MY-ID"
"projectTypeKey" = $projectTypeKey
"projectTemplateKey" = $projectTemplateKey
}
$uri = "https://MYSITE.atlassian.net/rest/api/3/project"
Invoke-RestMethod -Uri $uri -Method POST -Headers $headers -Body $body -ContentType "application/json"
Error:
Invoke-RestMethod: {"statusCode":500,"message":"org.codehaus.jackson.JsonParseException: Unexpected character ('k' (code 107)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')\n at [Source: org.apache.catalina.connector.CoyoteInputStream@1c316782; line: 1, column: 2]"}
Additional info:
The unexpected character changes from time to time, and has shown as "('p' (code 112))".
I cannot force the unexpected character to change, but trying in Powershell ISE, Powershell 7, and Visual Studio Code (With PS 7.1) will often give a different unexpected character.
The unexpected character remains constant in the three different environments, but will differ between them.
The POST request works just fine in Postman.