Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling add_user() on Jira Cloud instances fails with: You must specify the products that user can access. #1869

Open
2 of 4 tasks
kot0dama opened this issue Jun 17, 2024 · 2 comments

Comments

@kot0dama
Copy link

Bug summary

Calling add_user() on Jira Cloud instances fails with this error: You must specify the products that user can access.

This seems to be a new requirement on Jira Cloud instances from about 2 weeks ago.

Is there an existing issue for this?

  • I have searched the existing issues

Jira Instance type

Jira Cloud (Hosted by Atlassian)

Jira instance version

No response

jira-python version

3.5.2-1

Python Interpreter version

3.12.3

Which operating systems have you used?

  • Linux
  • macOS
  • Windows

Reproduction steps

# 1. Given a Jira client instance
jira: JIRA
# 2. When I call the add_user with either of these arguments
jira.add_user(username="REDACTED", email="REDACTED", fullname="REDACTED", notify=True, application_keys=["jira-software"])
jira.add_user(username="REDACTED", email="REDACTED", fullname="REDACTED", notify=True)

Stack trace

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/jira/client.py", line 4630, in add_user
    raise e
  File "/usr/lib/python3/dist-packages/jira/client.py", line 4620, in add_user
    self._session.post(url, data=payload)
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 637, in post
    return self.request("POST", url, data=data, json=json, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/jira/resilientsession.py", line 246, in request
    elif raise_on_error(response, **processed_kwargs):
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/jira/resilientsession.py", line 71, in raise_on_error
    raise JIRAError(
jira.exceptions.JIRAError: JiraError HTTP 400 url: https://REDACTED/rest/api/latest/user
        text: You must specify the products that user can access.

        response headers = REDACTED
        response text = {"errorMessages":["You must specify the products that user can access."],"errors":{}}

Expected behaviour

add_user() method shall comply with Jira Cloud requirements, and send a product list.

Calling a modified add_user() method, adding products like this fixes it:
https://github.com/pycontribs/jira/blob/main/jira/client.py#L5126

         if notify:
             x["notification"] = "True"
+       if products is not None:
+           x["products"] = products
         if application_keys is not None:
             x["applicationKeys"] = application_keys

Tested and confirmed working with products = ["jira-software"]

Thank you,
Loïc

Additional Context

No response

@zousu
Copy link

zousu commented Jul 12, 2024

When can this version be updated?

@princenyeche
Copy link

In the payload, you should specify a product or use an empty list if you just want to create the user without being added to any product

{
"emailAddress": "[email protected]",
"products": []
}

This update was added in May about products field now mandatory in the Create User API

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants