Error creating a new project using Java Jira API

ing.eln94@gmail.com November 25, 2018

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
sthumulati November 2, 2019

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

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 25, 2018

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

ing.eln94@gmail.com November 25, 2018

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?

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 25, 2018

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

ing.eln94@gmail.com November 25, 2018

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

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 25, 2018

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

ing.eln94@gmail.com November 25, 2018

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?

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 25, 2018

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

0 votes
Ismael Jimoh
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 25, 2018

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.

Suggest an answer

Log in or Sign up to answer