Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Trying to write a page using Spring RestTemplate

Larry Tambascio
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 14, 2022

Hi,

I'm trying to create a page with a POST call using Spring's RestTemplate object.  If I POST the following JSON via Postman, it works:

{
    "type""page",
    "title""new page",
    "ancestors": [
        {
            "id"3221782533
        }
    ],
    "space": {
        "key""~557058d26714f8ffdd4f1bb844999be9d0ea5c"
    },
    "body": {
        "storage": {
            "value""<p>This page was created on Fri Nov 11 14:10:22 EST 2022.</p>",
            "representation""storage"
        }
    }
}

Using the following bit of Java, however, gives me a 400 Bad Request response:

            HttpHeaders headers = new HttpHeaders();
headers.set("Authorization", "Basic " + authorization);
headers.set("Content-Type", "application/json");
ResponseEntity<Object> resp = restTemplate.exchange("https://xxxxxxx.atlassian.net/wiki/rest/api/content", HttpMethod.POST,
new HttpEntity<>(pageJson, headers), Object.class);

 Here's the response message:

org.codehaus.jackson.map.JsonMappingException: Can not instantiate value of type [simple type, class com.atlassian.confluence.api.model.content.Content] from JSON String; no single-String constructor/factory method

What class should I be passing to the exchange call??  Is it the com.atlassian.confluence.api.model.content.Content class in the error message??  And if so, what's the Maven dependency that has this class??  I can't seem to find it anywhere.

Thanks,

-Larry

0 answers

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events