Forums

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

REST API Create User Issue

Luke Simon February 21, 2023

Hello! I am trying to create a very simple script that creates a new user. I have been following the Jira Cloud platform REST API documentation

and copied the Create user script for Python. When I try running it, I receive the following error:

File "<stdin>", line 1, in <module>

  File "/opt/anaconda3/lib/python3.8/json/__init__.py", line 357, in loads

    return _default_decoder.decode(s)

  File "/opt/anaconda3/lib/python3.8/json/decoder.py", line 337, in decode

    obj, end = self.raw_decode(s, idx=_w(s, 0).end())

  File "/opt/anaconda3/lib/python3.8/json/decoder.py", line 355, in raw_decode

    raise JSONDecodeError("Expecting value", s, err.value) from None

json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

 

I'm not quite sure what I am doing wrong. The only portion of the script I'm really changing are the URL, email addresses, and API tokens. Any and all help is greatly appreciated!

1 answer

1 vote
Vamsi Kandala
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.
February 21, 2023

Hi @Luke Simon

Welcome to Atlassian community!

Is it possible to post your code here?  I know that you mentioned the article and the example provided there in, but just wanted to check it out.

Did you try checking out the curl example using the tool like Postman?

Thanks,
Vamsi

Luke Simon February 21, 2023

I have not tried the curl example, no.

Here is my code:


import requests
from requests.auth import HTTPBasicAuth
import json
url = "https://mycompanynamehere.atlassian.net/rest/api/3/user"
auth = HTTPBasicAuth("username@username.com", "APIKEY")
headers = {
"Accept": "application/json",
"Content-Type": "application/json"
}
payload = json.dumps( {
"emailAddress": "testuser@testuser.com"
} )
response = requests.request(
"POST",
url,
data=payload,
headers=headers,
auth=auth
)
print(json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": ")))

Luke Simon February 23, 2023

@Vamsi Kandala find anything?

Vamsi Kandala
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.
February 23, 2023

Hi @Luke Simon

I used the same exact code after updating the details for my Cloud Jira url and authentication.  It worked for me and created the user successfully.

So, it is not related to the code and must be missing some libraries.  

Are you using any application like PyCharm or anything and executing your code?  I just created the 'test.py' file and executed that in CLI directly like 'python test.py'.

Can you try updating Python to the latest version if it is not already updated and also try updating the GUI software if you are using one (like PyCharm)?

Thanks,
Vamsi

Luke Simon February 23, 2023

I am on MacOS and using python via terminal. It is updated to the newest version, so I'm not sure what I am doing wrong either!

Sam Stinton
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!
May 10, 2023

I've got the same issue, latest version of Python on windows and following https://confluence.atlassian.com/jirakb/how-to-bulk-create-users-in-jira-1129691096.html 

From what I've read it's seeing an invalid json file, but the syntax in the .py script looks correct?

Traceback (most recent call last):
File "C:\Temp\bulkuser.py", line 35, in <module>
print(json.dumps(json.loads(response.text), sort_keys=True, separators=(",", ": ")))
^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1008.0_x64__qbz5n2kfra8p0\Lib\json\__init__.py", line 346, in loads
return _default_decoder.decode(s)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1008.0_x64__qbz5n2kfra8p0\Lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1008.0_x64__qbz5n2kfra8p0\Lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Product Admin
TAGS
atlassian, atlassian government cloud, fedramp, webinar, register for webinar, atlassian cloud webinar, fedramp moderate offering, work faster with cloud

Unlocking the future with Atlassian Government Cloud ☁️

Atlassian Government Cloud has achieved FedRAMP Authorization at the Moderate level! Join our webinar to learn how you can accelerate mission success and move work forward faster in cloud, all while ensuring your critical data is secure.

Register Now
AUG Leaders

Atlassian Community Events