Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with example create #69

Open
ypsman opened this issue Apr 17, 2017 · 25 comments
Open

Problem with example create #69

ypsman opened this issue Apr 17, 2017 · 25 comments
Labels
needs triage Ticket that needs triage (a proper look for classification)

Comments

@ypsman
Copy link

ypsman commented Apr 17, 2017

Im trying to Connect with the Example to Jira and creating an Issue.
Getting this as Response
{"errorMessages":[],"errors":{"project":"project is required"}}
panic: runtime error: invalid memory address or nil pointer dereference

go version go1.6.2 linux/amd64
Jira 7.3 & 7.1

Im new to golang so a little hint what to do would be nice :)

@andygrunwald
Copy link
Owner

Hey @ypsman,
can you please post your complete code here? Without the source code it is hard to follow. Thanks.

@ypsman
Copy link
Author

ypsman commented Apr 17, 2017


import (
	"fmt"

	"github.com/andygrunwald/go-jira"
)

func main() {
	jiraClient, err := jira.NewClient(nil, "https://myjira.de/")
	if err != nil {
		panic(err)
	}

	res, err := jiraClient.Authentication.AcquireSessionCookie("APIuser", "pass")
	if err != nil || res == false {
		fmt.Printf("Result: %v\n", res)
		panic(err)
	}

	i := jira.Issue{
		Fields: &jira.IssueFields{
			Assignee: &jira.User{
				Name: "myname",
			},
			Reporter: &jira.User{
				Name: "APIuser",
			},
			Description: "Test Issue",
			Type: jira.IssueType{
				ID: "60",
			},
			Project: jira.Project{
				Name: "APITEST",
			},
			Summary: "Just a demo issue",
		},
	}

	issue, _, err := jiraClient.Issue.Create(&i)

	if err != nil {
		panic(err)
	}

	fmt.Printf("%s: %+v\n", issue.Key, issue.Fields.Summary)
}

its just like the Example.
I used it in another Project, that didnt work, so i tryd it in a single File.
Search for Issues Works.

@andygrunwald
Copy link
Owner

Does the Project APITEST exists?

@ypsman
Copy link
Author

ypsman commented Apr 18, 2017

Yes, the Fields are correct, its work with a Pyton script.

@andygrunwald
Copy link
Owner

Can you may post the Python script as well? With this i might be able to find the difference and maybe we hit a bug.

@ypsman
Copy link
Author

ypsman commented Apr 21, 2017

Its just a simple script with the Jira Module(python3)
I cant post it complete, but heres the class i use for.

from jira import JIRA
from jira.exceptions import JIRAError
class JiraAPI:
    def __init__(self):
        try:
            self.api = JIRA(jiraserver, basic_auth=(jiraauth))
        except JIRAError as e:
            print("Exit Code: " + e.status_code)
            sys.exit()

def ticket_create(self):
    self.ticket = {
                    'project' : self.Project,
                    'summary' : self.ticket_summary,
                    'issuetype' : { 'name' : 'Aufgabe' },
                    'description' : self.description,
                    "assignee": { "name": self.assignee }
                }
        JiraAPI().issue_create(self.ticket)

def issue_create(self, myTicket):
        self.api.create_issue(fields=myTicket)


btw, its a german Jira Version, hope this Helps.

@ypsman
Copy link
Author

ypsman commented May 4, 2017

Hi @andygrunwald,

any news, or just a working example for me:)
ty

@yageek
Copy link

yageek commented May 11, 2017

@andygrunwald I also encountered this issue.

If you take a look to the official documentation of JIRA to create an issue (https://developer.atlassian.com/jiradev/jira-apis/jira-rest-apis/jira-rest-api-tutorials/jira-rest-api-example-create-issue), you may have to use something like:

i := jira.Issue{
		Fields: &jira.IssueFields{
			Reporter: &jira.User{
				Name: "username",
			},
			Description: "Description",
			Type: jira.IssueType{
				Name: "Bug",
			},
			Project: jira.Project{
				Key:"PROJECTKEY",
			},
			Summary: "Some summary.",
		},
	}

@ypsman
Copy link
Author

ypsman commented May 11, 2017

@yageek thanks
Now it works, just replaced Name with Key for the Project,
also IssuType needs Name and not ID.

Thank you:)

@ypsman ypsman closed this as completed May 11, 2017
@andygrunwald
Copy link
Owner

Thanks for helping here @yageek!
@ypsman Would you mind to fix the example with a PR?

PS: Sorry to come so late to the game.

@ypsman
Copy link
Author

ypsman commented May 11, 2017

@andygrunwald
Sure :)
#74

@andygrunwald
Copy link
Owner

Merged :)
Thank you all

@vbisbest
Copy link

I have a similar issue with Reporter. Using any but the AccountID as the value fails to create the ticket with:
"{"errorMessages":[],"errors":{"reporter":"Reporter is required."}}"

Ideas?

@tuckyapps
Copy link

@andygrunwald Hey, great project by the way! I am having the same issue as @vbisbest with the reporter, is there any fix coming soon? Thanks!

@benjivesterby
Copy link
Contributor

@tuckyapps this is an open source project and those of us maintainers work on these issues as we're able. You're welcome to submit a PR to update the example so that it is correct and I'll review it. Otherwise, if you need production support you're welcome to reach out to the maintainers and see if they're available for contracted support.

@manuelbcd
Copy link
Contributor

@vbisbest @tuckyapps would you be so kind to specify jira version and type? Maybe I can bear a hand here
Best.

@andygrunwald
Copy link
Owner

Hey @tuckyapps and @vbisbest,
as @benjivesterby wrote, we, as maintainers, do not have the time that we would love to spend on this project, due to our work, family, and other obligations. We would ask you and others to provide an understanding of this.

