if project_response.status_code == 201:
print(f"Jira project '{project_name}' created successfully!")
# Extract the project ID from the project creation response
project_id = project_response.json()["id"]
# Users to be added to the project
users_to_add = ["xxx"] # Add the usernames you want to add
# Jira REST API endpoint for adding users to a project role
role_id = "10195" # Replace with the appropriate role ID
add_users_url = f"{jira_url}/rest/api/3/project/{project_key}/role/{role_id}"
# JSON payload for adding users to the project role
users_payload = {
"usernames": users_to_add
}
# Headers for the add users request
users_headers = {
"Content-Type": "application/json",
"Accept": "application/json"
}
# Make the API call to add users to the project role
users_response = requests.post(
add_users_url,
auth=HTTPBasicAuth(email, api_token),
json=users_payload,
headers=users_headers,
)
# Check the response status for adding users
if users_response.status_code == 204:
print("Users added to the project successfully!")
else:
print(f"Failed to add users to the project. Status code: {users_response.status_code}")
print("Response content:")
print(users_response.text)
else:
print(f"Failed to create Jira project. Status code: {project_response.status_code}")
print("Response content:")
print(project_response.text)
The error I am recieving:
Response content:
{"errorMessages":["Invalid request payload. Refer to the REST API documentation and try again."]}