Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Custom Fields with Jira API

Gareth
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 1, 2021

Hi all

This is my first time posting on this community.

I am new to APIs and so far I have managed to get my script to pull the information I need relating to a project, what I am slightly stuck over is how to return the values from custom fields within my script.

This is the script in Python

import requests
import json
import base64

# Security - Base encode email and api token
cred = "Basic " + base64.b64encode(b'***********:**************').decode("utf-8")
# Set header parameters
headers = {
"Accept": "application/json",
"Content-Type": "application/json",
"Authorization" : cred
}

# Project Key
projectKey = "AD"

# Link to my site URL
url = "https://**************/rest/api/3/search?jql=project=" + projectKey

# Request and Response
response = requests.request(
"GET",
url,
headers=headers
)

# Decode Json string to Python
json_data = json.loads(response.text)

# Display issues and selected fields
for item in json_data["issues"]:
print(item["id"] + "\t" + item["key"] + "\t" +
item["fields"]["issuetype"]["name"] + "\t" +
item["fields"]["created"]+ "\t" +
item["fields"]["creator"]["displayName"] + "\t" +
item["fields"]["status"]["name"] + "\t" +
item["fields"]["summary"] + "\t"
)

In the display issues and selected fields, how can I get it to return values from specific Custom Fields?

 

thanks

Gareth

1 answer

3 votes
Tuncay Senturk _Snapbytes_
Community Champion
October 2, 2021

Hi @Gareth 

Welcome to the community!

You can get custom field value by using the custom field id as below.

item["fields"]["customfield_10010"]

Here 10010 is the id of the custom field, you need to get the id values for the specific custom fields.

Please bear in mind that every custom field might have a different response type, e.g. string, number, date, or complex types like array, list, etc. Just check your response JSON to spot those values and update your code accordingly.

Hope it helps

Tuncay

Gareth
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 3, 2021

Thank you Tuncay, works great.

As you mentioned had to update my code to handle the various data types, all working and thanks again for the advice.

 

gareth

Tuncay Senturk _Snapbytes_
Community Champion
October 3, 2021

Perfect, I'm glad that it helped.

Could you please accept the answer so that the request seems as resolved?

Thanks

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events