go-jira icon indicating copy to clipboard operation
go-jira copied to clipboard

IssueUpdate -- Issue error occured: Request failed. Please analyze the request body for more details. Status code: 400

Open carljthompson opened this issue 6 years ago • 17 comments

I successfully connected to our JIRA instance and pulled in the details of an issue. I am trying to just add a label to an existing issue using IssueUpdate. I couldn't find a good example. I did drill into the code (issue.go | UpdateIssue ) and see the JIRA link (https://docs.atlassian.com/jira/REST/7.4.0/#api/2/issue-editIssue)

Here is the code I am using:

package main

import ( "fmt" "github.com/andygrunwald/go-jira" )

func main() {

base := "https://<ourJIRAserver>"
tp :=  jira.BasicAuthTransport {
	Username: "<username>",
	Password: "<token>",
}

jiraClient, err := jira.NewClient(tp.Client(), base)
if err != nil {
	fmt.Println("An error occured: ", err.Error())		
}

l := make(map[string]interface{})
l["update"] = `{ "update": { "labels": [ { "add": "cjt_test_label" } ] } }`
_, err = jiraClient.Issue.UpdateIssue("BLAH-3001",l)
if err != nil {
	fmt.Println("Issue error occured: ", err.Error())
}

}

I receive the following error every time Issue error occured: Request failed. Please analyze the request body for more details. Status code: 400

My JIRA system account has administrator privileges.

Could you give me a good example or assist me if there is a bug in IssueUpdate pertaining to labels?

carljthompson avatar Feb 14 '19 14:02 carljthompson

@carljthompson Hey, thanks for the issue. Sadly I don't have a lot of time right now. Because of this, I won't be able to take care of this soon. Is someone from the community able to help here?

andygrunwald avatar Feb 26 '19 14:02 andygrunwald

@carljthompson you are ignoring the response here:

_, err = jiraClient.Issue.UpdateIssue("BLAH-3001",l)

that _ is the response. Read the body to get more information.

ghostsquad avatar Mar 29 '19 22:03 ghostsquad

body, _ := ioutil.ReadAll(resp.Body)
fmt.Println(string(body))

ghostsquad avatar Mar 29 '19 22:03 ghostsquad

Thanks @ghostsquad, do you think it makes sense to add this to the README as troubleshooting?

andygrunwald avatar Mar 30 '19 08:03 andygrunwald

@andygrunwald I think the error should be useful. ;)

ghostsquad avatar Mar 30 '19 15:03 ghostsquad

@ghostsquad Maybe something like this? https://github.com/andygrunwald/go-jira/pull/196

andygrunwald avatar Mar 31 '19 15:03 andygrunwald

@carljthompson did you solve this problem?

OstaninKI avatar Apr 08 '19 09:04 OstaninKI

I'm having what looks like the same issue.

        l := make(map[string]interface{})
        l["update"] = `{"components":[{"set":""}]}`
        resp, err := client.Issue.UpdateIssue("FOO-7573", l)
        lines, _ := ioutil.ReadAll(resp.Body)
        println(string(lines))

That code produces the following error:

{"errorMessages":["Can not instantiate value of type [map type; class java.util.LinkedHashMap, [simple type, class java.lang.String] -> [collection type; class java.util.List, contains [simple type, class com.atlassian.jira.rest.api.issue.FieldOperation]]] from JSON String; no single-String constructor/factory method (through reference chain: com.atlassian.jira.rest.v2.issue.IssueUpdateBean[\"update\"])"]}

with an http status of 400, so I get the feeling that I'm formatting the map incorrectly.

yocally avatar Jul 08 '19 13:07 yocally

I ended up just using NewRawRequest and it worked nicely.

        req, err := jclient.NewRawRequest("PUT", "rest/api/2/issue/FOO-7594", bytes.NewBufferString(`{"update":{"components":[{"add":{"name":"BAR"}}]}}`))
        req.Header.Set("Content-type", "application/json")
        jclient.Do(req, nil)

Refer to jira docs for more info. It's not really an answer but it works for me, just posting in case somebody else was having trouble.

yocally avatar Jul 10 '19 19:07 yocally

I think the problem is that you are mixing string and object. @carljthompson your example will result in the following json: {"update":"{ \"update\": { \"labels\": [ { \"add\": \"cjt_test_label\" } ] } }"} see: https://play.golang.org/p/DW2LpYFulfL

The proper way is to use objects see https://play.golang.org/p/FEX-q6er4gF this will produce the following json: {"update":{"duedate":[{"set":"2019-08-29"}],"labels":[{"add":"test1"},{"add":"test2"}]}}

wvell avatar Aug 28 '19 13:08 wvell

I'm closing this issue, but labeling it as a reminder for v2 ideas. I think error reporting could be improved.

ghostsquad avatar Dec 07 '19 23:12 ghostsquad

@ghostsquad I'm hitting the same error on login. Why is this issue closed? It looks like a simple error reporting fix would help with debugging a whole lot.

wkoszek avatar Aug 19 '20 16:08 wkoszek

Reopened to get the v2 visibility.

@wkoszek Would you be open to create a PR and give it a try?

andygrunwald avatar Aug 19 '20 17:08 andygrunwald

@andygrunwald https://pastebin.com/CKG9R2tH <- do you know how to workaround this Golang issue?

wkoszek avatar Aug 19 '20 17:08 wkoszek

@wkoszek Never had this case. A quick searched looked like replacing is the way to go, see https://starkandwayne.com/blog/switching-to-go-modules/#using-forks-and-branches and https://stackoverflow.com/questions/56671133/how-to-use-a-forked-module-with-versioned-go-modules-v1-11-go111module-on

Sounds scary and seems to be a hack, somehow. Maybe this can worth a try?

andygrunwald avatar Aug 19 '20 17:08 andygrunwald

@andygrunwald I looked at the code. I attempted to make a fix by simply carrying 'error' value up in the stack to the top layers of the code. Unfortunately a bunch of unit tests failed, because there are places in the code where you create your own error messages.

In the meantime, I've switched to https://github.com/go-jira/jira which after solving some hiccups (https://github.com/go-jira/jira/issues/369) appears to work.

Feel free to close this issue.

wkoszek avatar Sep 05 '20 03:09 wkoszek

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!

andygrunwald avatar Aug 21 '22 14:08 andygrunwald