Forums

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

Creating a sub-task using python: "description" field and error 400

Andrea September 10, 2023

Hi all,

I have the following code that works perfectly:

# Answers inputs
def call_Jira_api(JIRA_USERNAME, JIRA_API_TOKEN, parent_issue_key, subtask_summary, JIRA_API_URL):
# Set the headers for the request
headers = {
"Accept": "application/json",
"Content-Type": "application/json"
}

# Authentication headers
auth_headers = (JIRA_USERNAME, JIRA_API_TOKEN)

# Define the JSON payload for creating the subtask
subtask_data = {
"fields": {
"project": {
"key": "ATDC" # Replace with the appropriate project key
},
"parent": {
"key": parent_issue_key # Replace with the appropriate parent issue key
},
"summary": subtask_summary,
"issuetype": {
"name": "Sub-task", # You can specify the appropriate subtask type
},
}
}


# Send the POST request to create the subtask
response = requests.post(f"{JIRA_API_URL}/issue", headers=headers, auth=auth_headers, json=subtask_data)

# Check the response status
if response.status_code == 201:
subtask_info = response.json()
return (f"Subtask created with key: https://lightchainventures.atlassian.net/browse/{subtask_info['key']}")
else:
return(f"Failed to create subtask. Status code: {response.status_code}")

However, if I try to add the field "description" to subtask_data

subtask_data = {
"fields": {
"project": {
"key": "ATDC" # Replace with the appropriate project key
},
"parent": {
"key": parent_issue_key # Replace with the appropriate parent issue key
},
"summary": subtask_summary,

"description": "Test",
"issuetype": {
"name": "Sub-task", # You can specify the appropriate subtask type
},
}
}

 

I get an error 400.

 

I am rather confused. Does anyone know why this is happening?

1 answer

0 votes
Andrea September 10, 2023

This is the solution:

subtask_data = {
"fields": {
"project": {
"key": "ATDC" # Replace with the appropriate project key
},
"parent": {
"key": parent_issue_key # Replace with the appropriate parent issue key
},
"summary": subtask_title,
"issuetype": {
"name": "Sub-task", # You can specify the appropriate subtask type
},
"description": {
"type": "doc",
"version": 1,
"content": [

{
"type": "paragraph",
"content": [

{
"type": "text",
"text": "Test",
}

]
}
]
}
}
}

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events