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

Issue Creation Failed --: Request failed. Please analyze the request body for more details. Status code: 400 #437

Open
ujala-singh opened this issue Feb 6, 2022 · 8 comments
Labels
needs triage Ticket that needs triage (a proper look for classification)

Comments

@ujala-singh
Copy link

ujala-singh commented Feb 6, 2022

I am able to successfully connect to My JIRA cloud and pulled in the details of an issue even transition is also happening of existing tickets. I am trying to just create a new issue with the example provided (https://github.com/andygrunwald/go-jira/blob/master/examples/create/main.go) but it's failing with the error: 2022/02/06 21:38:47 request failed. Please analyze the request body for more details. Status code: 400.

Here is the code I am using:

package main

import (
	"log"
	"os"
	"fmt"
        "github.com/joho/godotenv"
	jira "github.com/andygrunwald/go-jira"
)

func main() {
	// Load the .env file
	godotenv.Load(".env")
	// Create a BasicAuth Transport object
	tp := jira.BasicAuthTransport{
		Username: os.Getenv("JIRA_USER"),
		Password: os.Getenv("JIRA_TOKEN"),
	}
	// Create a new Jira Client
	client, err := jira.NewClient(tp.Client(), os.Getenv("JIRA_URL"))
	if err != nil {
		log.Fatal(err)
	}
        i := jira.Issue{
		Fields: &jira.IssueFields{
			Assignee: &jira.User{
				Name: "[email protected]",
			},
			Reporter: &jira.User{
				Name: os.Getenv("JIRA_USER"),
			},
			Description: "Test Issue",
			Type: jira.IssueType{
				Name: "Task",
			},
			Project: jira.Project{
				Key: "Infra",
			},
			Summary: "Just a demo issue",
		},
	}
	createIssue, _, err := client.Issue.Create(&i)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%s: %+v\n", createIssue.Key, createIssue.Fields.Summary)
}

I receive the following error every time
2022/02/06 21:38:47 request failed. Please analyze the request body for more details. Status code: 400
My JIRA_USER account has administrator privileges. I am using JIRA cloud.

Could you give me a good example or assist me on this? Also possible to get any user's ccountID with this module??

@github-actions
Copy link

github-actions bot commented Feb 6, 2022

Hi! Thank you for taking the time to create your first issue! Really cool to see you here for the first time. Please give us a bit of time to review it.

@HaoKunT
Copy link

HaoKunT commented Feb 21, 2022

same problem, the jira server version is v8.20.6, the go-jira version is v1.15.0.

@eBeyond
Copy link

eBeyond commented Feb 23, 2022

I've hit the same issue yesterday. The solution in my case was to remove the "Reporter"-field. My Jira told me that's set automatically. The errormessage is somewhat misleading. You can reproduce this behaviour when you generate the JSON and push it to JIRA manually. Then there is a proper message. ;)
Hope it helps. ;)

@ujala-singh
Copy link
Author

@eBeyond I am able to create the ticket with this hack. But it doesn't make any sense right, I mean for me now my ticket doesn't have any assignee and my email which is an assignee coming as a reporter now. So technically it's a BUG. I tried with this:

i := jira.Issue{
		Fields: &jira.IssueFields{
			Assignee: &jira.User{
				Name: "[email protected]",
			},
			Description: "Test Issue",
			Type: jira.IssueType{
				Name: "Task",
			},
			Project: jira.Project{
				Key: "Infra",
			},
			Summary: "Just a demo issue",
		},
	}

@TheDarkTrumpet
Copy link

I went by this a bit differently, and I agree this is a bit of a bug going on. Here's my solution, though:

issue := jira.Issue{
		Fields: &jira.IssueFields{
			Description: fmt.Sprintf("{code:text}%s{code}", string(fcontent)),
			Summary:     "Test Issue",
			Project: jira.Project{
				Key: project.Key,
			},
			Type: jira.IssueType{
				Name: "Task",
			},
		},
	}

basicIssue, _, err := ejira.Client.Issue.Create(&issue)
ejira.Client.Issue.UpdateAssignee(basicIssue.ID, me)

What this does for me is I'm correctly identified as the reporter coming in, and after that's done, I assign my user from another call. I have a bit of hardcoded stuff here, but I'm hoping to avoid that long term (e.g. having the name in jira.user hardcoded is not a great idea.

@HaoKunT
Copy link

HaoKunT commented Apr 2, 2022

same problem, the jira server version is v8.20.6, the go-jira version is v1.15.0.

The reason that casue this issue is that I do not have correct permisson. For me, it's only Administrators, RevisionReporter, Reporter can edit reporter field when creating or update issue, but my role is Robot. When I remove reporter field, that's ok.

Jira server will create reporter automatically because we must login to create issue, so Jira will use username as reporter.

I suggest to adjust examples, remove reporter field.

@awinlei
Copy link

awinlei commented Jul 25, 2022

should return more useful info in func :
func (s *IssueService) CreateWithContext(ctx context.Context, issue *Issue) (*Issue, *Response, error)

and
resp, err := s.client.Do(req, nil)
if err != nil {
data, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, resp, fmt.Errorf("could not read the returned data:%v", err)
}

return nil, resp, fmt.Errorf("reson:%s err:%v", data, err)
}

then you will get more error info to fix your params.

@andygrunwald andygrunwald added the needs triage Ticket that needs triage (a proper look for classification) label Aug 20, 2022
@andygrunwald
Copy link
Owner

Hey,

I am very sorry that this issue has been open for a long time with no final solution. We work on this project in our spare time, and sometimes, other priorities take over. This is the typical open source dilemma.

However, there is news: We are kicking off v2 of this library 🚀

To provide visibility, we created the Road to v2 Milestone and calling for your feedback in #489

The development will take some time; however, I hope you can benefit from the changes.
If you seek priority development for your issue + you like to sponsor it, please contact me.

What does this mean for my issue?

We will work on this issue indirectly.
This means that during the development phase, we aim to tackle it.
Maybe in a different way like it is currently handled.
Please understand that this will take a while because we are running this in our spare time.

Final words

Thanks for using this library.
If there is anything else you would like to tell us, let us know!

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

6 participants