2
votes

I used the example here: https://developer.atlassian.com/confdev/confluence-server-rest-api/confluence-rest-api-examples and others i found to try and create a page in confluence using jquery

<html>
<head>
<script src="jquery-1.11.1.min.js"></script>
<script>
    var username = "admin";
    var password = "admin";
    var jsondata = {"type":"page",
     "title":"My Test Page",
     "space":{"key":"mySpaceKey"},
     "body":{"storage":{"value":"<p>This is a new page</p>","representation":"storage"}}};

    $.ajax
      ({
        type: "POST",
        url: "http://localhost:8080/confluence/rest/api/content/",
        contentType:"application/json; charset=utf-8",
        dataType: "jsonp",
        async: true,
        headers: {
            "Authorization": "Basic " + btoa(username+ ":" + password)
        }, 
        data: JSON.stringify(jsondata),
        success: function (){
            console.log('success'); 
        },
        error : function(xhr,status errorText){
            console.log(errorText);
        }
    });
</script>
<body></body>
</head>
</html>

It goes to the success function but doesnt create the page, I tried different dataTypes/url and so on, but I dont understand why it wont work.

Anyonw knows what is the problem?

Thank you!

1
Use your browser's network inspector to see what Confluence replies to the request. - AKX
it replies an html page - but it does not include my page - 123456
it replies an html page or jsonp depending on the url i choose - with the html option i receive html page but it does not include my page, with the jsonp option i receive error 500 - 123456

1 Answers

0
votes

Comparing to your code and example on Atlassian dev, there is a small difference about data type in ajax function. Your code: dataType: "jsonp" Atlassian dev code: dataType: "json"

Check above issue.