Create annotations via API

Hello,

I’m trying to figure out how to create comments/annotations via API.
According to the documentation it should be something like
curl --request POST 'https://my.xwiki.domain/xwiki/rest/wikis/xwiki/spaces/MySpace/spaces/PageName/pages/WebHome/comments?text=Test' --header 'Content-Type: application/x-www-form-urlencoded' --header 'Authorization: Basic *****'
But it always replies with ‘Invalid or missing form token.

Could you please give me some hint?

Hi Boris,

Have you read this section about CSRF Token https://www.xwiki.org/xwiki/bin/view/Documentation/UserGuide/Features/XWikiRESTfulAPI#HAuthentication?
You only have to perform the simplest GET request to obtain a token and that would be used in the future requests, until you restart the XWiki instance.

Hope it helps,
Alex

Thank you Alex, I was able to create a comment.

But annotations endpoint is not documented.
I tried to do the PUT request with form parameters
annotation=Test&selectionLeftContext=30&selectionRightContext=40
but it was not succeeded.

Any clue on this?

An annotation is a comment that provides values for 3 fields: Selection, Target and State. You can see the difference if, on the same page, you add a comment and an annotation and check the page in object mode.