The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

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

Jira REST API v3 with OAuth 2.0 (3LO) via Google Chrome browser returns empty list []

Hiroshi Nishio
Contributor
September 5, 2022

Summary

Calling Jira REST API v3 (OAuth 2.0 (3LO)) from Google Chrome returns only an empty list. When I try the same API on Postman, it returns a list with proper contents.

Wanna know why and how to fix it.

Response via Chrome (Fail)

issues: []
maxResults: 1
startAt: 0
total: 0

Response via Postman (Success)

{
    "expand""names,schema",
    "startAt"0,
    "maxResults"1,
    "total"18,
    "issues": [
        {
            "id""10....20",
            "key""M...R-20",
            "fields": {
                "summary"".....",
                "created""2022-09-05T05:35:47.403+0000",
                "assignee": {
                    "accountId""62bb.....a1ff",
                    "displayName""Hiroshi Nishio",
                },
                "updated""2022-09-05T05:35:49.228+0000",
                "status": {
                    "name""To Do",
                    "id""10005",
                }
            }
        }
    ]
}

Source

```javascript

// Search issues in Jira with JQL
interface ParamsTypes extends Record<string, string | number | boolean> {
  startAt: number; // Default is 0
  maxResults: number; // Default is 50
  validateQuery: 'strict' | 'warn' | 'none' | 'true' | 'false'; // Default is strict
  fields: string; // Default is all fields
}

interface SearchIssuesProps {
  atlassianAccessToken: string;
  atlassianRefreshToken: string;
  atlassianCloudId: string;
  startAt: number;
  maxResults: number;
  uid: string;
}

const searchIssues = async ({
  atlassianAccessToken,
  atlassianRefreshToken,
  atlassianCloudId,
  startAt,
  maxResults,
  uid
}: SearchIssuesProps) => {
  const headers = new Headers();
  headers.append('Accept', 'application/json');
  headers.append('Authorization', 'Bearer' + atlassianAccessToken);
  const params: ParamsTypes = {
    startAt, // Default is 0
    maxResults, // Default is 50
    validateQuery: 'strict', // Default is strict
    fields: 'summary,status,assignee,creator,reporter,created,updated'
  };
  const queryString = Object.keys(params)
    .map((key) => `${key}=${encodeURIComponent(params[key])}`)
    .join('&');
  const url = `https://api.atlassian.com/ex/jira/${atlassianCloudId}/rest/api/3/search?${queryString}`;

  // Get tasks completed
  const response = await fetch(url, {
    method: 'GET',
    headers: headers
  })
    .then((res) => res.json())

  return response;
};

```

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

3 votes
Answer accepted
Hiroshi Nishio
Contributor
September 6, 2022

Sorry for the fuss, there was no space after Bearer, so it was not authenticated. It was a completely ordinary mistake. But it would be nice if the error would tell us these things too.

DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events