Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

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

Failing with jQuery PUT and POST to JIRA REST API from Confluence Edited

The Confluence and JIRA are connected with an application link. (servers)

Developing Built in Macros for confluence.

jQuery GET works fine, PUT and POST fails with 400.

I succeed with similar call from postman.

Permissions, logins - everything checked.

I know that there are plugins to solve this, but then I loose control of exact behavior.

Example code - trying to modify an issue summary in JIRA

var theurl = encodeURI(confbase + "/plugins/servlet/applinks/proxy?appId=" + confproxy +"&path=" + jirabase + "/rest/api/latest/issue/SP-4");

var thePost = JSON.parse('{ "update": { "summary": [{ "set": "Modified Summary 2" } ] } }');

var jqxhr = jQuery.ajax({
type: "PUT",
url: theurl,
dataType: 'json',
data: JSON.stringify(thePost),
cache:false,
async: false
}).done(function (response) {
alert("Success");
}).fail(function(jqxhr, textStatus, errorThrown) {
var contentType = jqxhr.getResponseHeader("Content-Type");
var responseBody = jqxhr.responseText;
console.log(responseBody);
alert("Failed");
});;

 

Response when attempting:

HTTP method PUT is not supported by this URL

The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).

Apache Tomcat/9.0.19

 

Other PUT and POST problems encountered with confluence property:

https://community.atlassian.com/t5/Jira-questions/Create-modify-confluence-property-through-REST-API-fails/qaq-p/1216072#M388269 

Confluence server 6.15

1 answer

0 votes
Dario B Atlassian Team Nov 12, 2019

Hi @zaphnet ,

I already replied the other thread. Since I believe the problem can be something similar in here as well. Can you kindly let me know which endpoint you are using in order to try to update an issue summary in Jira?

The only endpoint I can see in above code is the below one but it does not look correct:

var theurl = encodeURI(confbase + "/plugins/servlet/applinks/proxy?appId=" + confproxy +"&path=" + jirabase + "/rest/api/latest/issue/SP-4");

 

The REST API endpoint to update an issue in Jira Server 8.3 is:

http(s)://{JIRA}/rest/api/2/issue/{issueIdOrKey}

 

Can you kindly let me know which endpoint are you calling in order to try to update an issue summary in Jira?

Also, if this still fails, please try to run the exact same REST API call using Curl and paste the output in here (removing the sensitive data).

 

Cheers,
Dario

Thank for your reply. Replacing latest with 2 gives same result. Problem not solved.

GET from inside confluence works fine, but PUT or POST fails.

Postman and curl works fine:

curl.exe -u user:user -X PUT -H 'Content-Type: application/json' -d '{"update": { "summary": [{ "set": "Modified Summary 2" } ] } }' "https://jira-test.nnn.net/rest/api/2/issue/SP-4"

Not response object (as expected)

Summary of JIRA issue has been changed.

curl.exe -u user:user -X PUT -H 'Content-Type: application/json' -d '{"update": { "summary": [{ "set": "Modified Summary 3" } ] } }' "https://confluence-test.nnn.net/plugins/servlet/applinks/proxy?appId=nnn&path=https://jira-test.nnn.net/rest/api/2/issue/SP-4"

Also fails with

HTTP method PUT is not supported by this URL
 curl.exe -u user:user -X GET -H 'Content-Type: application/json'  "https://confluence-test.nnn.net/plugins/servlet/applinks/proxy?appId=nnn&path=https://jira-test.nnn.net/rest/api/2/issue/SP-4"

Returns the jira object OK.

Dario B Atlassian Team Nov 14, 2019

Hi @zaphnet ,

If my understanding is correct:

1) The PUT request works fine if you use the endpoint:

While it fails returning "HTTP method PUT is not supported by this URL" if you use: 

 

2) The PUT request fails in your code regardless the endpoint used.

 

Can you kindly confirm my understanding is correct and point me to the documentation of endpoint you are actually using (the application links one)?

Finally, please use the endpoint that works fine in with Curl in your code, run the request once again and check Confluence logs for more evidence on what's failing (you can paste the error message in here, making sure to remove the sensitive data).

 

Cheers,
Dario

  

(pretty much the same situation with both community questions)

The GET and PUT/POST Works OK from postman/curl. (with both endpoints)

Get works OK from my built in JS script code, PUT/POST fails. Only proxy endpoint possible from Confluence.

I'm admin in Confluence+JIRA, but not on the servers - I will check if I can get a hold of any log-files from the Server.

I'm a novice working with JS and Ajax, mostly been working with Golang scripts when accessing the REST API. Have made some attempts comparing the http resonse in Postman and response in JS (this can be seen in the cache=false and async=false, this is not based on knowledge of how it should be ;-) (trial and horror...)

BR

/Per

Hi @zaphnet ,

Hopefully you can get the logs. Otherwise, in case you cannot, if the GET works and the PUT fails, we can make the assumption that there is either something wrong with the code for the PUT request or with the provided body (but that should return error 400).

In this case one option would be to ask in the developers' community to check the code:

 

Cheers,
Dario

Thanks for the help - after some more help from community.developer I might be on to something:

jQuery.ajax({
contentType: 'application/json',
type: 'GET',
url: confbase + "/rest/api/content/" + AJS.params.contentId + "/property/example-property-key",
}).done(function(response) {
AJS.log("Response: " + JSON.stringify(response));
AJS.log("Response.key: " + response.key);
response.value.anything = "goes" + response.version.number;
response.version.number = response.version.number + 1;
jQuery.ajax({
contentType: "application/json; charset=utf-8",
type: 'PUT',
data: JSON.stringify(response),
url: confbase + "/rest/api/content/" + AJS.params.contentId + "/property/example-property-key",
}).done(function(response2) {
AJS.log("Response: " + JSON.stringify(response2));
AJS.log("Response.key: " + response2.key);
}).fail(function (xhr) {
AJS.log("Fail: " + xhr.responseText);
});

Need to test some more

Dario B Atlassian Team Nov 15, 2019

I am happy to know they were able to help! :)

Please test the code and if it works accept the answer so that this thread will be marked as solved.

Also, for the future, keep in mind that the below resources are available to get help on development related issues:

 

Have a nice weekend.

Dario

The other ideas did not pan out - I still have the problems previously described in the "curl" examples.

Executing the POST/PUT command directly to JIRA works, but when using the proxy through Confluence fails.

Still no access to the logfiles on server, will make additional tests on local installation

Cheers!

/Per

Suggest an answer

Log in or Sign up to answer
TAGS

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