pycontribs/jira

Add ability to search users by email

agileminor opened this issue · 5 comments

Problem trying to solve

Using search_user uses rest/api/2/user/search?username=XXX, which throws the following error for me from Jira Cloud - "The query parameter 'username' is not supported in GDPR strict mode."

Possible solution(s)

Looks like they want people to use accountId instead, so it would be good to get that added to the supported search commands. Also, email would be useful - /rest/api/3/user/search?query=

Alternatives

No response

Additional Context

This is discussed here https://developer.atlassian.com/cloud/jira/platform/deprecation-notice-user-privacy-api-migration-guide/

You can do that by using the query argument via:

jira.search_users(query="first.last@company.com")

Sample using requests:

        response = requests.get(
            url="https://company.atlassian.net/rest/api/2/user/search/",
            params={"query": "first.last@domain.com"},
            headers={"Authorization": "Basic  <basic auth secret>"},
        )

Sample using curl:

curl "https://company.atlassian.net/rest/api/2/user/search/?query=first.last%40company.com"

returns the following:

[
  {
    "self": "https://company.atlassian.net/rest/api/2/user?accountId=5f2...",
    "accountId": "5f2...",
    "accountType": "atlassian",
    "emailAddress": "first.last@company.com",
    "avatarUrls": {
      "24x24": "https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/5f2...",
    },
    "displayName": "First Last",
    "active": true,
    "timeZone": "blah",
    "locale": "en_US"
  }
]

True - but the current code doesn't use query=...., it uses username=..., which has the issue I mentioned above.
The workaround I'm using is to bypass search_user and directly call the rest API with query=.

I see. I posted an edit to how I use this library (you replied too fast!) See above. You can use the query arg with the search_users function to search by email.

I found this comment in the code:

jira/jira/client.py

Lines 3955 to 3956 in eb0ec90

"username" query parameter is deprecated in Jira Cloud; the expected parameter now is "query", which can just be the full email again.
But the "user" parameter is kept for backwards compatibility, i.e. Jira Server/Data Center.

Thanks - much appreciated.