How to get all users of a Jira Cloud project

Hi All,
I am following the page “https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-users/#api-rest-api-3-users-search-get” to fetch all the users in a certain project. I am using the simple JS sample code given in this documentation page and passed my respective cloud ID credentials to replace the sample provided. please see below my code sample.

const fetch = require('node-fetch');

fetch('https://api.atlassian.com/ex/jira/:678b8XXX-3d13-15fX-64HX-c465XXa9718XXXX:/rest/api/3/users/search', {
  method: 'GET',
  headers: {
    'Authorization': `Basic ${Buffer.from(
      'psl-mgr@yahoo.com:xdt2XXavUljiVRbxxcf43xx'
    ).toString('base64')}`,
    'Accept': 'application/json'
  }
})
  .then(response => {
    console.log(
      `Response: ${response.status} ${response.statusText}`
    );
    return response.text();
  })
  .then(text => console.log(text))
  .catch(err => console.error(err));

and I am getting the response,
Response: 400 Bad Request
{“code”:400,“message”:“cloudId or product name are not provided”}

Blockquote

if I remove the colon (:cloud id:) before and after the cloud id in the fetch request I am getting differnet error as below.

Response: 404 Not Found
{“timestamp”:“2021-08-23T03:14:13.854Z”,“status”:404,“error”:“Not Found”,“message”:“No message available”,“path”:“/ex/jira/678b8XXX-3d13-15fX-64HX-c465XXa9718XXXX/rest/api/3/users/search”}

Please, guide me on how to fetch all the users of the Jira project, using the ADMIN’s API Key.

Regards,
Srini.

Welcome to the Atlassian developer community @srinivasanr.

Unfortunately, the documentation, sample code, and error messages are misleading for use with API tokens. At the top of the REST API documentation is a section on Version and URI that explains:

The URIs for resources have this structure:
https://<site-url>/rest/api/3/<resource-name>
For example, https://your-domain.atlassian.net/rest/api/3/issue/DEMO-1

The documentation on using API tokens subtly documents this with the curl example:

curl -v https://mysite.atlassian.net --user me@example.com:my-api-token

I think you are getting a 404 error because you have colons around the cloud ID. Otherwise, I think you would get a 401 to indicate you are using the wrong auth mechanism.

Other than the URL in the fetch call, everything looks correct. Maybe too correct. I hope you didn’t post a real API token! If you have, I recommend you revoke it immediately.

2 Likes

Thank you, Ian, I tried executing the call with the URL format as in your response
https:///rest/api/3/ so, now my URL is
https://brtchip02.atlassian.net/rest/api/3/users/search and it is working fine, I could able to fetch all the users in this account.

I have another doubt, is it possible to fetch the user only for a specific project? in that case how to pass the Project key in your URL format?

Regards,
Srini.

@srinivasanr,

is it possible to fetch the user only for a specific project?

I think you need to refine the concept of “user for a specific project” because there are multiple layers of indirection between project and user. Projects have roles. Roles have actors, which is the name for the superset of users or groups. And groups have users. Because of this indirection, a user can be “in” a project for multiple reasons. For example, I could be added as part of both a “developer” role and an “admin” role, each providing me different things I can do with the project.

To resolve the ambiguity, we need to pick what we think the user should be able to do using permissions. Let’s say what I care about is CREATE_ISSUES. Then I can find users with permissions for my TIS project using GET /rest/api/3/user/permission/search?permissions=CREATE_ISSUES&projectKey=TIS.

1 Like

Thank you Ian, I tried the format

/rest/api/3/user/permission/search?permissions=CREATE_ISSUES&projectKey=TP

Still, I am getting all the users as the same response as when I simply pass " /rest/api/3/users/search". Passing the query parm is not having any impact.

The main problem I am seeing is, in the response Object I am getting some users of type “app” with display name “Automation for Jira”, “Microsoft Teams for Confluence Cloud”, “Trello” and so on, those responses make my parsing more complicated I tried sending the request with query parm set to “accountType=atlassian”, but still I am getting all the full list. could you please give me some clue how to get only the users with the accountType having “atlassian”.

Regards,
Srini.

@srinivasanr,

I can’t help narrow the query because I don’t understand what you are trying to accomplish. What do you mean by “user for a project”? How are you going to use that list?

Okay, Yes, I should give a bigger picture in this case.
I am creating a program that would sync (create/update) the Bugs/issues created in Redmine by the verification team into the Jira for the developers to work on.
Note: Verification team uses Redmine for Bug tracking and the development team uses Jira for Bug fixing and other process management to comply with Agile development.

