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.
×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!
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.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 →
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.