I am trying to using the JIRA REST API to create a ticket (want to incorporate it into an external function to feed to JIRA), specifically through Python (though will use another method if you advise that will work better). One of the example issues I get is that custom_field13500 (Organizations) doesn't accept the input I have as correct, and wants it in an array, however this is an exact copy of an existing tickets value so it is odd I am getting this answer. See the code below and let me know what we need to change or if you have a better way of doing this:
import requests
from requests.auth import HTTPBasicAuth
import json
url = "https://project_domain.atlassian.net/rest/api/3/issue"
auth = HTTPBasicAuth("<email_address>", "<API_Token>")
headers = {
"Accept": "application/json",
"Content-Type": "application/json"
}
payload = json.dumps({
"fields": {
"project": {
"id": "21489"
},
"summary": "TEST Ticket via API with certain fields",
"issuetype": {
"id": "11152"
},
"priority": {
"id": "3"
},
"assignee": {
"id": "62d536279189e98a2017cf94"
},
"description": {
"type": "doc",
"version": 1,
"content": [
{
"type": "paragraph",
"content": [
{
"text": "This is a test ticket created via API.",
"type": "text"
}
]
}
]
},
"customfield_13500": [
{
"id": "122",
"name": "RJ Test Organisation Ltd",
"created": {
"iso8601": "2024-10-28T17:23:22+0000",
"jira": "2024-10-28T17:23:22.928+0000",
"friendly": "28/Oct/24 5:23 PM",
"epochMillis": 1730136202928
},
"_links": {
"self": "https://project_domain.atlassian.net/rest/servicedeskapi/organization/122"
}
}
],
"customfield_14601": {
"id": "12201"
},
"customfield_14605": {
"self": "https://project_domain.atlassian.net/rest/api/3/customFieldOption/12278",
"value": "More info required",
"id": "12278"
},
"timetracking": {
"originalEstimate": "10",
"remainingEstimate": "5"
},
"status": {
"id": "10005"
},
"labels": ["API", "test_creation"]
}
})
response = requests.post(url, headers=headers, data=payload, auth=auth)
print(response.status_code)
print(response.json())
response = requests.request(
"POST",
url,
data=payload,
headers=headers,
auth=auth
)
print(json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": ")))