while creating the issue in Jira I need to set the assignee field. Redmine Assignee string is not directly compatible with Jira’s Assignee’s account ID, so I need to map the users of the Redmine with the display name of account Ids from Jira. In this context when the program starts I need to pull all the users working in the given Jira Project and match the name string that comes from the Redmine Bug task and pass that account Id while making a call to the resource “/rest/api/3/issue/{issueIdOrKey}/assignee”.

Now, with your suggestion in accessing the resource “/rest/api/3/users/search” to fetch all the users in the Jira Project, I am successful, but it has many other different accounts types called “app” with the display "Automation for Jira”, “Microsoft Teams for Confluence Cloud”, “Trello” and so on, but I want to fetch only the users with the account type “atlassian”, which has the proper display name of our Project members.
Firstly, I am not aware of what is these accounts with type “app” and why are they connect with the Jira project, secondly how to exclude them in fetching all the users.

please let me know If I miss out some details.

Regards,
Srini.

@srinivasanr,

Sorry to hear the team can’t get into the same tooling. And I’m sad to hear that you must “comply with Agile development” while leaving the verification team outside the development team. From long ago, I remember how painful it is for both developers and testers when they aren’t working together daily. Back when those problems were more fresh for me, I wrote about software tools that solve for this kind of synchronization:

If you still think writing your own is the way to go, then you will want to use the ASSIGNABLE_USER permission as a filter, instead of CREATE_ISSUES. Technically, Apps can be given permission to be assignees, but that’s a rare corner case. As you build the integration, you should use the permissions API that I linked above to see what other permissions make sense as a filter.

Also, you might find emails easier to map because display names are not guaranteed to be in a consistent format (because of profile visibility settings). The Email API does require getting permission, but should be straightforward for your in-house scenario:

Thank you, Ian, this is the complete reference you have given me. Adding on the list of the available tools, like TaskTop and OpsHub, we are planing to try out the Taskadapter.
Okay, Yes, I must use the email address field of Jira instead of the display name to avoid inconsistancies, But the Redmine API that fetches the issue has the Assignee field mad of First name, if that contains the email property instead, then, it is much easier to map the email from Redmine to Jira. Since Redmine’s assignee field of the issue does not contain the email and it only has the Fullname, I need to first map the Redmine user’s fullname to the Redmine User’s email and then map to the Jira email field.

Hi Ian,
Need one more piece of advice from you for the below scenario.
Problem statement:
How to update the status of a Jira Issue?
Details:
In Redmine we have a different status of the Issues such as 1) New, 2) Assigned 3) In Progress 4) Resolved 5) Verified 6) closed 7) Rejected.
In the case of Jira, I believe the status is managed by the workflow and when I sync the issues from Redmine to Jira, Even the status of the Redmine Issue is Resolved or closed, the issue in the Jira is reflected to “To Do / Open”.Is there any way that I can directly alter the status of the Jira Issue based on the mapping of the status between Redmine and Jira?
Or else could you please pass me how to handle this situation?

@srinivasanr,

How to update the status of a Jira Issue?

The short answer is that you update the status of an issue by transitioning the issue using POST /rest/api/3/issue/{issueIdOrKey}/transitions.

What makes this difficult is what you describe in mapping from another tool. The issue status cannot be set directly and an issue transition means first checking what status the issue already has, enumerating the transitions, and finding the transition to the target state. The complexity of this logic is why I usually recommend the middleware instead of “do it yourself”.

One thing that really helps is to intentionally configure both products with matching workflows. For example, Redmine with “verified”, “rejected”, and “resolved” states won’t map easily to default Jira workflows where those are considered resolutions, not statuses. Conversely, many Jira configurations have statuses after “in progress”, like “in review” or “testing”. The technical side is hard enough without the configurations being very different.

Hi Ian,
I am facing an issue, all of the sudden, with my test setup, I am sure it is not something related to the code, rather something related to the Jira setup. the problem is, for all the sync I attempt to post to JIRA, I am getting the response Default issue type Bug does not exist in JIRA]. I have verified the settings in the JIRA account and set the default issue type to “Bug” for this particular project, but still I could not able to come out of this problem, Please see the below screenshot for my project setup.

Please, pass me any hint, which could unblock me. This problem is happening to my setup after I pause and resume back this task, after I switch over to other priority tasks and come back to this.

Thanks,
Srini.

@srinivasanr,

Could you provide an example (with API key redacted) of the requests you are trying to POST?

Hi Ian,
I was able to solve that problem, as this problem was happening might because of the expiry of the access token. when I created the new access token, the problem disappears.

Regards,
Srini.

1 Like