Use REST API in JIRA (user registration as an example)

Described because it was investigated in connection with business.

Purpose

As an example of how to use the REST API in JIRA This section describes the procedure for user registration.

Premise

--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.

Overview

Register a specific user by hitting JIRA's REST API from Python code.

easy explanation

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.

Use of user registration API

Request destination path

/rest/api/2/user

Use POST for the method.

Request body

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

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))

Reference material

--Request module documentation - http://docs.python-requests.org/en/master/ --Official document - https://docs.atlassian.com/jira/REST/7.1.8/

Recommended Posts

Use REST API in JIRA (user registration as an example)
Use JIRA API
Implement item-based collaborative filtering in python-using MovieLens as an example
Use Remotte as a user
Quickly implement REST API in Python
Use tensorflow in an environment without root
Use Ghost.py as an alternative to PhantomJS