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

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

Open
carljthompson opened this issue Feb 14, 2019 · 17 comments
Labels
help wanted needs triage Ticket that needs triage (a proper look for classification) v2
Milestone

Comments

@carljthompson
Copy link

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?

@andygrunwald
Copy link
Owner

@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?

@ghostsquad
Copy link
Contributor

@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
Copy link
Contributor

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

@andygrunwald
Copy link
Owner

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

@ghostsquad
Copy link
Contributor

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

@andygrunwald
Copy link
Owner

@ghostsquad Maybe something like this? #196

@OstaninKI
Copy link

OstaninKI commented Apr 8, 2019

@carljthompson did you solve this problem?

@yocally
Copy link

yocally commented Jul 8, 2019

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
Copy link

yocally commented Jul 10, 2019

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.

@wvell
Copy link
Contributor

wvell commented Aug 28, 2019

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"}]}}

@ghostsquad ghostsquad added the v2 label Dec 7, 2019
@ghostsquad
Copy link
Contributor

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

@wkoszek
Copy link

wkoszek commented Aug 19, 2020

@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.

@andygrunwald andygrunwald reopened this Aug 19, 2020
@andygrunwald
Copy link
Owner

Reopened to get the v2 visibility.

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

@wkoszek
Copy link

wkoszek commented Aug 19, 2020

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

@andygrunwald
Copy link
Owner

@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?

@wkoszek
Copy link

wkoszek commented Sep 5, 2020

@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 (go-jira/jira#369) appears to work.

Feel free to close this issue.

@andygrunwald andygrunwald added the needs triage Ticket that needs triage (a proper look for classification) label Aug 20, 2022
@andygrunwald andygrunwald added this to the Road to v2 milestone Aug 21, 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
help wanted needs triage Ticket that needs triage (a proper look for classification) v2
Projects
None yet
Development

No branches or pull requests

7 participants