Query an API with PowerShell for Issue Limit

Jason Krewson
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 13, 2024

I am looking to query a Jira API with PowerShell to get the worklog amount for all issues, this is basically to understand what issues are getting close to the 10,000 worklog limit that starts in December. 

Below is the curl I am attempting unsuccessfully. 

{{
curl --request GET \
--url 'https://https://<site name>.atlassian.net//rest/api/3/issue/limit/report?isReturningKeys=

{isReturningKeys}

' \
--user '<my email>:<api_token>' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{
"issuesApproachingLimitParams": {}
}'
}}

 

Documentation: https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issues/#api-rest-api-3-issue-limit-report-get

 

Anyone know how to do this in PowerShell or have a good reference/tutorial for calling APIs in Jira Cloud with PowerShell?

Thanks in advance!

2 answers

1 accepted

0 votes
Answer accepted
Jason Krewson
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 14, 2024

So I did find a way using Copilot to convert the curl into a PowerShell cmd, below is that cmd, but this will just tell you what is over the limit. I am unable to get it to tell me what is close to the limit instead, or what is over say 8,000 worklogs yet. 

$headers = @{
    "Accept" = "application/json"
    "Content-Type" = "application/json"
    "Authorization" = "Basic " + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("<My Email>:<my API Token>"))
}

$response = Invoke-RestMethod -Uri 'https://<site name>/rest/api/3/issue/limit/report?isReturningKeys=true' `
                              -Method Get `
                              -Headers $headers

# Display the response in a readable format
$response | ConvertTo-Json -Depth 4

 Its cool to know that in the future when I need to query a Jira API I can just have Copilot convert it though.

Jason Krewson
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 14, 2024

This seems to be the answer, I started over and asked Copilot to write the PowerShell cmd instead of converting it from the curl like I did in my last update, I provided the link to the documentation also at https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issues/#api-rest-api-3-issue-limit-report-get

After running this I got a response that no issues approaching the worklog limit were found, so its hard to test this as this is the only way to query this according to my conversation with Atlassian last week. 

 

 

 

# Define your Jira Cloud instance URL and authentication details
$JiraBaseUrl = "Your Jira Site"
$JiraUsername = "Your Jira Account Email"
$JiraAPIToken = "Your Jira API Token"

# Define the API endpoint for the issue limit report
$ApiEndpoint = "$JiraBaseUrl/rest/api/3/issue/limit/report"

# Encode the credentials
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("${JiraUsername}:${JiraAPIToken}"))

# Make the API request
$response = Invoke-RestMethod -Uri $ApiEndpoint -Method Get -Headers @{
    Authorization = "Basic $base64AuthInfo"
    Accept = "application/json"
}

# Check if the response contains issues
if ($response.issuesApproachingLimit) {
    # Output the results
    $response.issuesApproachingLimit | ForEach-Object {
        [PSCustomObject]@{
            IssueKey = $_.issueKey
            LimitType = $_.limitType
            CurrentValue = $_.currentValue
            LimitValue = $_.limitValue
        }
    }
} else {
    Write-Output "No issues approaching the worklog limit were found."
}
1 vote
Harrison Ponce
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 13, 2024

Hi @Jason Krewson , we've struggled a lot with these and we've learned....some stuff lol.

One of the things I'm noticing right away from your curl is that your url has two "https://" pieces back to back which could be causing an issue.

If that doesn't fix the issue for you, I'm happy to dig further and try it on ours to get it to work for what you're looking for!

Jason Krewson
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 14, 2024

Thanks so much for the response!

So I removed the second "https://", good find, it's still failing to run. 

Seems to be an issue with "unary operator '--'" for all of them, I am still messing with it also.

I cleaned up company information also with <company info - what it was> so if you see that, that is why.

--------------------------

PS C:\Users\<company info - my Windows account> {{
>> curl --request GET \
>> --url '<company info - our site>//rest/api/3/issue/limit/report?isReturningKeys=
>>
>> {isReturningKeys}
>>
>> ' \
>> --user '<company info - my email>:<company info - my API token>' \
>> --header 'Accept: application/json' \
>> --header 'Content-Type: application/json' \
>> --data '{
>> "issuesApproachingLimitParams": {}
>> }'
>> }}
At line:3 char:3
+ --url '<company info - our site>//rest/api/3/issue/limit/report? ...
+ ~
Missing expression after unary operator '--'.
At line:3 char:3
+ --url 'https://<company info - our site>//rest/api/3/issue/limit/report? ...
+ ~~~
Unexpected token 'url' in expression or statement.
At line:8 char:3
+ --user '<company info - my email>:<company info - my API token> ...
+ ~
Missing expression after unary operator '--'.
At line:8 char:3
+ --user '<company info - my email>:<company info - my API token> ...
+ ~~~~
Unexpected token 'user' in expression or statement.
At line:9 char:3
+ --header 'Accept: application/json' \
+ ~
Missing expression after unary operator '--'.
At line:9 char:3
+ --header 'Accept: application/json' \
+ ~~~~~~
Unexpected token 'header' in expression or statement.
At line:10 char:3
+ --header 'Content-Type: application/json' \
+ ~
Missing expression after unary operator '--'.
At line:10 char:3
+ --header 'Content-Type: application/json' \
+ ~~~~~~
Unexpected token 'header' in expression or statement.
At line:11 char:3
+ --data '{
+ ~
Missing expression after unary operator '--'.
At line:11 char:3
+ --data '{
+ ~~~~
Unexpected token 'data' in expression or statement.
Not all parse errors were reported. Correct the reported errors and try again.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : MissingExpressionAfterOperator

Jason Krewson
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 14, 2024

Working with Copilot to convert this to use in PowerShell. 

At first I had some credential issues, but I kept telling Copilot the error I received over and it would tell me something new to try mentioning what it thinks the issue was, its pretty amazing. 

After trying a couple times I got the below results, still not correct but close. 

limits issuesBreachingLimit

------ --------------------

@{worklog=10000; attachment=2000; comment=5000; issuelinks=2000; remoteIssueLinks=2000} @{remoteIssueLinks=; attachment=; comment=; issuelinks=; worklog=}

 

I let Copilot know its not providing the issues that are close to the limits, so next output I received the below, 

 

$headers = @{
    "Accept" = "application/json"
    "Content-Type" = "application/json"
    "Authorization" = "Basic " + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("<My Email>:<my API Token>"))
}

$response = Invoke-RestMethod -Uri 'https://<site name>/rest/api/3/issue/limit/report?isReturningKeys=true' `
                              -Method Get `
                              -Headers $headers

# Display the response in a readable format
$response | ConvertTo-Json -Depth 4


MY RESULTS WERE THIS:

# Display the response in a readable format
$response | ConvertTo-Json -Depth 4
{
"limits": {
"remoteIssueLinks": 2000,
"worklog": 10000,
"attachment": 2000,
"comment": 5000,
"issuelinks": 2000
},
"issuesBreachingLimit": {
"remoteIssueLinks": {

 

},
"attachment": {

 

},
"comment": {

 

},
"issuelinks": {

 

},
"worklog": {
"PLSD-587": 14056,
"PLSS-194": 27223
}
}
}

 

 

I still need to review them but just wanted to update here, AI can help, so that is cool. 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events