Using server endpoints (REST/Servlets)
Introduction
User Export for Jira has application endpoints and servlets that can be used programmatically to interact with user search in Jira. These endpoints are also used in the user interface in the Jira administration area.
SUPPORT
Please use Netic A/S Service Desk if you have any questions or difficulties using the server endpoints.
Endpoint/Servlet security
All REST endpoints can ONLY be accessed by a Jira administrator via basic authentication. Secure your Jira access via HTTPS (HTTP over SSL).
Searching
The search cURL command takes a JSON object as POST data.
# Search for admin string in both active and inactive users
curl -v -u admin:admin -X POST "<your-jira-baseurl>/rest/jirauserexport/1.0/users/find?pageNumber=0&pageSize=100" \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-d '{"searchString":"admin","activeUsers":"true","inActiveUsers":"true","group":"","application":""}' >> jira-users.json
The JSON object has the following properties:
Property name | Property description | Property type | Property value(s) examples |
---|---|---|---|
searchString | The actual search string to use for email, username and full name. | String | "admin" |
activeUsers | Filter on active users in Jira. | boolean | true or false |
inActiveUsers | Filter on inactive users in Jira. | boolean | true or false |
application | The application name in Jira. | String | jira-software,jira-servicedesk |
groups | The list of Jira group names. | Array of Strings | jira-users,jira-administrators |
Searching Jira Users via REST endpoint
Python 3 code with requests library for searching Jira users by calling the search REST endpoint
Python 3 code
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
Search for admin string
'''
import requests
import base64
import json
JIRA_URL = "http://localhost:2990/jira/rest/jirauserexport/1.0/users/find"
BASIC_AUTH = "Basic " + base64.b64encode(b"admin:admin").decode("utf-8")
HEADERS = {"Content-type": "application/json", "Accept":"application/json", "Authorization": BASIC_AUTH}
def call_endpoint(url, data, headers, method, page_number, page_size):
local_url = url + "?pageNumber=" + str(page_number) + "&pageSize=" + str(page_size)
r = requests.post(url=local_url, json=data, headers=HEADERS)
assert r._content
return json.loads(r._content)
if __name__ == "__main__":
data = {"searchString": "admin", "activeUsers": "true", "inActiveUsers": "true"}
json_data = call_endpoint(url=JIRA_URL, data=data, headers=HEADERS, method="POST", page_number=0, page_size=100)
print(json_data)
cURL command for searching and saving search results in file named jira-users.json
cURL commands for searching
# Search and return full result
curl -u admin:admin -X POST "<your-jira-baseurl>/rest/jirauserexport/1.0/users/find?pageNumber=0&pageSize=100" \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-d '{"searchString":"","activeUsers":true,"inActiveUsers":true}' >> jira-users.json
# Search and return 20 users with offset 0
curl -u admin:admin -X POST "<your-jira-baseurl>/rest/jirauserexport/1.0/users/find?pageNumber=0&pageSize=20" \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-d '{"searchString":"","activeUsers":true,"inActiveUsers":true}' >> jira-users.json
# Search for active Jira users only
curl -u admin:admin -X POST "<your-jira-baseurl>/rest/jirauserexport/1.0/users/find?pageNumber=0&pageSize=100" \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-d '{"searchString":"","activeUsers":true,"inActiveUsers":false}' >> jira-users.json
Exporting search results
In order to use the export servlets some request parameters are needed for filtering.
Parameter name | Parameter description | Parameter type | Parameter value(s) examples |
---|---|---|---|
userexport_searchstring | The actual search string to use for email, username and full name | String | A search string like "admin" or "john" |
userexport_application | The application name in Jira. | String | jira-software, jira-servicedesk, jira-core |
userexport_groups | The list of Jira group names. | String | jira-administrators |
userexport_activeUsers | Filter on active users in Jira. | boolean string | "true" or "false" |
userexport_inactiveUsers | Filter on inactive users in Jira | boolean string | "true" or "false" |
The cURL command below will use the search string "admin" where Jira users are active and inactive and where application access is Jira Software and where there the user belongs to Jira groups jira-software-users and jira-administrators and where the user has Jira project browse permission in Jira projects ITINT and CEA.