andygrunwald / go-jira

Go client library for Atlassian Jira
https://pkg.go.dev/github.com/andygrunwald/go-jira?tab=doc
MIT License
1.44k stars 458 forks source link

PUT request fails even though json is correct #632

Open rasmusolssony opened 1 year ago

rasmusolssony commented 1 year ago
    var s strings.Builder
    fmt.Fprintf(&s, `{"fields": {"customfield_11702": "%s"}}`, *targetVersion)
    data := s.String()
    req, err := client.NewRequest("PUT", "rest/api/latest/issue/ACCCONTROL-12365", data)

Im trying to do a simple PUT request but even though my json is correct it says there is something wrong with the body.

andygrunwald commented 1 year ago

Hey @rasmusolssony, Why was this issue closed already? Did you find the solution to it? Would be cool if you could share your solution with the community.

rasmusolssony commented 1 year ago

I finally got it to work using this solution:

    var s strings.Builder
    fmt.Fprintf(&s, `{"fields": {"customfield_11702": "%s"}}`, *targetVersion)
    var data = strings.NewReader(s.String())

    req, err := client.NewRawRequest(http.MethodPut, url, data)

But I never got the NewRequest method to work and I'm not sure why the code in my original post didn't work either. Maybe an example or more detailed documentation about what type and format you are supposed to use could be handy.

andygrunwald commented 1 year ago

Thx. I will ensure to write something in the docs.