REST POST request from Confluence html macro returns “HTTP Status 415 – Unsupported Media Type” erro

We are (F5 Networks, Inc) heavy Jira and Confluence using company.

I am stuck while attempting to create Jira issues through html macro in Confluence.

I am essentially using <form> element to get some input and send it through a java script making an REST API POST request  (via XMLHttprequest)  with Content-Type set to application/json.

I get “HTTP Status 415 – Unsupported Media Type” error.

However, if I disable <form> element and use <button> element (commented in the code below), it works. 

Some insight on this behaviour would greatly be appreciated.

Here is the code snippet:

<form method="post" action="https://<Server URL>/rest/jira-integration/1.0/issues?applicationId=29bbc237-8c6b-3a19-8e64-4da8fed882e6" name="myForm">

         TMA Owner: <input type="text" name="tmao" id="tmao">

        <input type="submit" value="Submit" onclick="submitform()">

</form>

 <!--

<button type="button" onclick="submitform()">Submit</button>

-->

<script type="text/javascript">

function submitform() {

        var data = {"issues":[{"fields":{"project":{"key":"TMA"}, "issuetype":{"name":"TMA Review"}, "customfield_11683":{"name": "gunduc"}, "summary":"TMA 1", "description":"TMA testing"}}]};

         var xhr = new XMLHttpRequest();

        xhr.open("POST", "https://<Server URL>/rest/jira-integration/1.0/issues?applicationId=29bbc237-8c6b-3a19-8e64-4da8fed882e6", true);

alert("Sending JSON3.1");

        xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');

        xhr.setRequestHeader('Accept', 'application/json);

        xhr.send(JSON.stringify(data));

        console.log(xhr.responseText.substring(0, 150)) ;

};

</script>

1 answer

0 votes
Aleksandr Zuevich Community Champion Dec 10, 2017

Hi,

please compare your requests in two cases (using browser Network console). I suppose when you press Submit in form the data is sent using form-data while when you press Submit outside the form you invoke your submitform function. If you are sure that your function is invoked in two cases check stopPropagation or preventDefault event's methods.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Mar 12, 2019 in Confluence

Confluence Admin Certification now $150 for Community Members

More and more people are building their careers with Atlassian, and we want you to be at the front of this wave! Important Dates Start the Certification Prep Course by 2 April 2019 Take your e...

1,268 views 2 13
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you