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.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.