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 vote
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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Kesha Thillainayagam
Posted Apr 13, 2018 in Confluence

We want to hear how your non-technical teams are using Confluence!

Hi Community! Kesha (kay-sha) from the Confluence marketing team here! Can you share stories with us on how your non-technical (think Marketing, Sales, HR, legal, etc.) teams are using Confluen...

1,898 views 25 10
Join discussion

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