go-jira
go-jira copied to clipboard
Issue Creation Failed --: Request failed. Please analyze the request body for more details. Status code: 400
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??
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.
same problem, the jira server version is v8.20.6, the go-jira version is v1.15.0.
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. ;)
@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",
},
}
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.
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.
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.
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 https://github.com/andygrunwald/go-jira/issues/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!