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

Error creating a new project using Java Jira API

Hello,

I am trying to create a new project in Jira cloud using Java Jira Rest API but it gives me an error: Exception in thread "main" java.lang.NoSuchFieldError: INSTANCE.

I have removed the older versions of http client from my classpath but nothing changes.

Can anyone help me to find out where is the problem or any other sample code that works for create a new project in jira?

Note: I have used Basic Authentication:

Username: My email adress

Pasword: My Jira account pasword

In the attach there are the code that I have used, the error it produces and the jars.jars.PNG

code 1.PNGcode 2.PNGconsole.PNG

3 answers

0 votes

Hi,

 

Are you using JIRA Server or JIRA Cloud?

If yes, I would suggest using REST API instead: https://developer.atlassian.com/cloud/jira/platform/rest/v3/#api-api-3-project-post

I do not know if the JAVA API works with JIRA Cloud.

Regards.

 

---Update---

Just saw you are calling the rest api over Java, may I ask why and why you are not using a simple curl to test first?

Let's start from there and confirm you have this working correctly and not throwing an error. 

I have not tested from Java and would need to look at this further.

0 votes

Your code is feeding your Jira instance a field that does not exist.  Try not sending that pointlessly, it should work fine then.

I am using another sample code to cretate a project:

try {

Client client = Client.create();
client.addFilter(new HTTPBasicAuthFilter("ing.eln94@gmail.com", "1M3GaUNXMVIpsRdrWq3p011B"));
WebResource webResource = client.resource("https://aplikim.atlassian.net/rest/api/2/project");
String input="{\"key\": \"EX\",\"name\": \"Example\",\"projectTypeKey\": \"business\", \"projectTemplateKey\": \"com.atlassian.jira-core-project-templates:jira-core-simplified-project-management\",\"description\": \"Example Project description\", \"lead\": \"ing.eln94@gmail.com\", \"url\": \"https://atlassian.com\",\"assigneeType\":\"PROJECT_LEAD\",\"avatarId\":10200}" ;
ClientResponse response = webResource.type("application/json").post(ClientResponse.class, input);

String output = response.getEntity(String.class);

System.out.println("Output from Server .... \n");
System.out.println(output);

} catch (Exception e) {
System.out.println("oii");
e.printStackTrace();

}

 

 

 

but it gives me the output:

loii.PNG

I have specified the projectLead: \"lead\": \"ing.eln94@gmail.com\".

 

Can you help me to find out the problem?

You need to give the lead as a user id, not an email address

You mean username?

lead.PNG

For example, as shown in the image I have created some projects and I am the leader.

When I use : \"lead\": \"Ing\"  it gives me the same error 

loii.PNG

So "Ing" is not the username, or if it is, it's someone who can't be set as a project lead.

But "Ing" is the admin and when I create a project manually by using the Create New Project button in Jira it creates succesfully. I want to use Java code because I want to create multiple projects. So where is the problem?

The problem is that you're not giving it a valid user for the project lead.

0 votes

Try the username. Its under the Profile Summary of your account.

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in Jira

Demo Den Ep. 7: New Jira Cloud Reports

Learn how to use two new reports for next-gen projects in Jira Cloud:  Cumulative flow diagram and Sprint burndown chart. Ivan Teong, Product Manager, Jira Software, demos the Cumulative ...

302 views 1 3
Join discussion

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