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
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Perfect, I'm glad that it helped.
Could you please accept the answer so that the request seems as resolved?
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.