Create project with Java API

I’m trying to create a project programmatically.

I found this:

But validation will fail, unless I supply everything:

ProjectCreationData data = new ProjectCreationData.Builder()
					.withAssigneeType(Assignee Type as Long)
					.withAvatarId(Avatar ID as Long)
					.withDescription("Project Desc")
					.withKey("Project Key")
					.withLead("Username of lead")
					.withName("Project Name")
					.withType("Project Type Key")
					.withUrl("Project URL")
					.withProjectTemplateKey("Project Template Key")
					.build();

The problem I have is with the project template. Validation will fail unless I provide an template, but if I provide the default template:

ProjectTemplateManager.getDefaultTemplate();

It will create default issue/workflow/screen schemes along with the project, and I don’t want that.

To create my own template, I found addProjectHook() in:
https://docs.atlassian.com/software/jira/docs/api/8.0.0/com/atlassian/jira/project/template/ProjectTemplate.html

Which in turn requires a ConfigureData class:
https://docs.atlassian.com/software/jira/docs/api/8.0.0/com/atlassian/jira/project/template/hook/ConfigureData.html

The static create() method seems to be what I want, but it requires a Project… before I create the project.

How to programmatically create a project along with the associated issue/workflow/screen schemes, or how to create a project with no schemes attached, then configure the schemes afterwards?

We use this, more or less successfully, at my job today.
https://developer.atlassian.com/server/jira/platform/creating-a-project-template/

The documentation is poor but I can provide examples if needed.

I found out the problem. API doc states that you can either:

  1. Provide project type
  2. Provide project template
  3. Provide both

I provided an incorrect project type object (created one with a String key instead of searching for one), so the API wanted a project template instead.

With only project type and no project template, project is created without any issue/view/workflow schemes attached.

1 Like