How to get list of all Jira server fields (system and custom) via REST-API

Use curl in a Linux Bash script:

#!/bin/bash

admin_user=fu
admin_password=bar
jira_server="https://jira.acme.com"
api_version=2
url_part2="/rest/api/${api_version}/field"

curl -k -u ${admin_user}:${admin_password} -X GET -H "Accept: application/json" ${jira_server}${url_part2} \
| jq '.' > raw_file.json

# Extract field names, remove double quotes, sort

cat raw_file.json | jq '.[].name' | sed 's/"//g' | sort > nice_file.txt

 

Note: There is a separate REST-API to get only custom fields, but it's not working for me at this time. I will update once I find a solution.

Updates

1. The REST-API for Jira Server does not support getting only the custom fields.

Your recourse is to check the "id" key in the JSON (the file raw_file.json). If the value is "customfield_nnnnn", it's a custom field. Or, even simpler, you can check the key "custom" which is "true" for custom fields.

2. When you view the fields in the Jira UI

    https://jira.acme.com/secure/admin/ViewCustomFields.jspa

there may be fields which are marked Not configured for any context under the Available context(s) column.

I've found out that the REST-API call does not retrieve these fields.

1 comment

Suddha
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 29, 2020

Recently came across this requirement and taking hint from this script, was able to extract just the custom fields:

Hope that helps:

#!/bin/bash
# small script to CSV export Custom Fields
# Author: Mr. Doubt Everyhim
# Date: 2020-09-22
#
#
#
admin_user=foo
admin_password=bar
jira_server="http://localhost:8854/j854"
url_part2="/rest/api/2/field"

# Get all the fields:
curl -k -u ${admin_user}:${admin_password} -X GET -H "Accept: application/json" ${jira_server}${url_part2} \
 | jq '.' > raw_file.json
# Create to_entries:
cat raw_file.json| jq 'to_entries' > raw_key_entry.json
# Extract keys:
cat raw_key_entry.json | grep -B2 customfield_ | grep key | awk '{print $2}' | sed 's/,//g' > key_entries.txt 
# Extract ID, Name, Field Types:
for i in $(cat key_entries.txt); do
  cat raw_file.json | jq -r "[.[$i].id, .[$i].name, .[$i].schema.custom] |@csv" >> CF_details.csv
done
echo "Results are printed in: ./CF_details.csv"
Like Amir Katz (Outseer) likes this

Comment

Log in or Sign up to comment
TAGS
AUG Leaders

Atlassian Community Events