rest api shows data in browser but from powershell no result .

prakashgss
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!
March 14, 2025

myurl/rest/api/3/search/jql?jql=project=xxxx    shows data when opened in IE . But when run from powershell with below command not retuning any data.

 

Invoke-RestMethod -Method 'Get' -Uri $jira_url -Authentication Basic -Credential $credential -ContentType "application/json" -OutFile ./jiras-current-project.json

2 answers

0 votes
Daniel Ajenjo
Contributor
March 14, 2025

Hi @prakashgss

I have verified that the Jira API works correctly using both cURL and PowerShell. Below are the detailed steps for both options. 

🔹 Option 1: Using cURL in the Terminal (Recommended)

1️⃣ Get the API Token

If you don’t have an API token yet:

2️⃣ Run the command in Terminal

Replace "your_email@domain.com" and "your_api_token" with your Atlassian credentials and yourdomain and project in GET method:

curl -u "your_email@domain.com:your_api_token" \
     -H "Accept: application/json" \
     -H "Content-Type: application/json" \
     -X GET "https://yourdomain.atlassian.net/rest/api/3/search?jql=project=XXX"

🔹 To save the response to a JSON file:

curl -u "your_email@domain.com:your_api_token" \
     -H "Accept: application/json" \
     -H "Content-Type: application/json" \
     -X GET "https://yourdomain.atlassian.net/rest/api/3/search?jql=project=PROJ1" \
     -o jiras-current-project.json

✔ This will generate a jiras-current-project.json file in your current directory.

🔹 Option 2: Using PowerShell

If you prefer to use PowerShell, follow these steps:

1️⃣ Create a PowerShell script file

Run in Terminal:

nano jira_request.ps1

Copy and paste the following code into the file, replacing "your_email@domain.com" and "your_api_token" with your credentials and yourdomain and project in GET method:

$email = "your_email@domain.com"
$api_token = "your_api_token"
$auth = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("${email}:${api_token}"))

$headers = @{
    Authorization = "Basic $auth"
    "Content-Type" = "application/json"
    Accept = "application/json"
}

$jira_url = "https://yourdomain.atlassian.net/rest/api/3/search?jql=project=XXX"

$response = Invoke-RestMethod -Method 'Get' -Uri $jira_url -Headers $headers
$response | ConvertTo-Json -Depth 50 | Out-File -Encoding utf8 "./jiras-current-project.json"

Save and close (CTRL + X, then Y, and ENTER).

2️⃣ Run the script in PowerShell

In the Terminal, start PowerShell:

pwsh

Run the script:

./jira_request.ps1

✔ This will generate a jiras-current-project.json file with the Jira response.

📌 Verification

To check if the JSON file was generated correctly:

cat jiras-current-project.json

⸻ 

🚀 Conclusion

With these steps, you can test and save the Jira Cloud API response in two ways: using cURL in Terminal or PowerShell with a script. Both options have been verified and work correctly.

If this response was helpful, don’t forget to mark it as accepted! 🚀

0 votes
Vishal Biyani
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.
March 14, 2025

@prakashgss 

Can you try with this script? The difference in calling is to pass the Authorization in header.

$headers = @{
Authorization = "Basic YourPAT"
}

$response = Invoke-RestMethod -Uri "https://your-instance.atlassian.net/rest/api/3/myself" -Headers $headers -Method Get

$response

prakashgss
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!
March 14, 2025

Did not work .  Many REST APIs have been working for me except this one to get issues in project . It seems OAuth2.0 should be used to register and app and get required token for specific APIs. It is mentioned here.

https://www.google.com/search?q=client+must+be+authticated+to+use+this+powershell+rest+api+jira&rlz=1C1GCEA_enIN1148IN1148&oq=client+must+be+authticated+to+use+this+powershell+rest+api+jira&gs_lcrp=EgZjaHJvbWUyBggAEEUYOdIBCTExMDQxajBqN6gCALACAA&sourceid=chrome&ie=UTF-8

 

Thanks for your time .

Suggest an answer

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

Atlassian Community Events