Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Jira Invoke-RestMethod PowerShell 400 Bad Request

Wes Brown
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 2, 2025

Have tried the $body_json output in Postman to grab the json data and the Jira is created without issue using the bearer token. I am also able to view a jira using the $headers variable which shows me my authorization is fine. I've tried different error capture methods and all I get back is 400 Bad Status and "ScriptStackTrace : at <ScriptBlock>, <No file>: line 2". I'm not even sure what that means. I've scoured these forums and google and am getting nowhere. Any assistance is much appreciated. Trying to avoid JiraPS module in favor of Invoke-RestMethod for future supportability.

 

$headers = @{

Authorization = "Bearer mytoken"

"Content-Type" = "application/json"

}

$restapiuri = "https://jira.mydomain.com/rest/api/2/issue"

$body = @{

    fields = @{

        reporter = @{

            name = "myname"

        }            

        project = @{

            key = "IT"

        }

        issuetype = @{

            name = "Task"

        }

        summary = "Test Issue 2"

        description = "Detailed description of the issue"

components = @(

            @{name = "MyTeam"}

        )

     }

}

$body_json = $body | ConvertTo-Json -Depth 5

Try{

Invoke-RestMethod -Uri $restapiuri -Method POST -Body $body_json -Headers $headers

 }

Catch {

    Write-Host "StatusCode:" $_.Exception.Response.StatusCode.value__ 

    Write-Host "StatusDescription:" $_.Exception.Response.StatusDescription

    }

 

Here's the json from $body_json



{
"fields": {
"issuetype": {
"name": "Task"
},
"description": "Detailed description of the issue",
"reporter": {
"name": "myusername"
},
"summary": "Test Issue 2",
"components": [
{
"name": "myteam"
}
],
"project": {
"key": "IT"
}
}
}

 This returned (201) created in Postman and I verified the Jira was created.

0 answers

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events