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

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Create project via REST api and copy workflow

Hi guys,

 

im trying to find a way to create projects via the REST api.

i've found the usual: rest/api/2/project PUBLIC api.

 

Sadly i can't find a solution to copy the workflow of another project to also use it for the new project

I've seen some old comments from 2016 that the rest api doesnt support this function, is it still that case ?

 

Has anybody found a workaround?

Has somebody done this with another api already or with scriptrunner?

3 answers

1 accepted

0 votes
Answer accepted
Antoine Berry Community Leader Apr 12, 2019

Hi @Marvin Schmidtke ,

Talking about scriptrunner, I have not done it with workflows but with issue types. Looking at the documentation, something like : 

Project sourceProject = ComponentAccessor.getProjectManager().getProjectObjByKey("source-project");
Project targetProject = ComponentAccessor.getProjectManager().getProjectObjByKey("target-project");
def workflowSchemeManager = ComponentAccessor.getWorkflowSchemeManager()
def sourceWorkflowScheme = workflowSchemeManager.getWorkflowSchemeObj(sourceProject)

workflowSchemeManager.addSchemeToProject(targetProject, sourceWorkflowScheme)

could work.

Antoine

Antoine Berry Community Leader Apr 16, 2019

Hi @Marvin Schmidtke ,

Did that help ?

I found that this answer has been asked and answered elsewhere.  Stackoverflow is awesome.

Anyway, I'll post my solution here.  First and foremost we assume that you know how to login and get websudo privileges.  It's needed.  Or this won't work.

2nd, I assume you know how to setup your own ApacheHttpClient or whatever you want to use.  So we won't go there.  And I assume you know how to serialize and deserialize objects to/from JSON.  

And, I'll apologize...I'm 60 years old and don't work with JSON.  I work with POJO's.  And lumbok and gson are my friends.  And, I am not going to post my 50 POJO's..  Assume all POJO's are JSON.

Anyway:

// This is the pid of MY template.  Not yours.  Change to your template
private
static final int TEMPLATE_ARTIFACT_SCRUM = 10457;

// Create a project creation request for use with the createshared API
JiraProjectCreateTemplateRequest
template = new JiraProjectCreateTemplateRequest();
template.setKey(key);
template.setName(name);
template.setLead(admins[0]);

JiraProject jp = createProjectWithTemplate(template, TEMPLATE_ARTIFACT_SCRUM);
// create a project from a template or Shared Configuration project
public
JiraProject createProjectWithTemplate(JiraProjectCreateTemplateRequest request, int template) throws HttpRequestException {
String path = String.format("/rest/project-templates/1.0/createshared/%d", template);
JiraProjectCreateTemplateResponse response = post(path, request, JiraProjectCreateTemplateResponse.class);
if (response == null)
throw new HttpRequestException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "Project not created");
return getProject(response.getProjectKey());
}

 The 'post' method in this function is my little wrapper to deserialize and serialize POJO's.  The POJO for the response is:

@Data
public class JiraProjectCreateTemplateResponse implements Serializable {

String returnUrl;
int projectId;
String projectKey;
String projectName;
JiraRemoteProjectLinks remoteProjectLinks;
}

 In the end, this works for me because this is how I create projects in the GUI anyway.

Enjoy,

I cannot find the answer either.  

There is the REST api using the com.pyxis.greenhopper.jira:gh-scrum-template default template as the projectTemplateKey.

But, doesn't appear that you can specify anything else.

So, I'm abandoning the REST API and will simply use the form POST as done from the GUI.

I've just decided to do this.  So, if you found another answer, let me know.  Else, I'll post my final code once I get it working (need to dive into Javascript...)

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Apps & Integrations

🍻🍂Apptoberfest Update: Upcoming Virtual Events 🎉

Hello Community! I hope you've been enjoying the 🍂Apptoberfestivities🍂 (I know I have!) The event is heating up next week with a series of virtual events that we're calling the 🍻🍂Partner App ...

354 views 3 14
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you