Described because it was investigated in connection with business.
As an example of how to use the REST API in JIRA This section describes the procedure for user registration.
--jira version is 7.1.8 --jira is published on https
It may not work if it is published on HTTP. (unconfirmed)
Also, since I am using Python, the following conditions are also required.
Register a specific user by hitting JIRA's REST API from Python code.
Basically, you can operate by passing the specified HTTP method and authentication information to the path of Document description. .. This time, I'm hitting the user registration API as a sample.
In addition, the following conditions must be met in order to hit the following REST API.
--User authenticates with Basic authentication --The REST API can be executed only for the operations that can be performed by the above users. --In other words, you must be in the jira-administrator group to perform user registration with JIRA's REST API.
/rest/api/2/user
Use POST for the method.
Parameters | Description |
---|---|
name | User ID |
emailAddress | (Valid)mail address |
password | Initial password. Random when not specified**(Not used this time)** |
displayName | The name to display on the screen |
applicationKeys | Application to belong to(Described in a list) |
Request body sample
{
"name": "test_taro",
"emailAddress": "[email protected]",
"displayName": "Test Taro",
"applicationKeys":
"jira-software",
],
}
Sample code
import requests
from requests import RequestException
#Request destination host
TARGET_HOST = "atlassian.example.com"
CONTEXT = "/jira"
USER_CREATE_PATH="/rest/api/2/user"
request_body = {
"name": "test_taro",
"emailAddress": "[email protected]",
"displayName": "Test Taro",
"applicationKeys":
"jira-software",
],
}
request_path = "https://"+TARGET_HOST+CONTEXT+USER_CREATE_PATH
try:
response = requests.post(request_path, auth=('jira_admin_user','hogehoge'),json=request_body)
except RequestException as err:
print(str(err))
print(str(response))
--Request module documentation - http://docs.python-requests.org/en/master/ --Official document - https://docs.atlassian.com/jira/REST/7.1.8/
Recommended Posts