Forums

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

I am trying to create a project using python, but I am getting payload error

Nawar Noorudeen December 28, 2023

This is my code:

import requests
from requests.auth import HTTPBasicAuth

# Jira API details
jira_url = "xxx"  # Replace with your Jira URL
email = "xxx"  # Use your Jira email address
api_token = "xxx"  # Use your API token

# Project details
project_key = "EX"
project_name = "Test Project"

# Jira REST API endpoint for project creation
api_url = f"{jira_url}/rest/api/2/project"

# JSON payload for creating a new project
payload = {
    "key": project_key,
    "name": project_name,
    "projectTypeKey": "business",
    "projectTemplateKey": "com.atlassian.jira-core-project-templates:jira-core-simplified-process",
    
}
print(payload)

# Headers for the request
headers = {
    "Content-Type": "application/json",
}

# Make the API call
response = requests.post(
    api_url,
    auth=HTTPBasicAuth(email, api_token),
    json=payload,
    headers=headers,
)

# Check the response status
if response.status_code == 201:
    print(f"Jira project '{project_name}' created successfully!")
else:
    print(f"Failed to create Jira project. Status code: {response.status_code}")
    print("Response content:")
    print(response.text)
I am getting the following error:  
{'key': 'EX', 'name': 'Test Project', 'projectTypeKey': 'business', 'projectTemplateKey': 'com.atlassian.jira-core-project-templates:jira-core-simplified-process'}
Failed to create Jira project. Status code: 400
Response content:
{"errorMessages":["The project template specified does not exist. Make sure the project template is available in your Jira instance. Please talk to your Jira administrator if you need more help."],"errors":{"projectLead":"You must specify a valid project lead."}}

1 answer

1 accepted

0 votes
Answer accepted
Jehan Bhathena
Community Champion
December 30, 2023

Hi @Nawar Noorudeen ,

I'm not a Python expert, but from the error shown I would suggest making the below changes:

Hope this helps.

Nawar Noorudeen January 2, 2024

Hello @Jehan Bhathena Thanks for getting back to me. I figured out that was the issue and I am able to create the project. Now I am trying to add users to the created project. Any recommendations?

Jehan Bhathena
Community Champion
January 2, 2024

Glad to know the response worked out for you.

To add a User to a Project role you can try this API :

https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-project-role-actors/#api-rest-api-3-project-projectidorkey-role-id-post.

Would suggest creating a new thread for more questions if you have any more question on this :-)

 

Suggest an answer

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

Atlassian Community Events