Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Table of Contents

Introduction

Jira User Export app has a build in REST endpoint that can be used to get, create, update and delete Jira User Properties. This can be very useful if you want to bulk update Jira user properties for a large set of Jira users.

The REST endpoint is available when Jira User Export app 1.2.0 or greater is installed in Jira. It can be found under <jira-base-url>/rest/jirauserexport/1.0/userproperties.

Info
title

SECURITY

Only Jira users with Jira Admininstrators or Jira System Administrators global permission can access this endpoint.


Info
title

SUPPORT

Please use Netic A/S Service Desk if you have any questions or difficulties using the server endpoints for Jira user properties.


Operation

HTTP Method

Authentication

REST endpoint

JSON Payload

Get Jira user property

GET

BASIC

<jira-base-url>/rest/jirauserexport/1.0/userproperties


Code Block
languagejs
themeRDarklinenumberstrue
{"username": "admin","userPropertyKey": "mobile"}


Create Jira user property

POST

BASIC

<jira-base-url>/rest/jirauserexport/1.0/userproperties


Code Block
languagejs
themeRDarklinenumbers
true
{"username": "admin","userPropertyKey": "mobile", "userPropertyValue":"+4511223344"}


Update Jira user property

PUT

BASIC

<jira-base-url>/rest/jirauserexport/1.0/userproperties


Code Block
languagejs
themeRDarklinenumberstrue
{"username": "admin","userPropertyKey": "mobile", "userPropertyValue":"+4511223344"}


Delete Jira user property

DELETE

BASIC

<jira-base-url>/rest/jirauserexport/1.0/userproperties


Code Block
languagejs
themeRDarklinenumberstrue
{"username": "admin","userPropertyKey": "mobile"}


Get user property for a given user

Python 2 code for getting a Jira user property

Code Block
languagepy
themeRDark
linenumberstrue
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
Get user properties for Jira user - HTTP GET
'''
import json
import urllib2
import base64

BASIC_AUTH = "Basic " + base64.b64encode("admin:admin")
HEADERS = {"Content-type": "application/json","Accept":"application/json","Authorization": BASIC_AUTH}
URL = "http://localhost:2990/jira/rest/jirauserexport/1.0/userproperties"

def get_user_property(user_name, property_key, url):
    data = json.dumps({
        "username": user_name,
        "userPropertyKey": property_key
    })
    request = urllib2.Request(url, data, HEADERS)
    request.get_method = lambda: "GET"
    try:
        contents = urllib2.urlopen(request).read()
        if contents:
            print contents
    except urllib2.HTTPError as e:
        print e.code


get_user_property(user_name="admin", property_key="mobile", url=URL)

...

Python 2 code for creating a Jira user property

Code Block
languagepy
themeRDark
linenumberstrue
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
Create user properties for Jira user - HTTP POST
'''
import json
import urllib2
import base64

BASIC_AUTH = "Basic " + base64.b64encode("admin:admin")
HEADERS = {"Content-type": "application/json","Accept":"application/json","Authorization": BASIC_AUTH}
URL = "http://localhost:2990/jira/rest/jirauserexport/1.0/userproperties"

def create_user_property(user_name, property_key, property_value, url):
    data = json.dumps({
        "username": user_name,
        "userPropertyKey": property_key,
        "userPropertyValue": property_value
    })
    request = urllib2.Request(url, data, HEADERS)
    request.get_method = lambda: "POST"
    try:
        contents = urllib2.urlopen(request).read()
        if contents:
            print contents
    except urllib2.HTTPError as e:
        print e.code


create_user_property(user_name="admin", property_key="mobile", property_value="+4511223344", url=URL)

...

Python 2 code for updating a Jira user property

Code Block
languagepy
themeRDark
linenumberstrue
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
Update user properties for Jira user - HTTP PUT
'''
import json
import urllib2
import base64

BASIC_AUTH = "Basic " + base64.b64encode("admin:admin")
HEADERS = {"Content-type": "application/json","Accept":"application/json","Authorization": BASIC_AUTH}
URL = "http://localhost:2990/jira/rest/jirauserexport/1.0/userproperties"

def update_user_property(user_name, property_key, property_value, url):
    data = json.dumps({
        "username": user_name,
        "userPropertyKey": property_key,
        "userPropertyValue": property_value
    })
    request = urllib2.Request(url, data, HEADERS)
    request.get_method = lambda: "PUT"
    try:
        contents = urllib2.urlopen(request).read()
        if contents:
            print contents
    except urllib2.HTTPError as e:
        print e.code


update_user_property(user_name="admin", property_key="mobile", property_value="+4566996699", url=URL)

...

Python 2 code for deleting a Jira user property

Code Block
languagepy
themeRDark
linenumberstrue
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
Delete user properties for Jira user - HTTP DELETE
'''
import json
import urllib2
import base64

BASIC_AUTH = "Basic " + base64.b64encode("admin:admin")
HEADERS = {"Content-type": "application/json","Accept":"application/json","Authorization": BASIC_AUTH}
URL = "http://localhost:2990/jira/rest/jirauserexport/1.0/userproperties"

def delete_user_property(user_name, property_key, url):
    data = json.dumps({
        "username": user_name,
        "userPropertyKey": property_key
    })
    request = urllib2.Request(url, data, HEADERS)
    request.get_method = lambda: "DELETE"
    try:
        contents = urllib2.urlopen(request).read()
        if contents:
            print contents
    except urllib2.HTTPError as e:
        print e.code


delete_user_property(user_name="admin", property_key="mobile", url=URL)

...