Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Correct formatting to Create Project using REST API in Scriptrunner

Robert Wen_Cprime_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 27, 2021

I'm trying to create a script that creates a project as a post-function in Scriptrunner Cloud.  I'm using the REST API, but I'm getting 400 errors because of some minor change I need to do.  Code snippet is below.  What am I missing?

def result = post("/rest/api/2/project")
.header('Content-Type', 'application/json')
.body([
key: newProjectKey,
name: newProjectName,
projectTypeKey: newProjectTypeKey,
projectTemplateKey: newProjectTemplateKey,
leadAccountId: newLeadAccountId
])
.asObject(Map)
if (result.status == 201) {
return 'Success'
} else {
return "${result.status}: ${result.body}"
}

 What am I missing?  Thanks in advance!

2 answers

0 votes
Max Lim _Adaptavist_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 11, 2021

I can confirm the Rest API you used is correct. Perhaps, you want to programmatically retrieve the account id with email like so:

def newLead = get("/rest/api/3/user/search")
.header('Content-Type', 'application/json')
.queryString("query", "xxx@example.com")
.asObject(List)
.body
.first() as Map

def result = post("/rest/api/2/project")
.header('Content-Type', 'application/json')
.body([
key: newProjectKey,
name: newProjectName,
projectTypeKey: newProjectTypeKey,
projectTemplateKey: newProjectTemplateKey,
leadAccountId: newLead.accountId
])
.asObject(Map)

if (result.status == 201) {
return 'Success'
} else {
return "${result.status}: ${result.body}"
}

This community question also discuss finding account id for your own account.

0 votes
Robert Wen_Cprime_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 27, 2021

I think the main problem is leadAccountId.  I'm not using the correct format.  I think I have to use dot notation to get at accountId inside the field.

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, atlassian community, journeys for jira service management, journeys for jsm, eap jsm atlassian, early access program atlassian, early access program journeys atlassian, early access program journeys jira service management, join atlassian eap

Join the Early Access Program (EAP) - Journeys for Jira Service Management 🚪

Journeys is a brand new feature in Jira Service Management that helps you streamline various processes in your organization that may cross multiple departments, such as employee onboarding or off-boarding that require action from different teams. ✨

Join the EAP →
AUG Leaders

Upcoming Jira Service Management Events