What would be helpful are a few information about your setup, like:

  • go-jira version (git tag or sha):
  • Go version (go version):
  • Jira version:
  • Jira type (cloud or on-premise):
  • Involved Jira plugins:
  • Operating System and version:

If you need support in a timely manner incl. support, please reach out to me.
I am able to offer contractual support including feature and bug development for this.

PS: Thanks @benjivesterby and @manuelbcd for your support!
PPS: Reopening, because it seems that this is still an issue.

@andygrunwald andygrunwald reopened this Apr 16, 2021
@tuckyapps
Copy link

tuckyapps commented Apr 16, 2021

Hi @andygrunwald @manuelbcd @benjivesterby ,

Thanks again, didn't mean it in a bad way.

  • go-jira version was the last release.
  • Jira is Cloud.
  • System is Mac OS Big Sur.

I am not using the library because only to solve a specific need and I decided to go for Jira API this time.

In case it helps, this is the code I am using that is working:

// createJiraIssue is the function used to create a Jira issue.
func createJiraIssue(jiraNotification *notifications.Notification) error {
	jiraSite := jiraNotification.JiraSite
	jiraLoginEmail := jiraNotification.JiraLoginEmail
	jiraLoginToken := jiraNotification.JiraToken

	vulnDescription := jiraNotification.VulnerabilityDescription
	vulnPOC := jiraNotification.VulnerabilityProofOfConcept
	vulnCriticality := jiraNotification.VulnerabilityCriticalityDescription
	vulnSolution := jiraNotification.VulnerabilitySolution

	jiraIssue := JiraIssue{}
	jiraIssue.Fields.Project.Key = jiraNotification.JiraProjectKey
	jiraIssue.Fields.Summary = jiraNotification.VulnerabilityName
	jiraIssue.Fields.IssueType.Name = "Bug"
	jiraIssue.Fields.JiraPriority.Name = jiraNotification.VulnerabilityCriticality
	jiraIssue.Fields.Description = jiraNotification.VulnerabilityDescription
	jiraIssue.Fields.Labels = []string{"vulnerability", "strike.sh"}

	client := resty.New()
	resp, err := client.R().SetBasicAuth(jiraLoginEmail, jiraLoginToken).
		SetHeader("Content-Type", "application/json").
		SetBody(jiraIssue).
		Post(fmt.Sprintf("%s/rest/api/2/issue", jiraSite))

	if err != nil || resp.StatusCode() != http.StatusOK && resp.StatusCode() != http.StatusCreated {
		return fmt.Errorf("error creating Jira issue, status code '%v', err '%s', message '%s'", resp.StatusCode(), err, resp)
	}

	return nil
}

Again, great project, thank you for helping the community.

Cheers,

Santi

@manuelbcd
Copy link
Contributor

Let me shed some light on this (if I understood the problem properly).

@tuckyapps, @vbisbest you said you are unable to create issues when specifying reporter, using any username but accountID

That is right since Jira cloud abandoned usernames (please have a look to official article https://confluence.atlassian.com/cloud/blog/2018/06/say-goodbye-to-usernames-in-atlassian-cloud )

In short: Jira cloud API is accepting only accountIDs in user-related issue fields. It is not a go-jira library bug.

I hope it will help you.

@andygrunwald , @benjivesterby : then the question is... do you want to change the examples to specify accountID instead of username since username is no longer accepted by jira-cloud? The accountID is compatible with both on-prem (old/new) and cloud versions. I would be more than happy to prepare and send that PR

manuelbcd added a commit to manuelbcd/go-jira that referenced this issue Apr 17, 2021
…porter by accountID instead of username since it is deprecated in Jira cloud
benjivesterby added a commit that referenced this issue Apr 17, 2021
#69 #373 example/create changed to use accountID intead of username
@tuckyapps
Copy link

@manuelbcd Wow, thank you for your fast response!

Thank you for providing the article. I'm wondering however, why does it works using the API then?

Doesn't make sense, right?

@manuelbcd
Copy link
Contributor

manuelbcd commented Apr 19, 2021

Hey @tuckyapps. Sorry, maybe I did not express myself properly.

username field is not deprecated, it is a valid field within user structures in both Jira server and Jira cloud. However, you can't avoid accoundID in Jira cloud anymore (since 2008 due to GDPR compliance). That means you need to specify at least accountID... that makes redundant to specify also username, since accountID is enough and it is valid for both Cloud and Server versions.

Did I clarify your question? If not, please tell it to me, I'm gad to discuss and learn

Best.

@tuckyapps
Copy link

Hi @manuelbcd,

Now I get what you said :)

However, still wondering why it works using the API without the account id.

Best,

Santi

@manuelbcd
Copy link
Contributor

It will work with Jira Server API but not with Jira Cloud API.

If you are communicating with Jira Server API, you will be able to refer to users using only username field.

If you are communicating with Jira Cloud API, you can't refer to users using usernema, you need to use accountID.

But both (Server and Cloud) accepts accountID.

Best.

@tuckyapps
Copy link

Hmm then I don’t get it, as I am using Jira cloud 🤔

@manuelbcd
Copy link
Contributor

If Jira Cloud is allowing you to create issues by specifying username without accountID it is probably because your project has a default assignee and reporter :)

Please perform the folllowing test:
Having user-A as default assignee and user-B as default reporter, try to create an issue indicanting username from user-C (and avoid accountID). If I'm right, this issue will be created ignoring user-C

@andygrunwald andygrunwald added the needs triage Ticket that needs triage (a proper look for classification) label Aug 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage Ticket that needs triage (a proper look for classification)
Projects
None yet
Development

No branches or pull requests

7 participants