It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

PUT request for jira issue

Tobias Hofer Jan 10, 2012

Im trying to update a field in an issue over REST API. But I always get "MethodNotAllowed" Error when I drop a Put request. GET requests work. Anybody know what I am doing wrong?

4 answers

1 accepted

0 votes
Answer accepted
Rich Manalang Atlassian Team Jan 10, 2012

Before I get into coding against a REST API, I usually try to access the resource through curl or some basic client that I have full control over. Another tool you can try out is the Atlassian REST API Browser. We just installed this on our public JIRA instance. You can access it here: https://jira.atlassian.com/plugins/servlet/restbrowser#/com-atlassian-jira-rest-jira-rest-filter

Make sure you log in first.

Tobias Hofer Jan 11, 2012

thanks. this looks like a good plugin. where can I get it?

It seams to me that the PUT request is not yet implementet as I can not see such a request in the REST Browser for

/issue/{issueIdOrKey}/editmeta

But it is documented in http://docs.atlassian.com/jira/REST/5.0-rc2/#id3419201

Is there an example somewhere how to update a field in an issue over REST

Rich Manalang Atlassian Team Jan 12, 2012

For now, you can install it in UPM with this URL: https://maven.atlassian.com/content/repositories/atlassian-public/com/atlassian/devrel/developer-toolbox-plugin/1.1-rc2/developer-toolbox-plugin-1.1-rc2.jar

We're in the process of adding it to the Plugin Exchange.

Rich Manalang Atlassian Team Jan 12, 2012

Sorry... forgot to answer your question re: editmeta. I don't see a PUT method on editmeta in the documentation:

http://docs.atlassian.com/jira/REST/5.0-rc2/#id3419731

Only a get.

Tobias Hofer Jan 12, 2012

ah yes I just saw. There is a PUT methiod on

/rest/api/2/issue/{issueIdOrKey}

But when I try to update the summery field it sais "bad request". I'm sure Im forming the json wrong. But I can't figure out how. Here is my code:

var request = new RestRequest();

request.RequestFormat = DataFormat.Json;

request.Method = RestSharp.Method.PUT;

request.AddBody(new { summary = "test" });

Tobias Hofer Jan 12, 2012

Im a big step further now but I get this error from jira: errorMessages\":[],\"errors\":{\"summary\":\"Operation value must be a string

code:

var json = new JObject(

new JProperty("update",new JObject(new JProperty("summary",

new JArray(

new JObject(

new JProperty("set","test01" )))))));

var request = new RestRequest();

request.RequestFormat = DataFormat.Json;

request.Method = RestSharp.Method.PUT;

request.AddBody(json);

RestResponse response = client.Execute(request);

string content = response.Content;

Rich Manalang Atlassian Team Jan 12, 2012

Here... try this...

Basically, your PUT should have the following body:

{
  "fields": {
    "summary": "A new summary"
    }
}

Tobias Hofer Jan 15, 2012

Thank you. This works over the REST browser Plugin. But when I send the same string over my c# app i get the following error:

Content = "{\"errorMessages\":[\"Can not deserialize instance of com.atlassian.jira.rest.v2.issue.IssueUpdateBean out of VALUE_STRING token\\n at [Source: org.apache.catalina.connector.CoyoteInputStream@54046d9c; line: 1, column: 1]\"]}"

If I serialize it as a json I get this:

Content = "{\"errorMessages\":[],\"errors\":{\"summary\":\"Operation value must be a string\"}}"

Rich Manalang Atlassian Team Jan 15, 2012

@e3k do you have any way of sniffing the actual request/response the gets sent/received? I'm not a C#'er.

0 votes
Tobias Hofer Jan 10, 2012

var jsonDataSerialize = request.JsonSerializer.Serialize(jsonData);

request.RequestFormat = DataFormat.Json;

request.Method = RestSharp.Method.PUT;

request.AddBody(JSONSharp.Values.JSONStringValue.ToJSONString(@"{""update"": {""summary"": [{""set"": ""Bug in business logic""]}}"));

RestResponse response = client.Execute(request);

string content = response.Content;

0 votes
JamieA Jan 10, 2012

What version? There doesn't seem to be any such method... http://docs.atlassian.com/jira/REST/latest/

POST is the normal verb for updating, but that doesn't seem possible either.

Tobias Hofer Jan 10, 2012

http://docs.atlassian.com/jira/REST/5.0-rc2/#id3419065

I've installed this version. Hoped it would work..

JamieA Jan 10, 2012

Oh, my bad... sorry, not sure then.

0 votes
Tobias Hofer Jan 16, 2012

Thanks for the tipp. It looks like a bug in this third party REST client that I used. It did not send the string correctly. I switched to the basig HTTPRequest and it works now. Thank you

Mark Everest Jun 12, 2012

e3k - would you be prepared to share some of your .NET code?

I am using a WebRequest, but it is failing with an annoying "(400) Bad Request" error.

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Posted in Off-topic

Disney Live Action Reboots: Are you for or against?

Happy Friday Everyone! Today marks the international release of Disney's live action version of the animated classic Aladdin. I know that this movie was met with some controversy of over cast...

139 views 19 8
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you