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

How do we add an in-line comment to Confluence content using the REST API?

Chris Harvey January 6, 2017

Hello!

I am trying to add an in-line comment using the REST API.  Google pointed me to the following request format, however this fails with an error (see response).

Also, I am guessing at what to put in serializedHighlights, (it is flagged in the error response if not present in the request) so if anyone knows anything about that, I'll be pleased to receive advice on that!

I haven't looked at the code yet.

 

Here's the outgoing request:

POST {{server}}/rest/api/content
 
{
    "type": "comment",
    "mode": "create",
    "container": 
      {
        "id": "2031625",
        "type": "page"        
    },
    "body": {
        "storage": {
            "value": "<p>This inline comment added from REST API</p>",
            "representation": "storage"
        }
    },
    "extensions": {       
        "location": "inline",
        "inlineProperties": {
            "numMatches": 1,
            "originalSelection": "Hello From me",
            "matchIndex": 0,
          "serializedHighlights" : "[[\"Hello From me\"]]"
        }
    }
}

 

And the error response:

{
    "statusCode": 400,
    "data": {
        "authorized": true,
        "valid": false,
        "errors": [
            {
                "message": {
                    "key": "lastFetchTime",
                    "args": []
                }
            }
        ],
        "successful": false
    },
    "message": "Could not create content with type comment"
}

 

Regards,

Chris

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Jaime S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 21, 2017

Hi, Chris.

So, I was having the same issue and then I realized it was complaining about the a missing 'lastFetchTime' attribute. I'm not sure what it is exactly, it seems to be the date where it was last fetched. After some tests, I found out it is a date represented as a timestamp (so, a long integer).

I generated one using http://www.epochconverter.com/.

This worked for me:

 

...
    "extensions": {      
        "location": "inline",
        "inlineProperties": {
            "numMatches": 1,
            "originalSelection": "Hello From me",
            "matchIndex": 0,
            "serializedHighlights" : "[[\"Hello From me\"]]",
            "lastFetchTime":"1487711412"
...

I hope this helps.

Kind regards,
Jaime Kirch da Silveira
Atlassian Cloud Support

TAGS
AUG Leaders

Atlassian Community Events