Syntax error creating Confluence task when creating a new page using wiki/rest/api/content api
Asked by Tom VandenBerge:

Using postman to call the wiki/rest/api/content api to create a new page with the body (with Content-Type: application/json) below, I receive this message:

"message": "java.lang.RuntimeException: com.atlassian.confluence.content.render.xhtml.XhtmlException: com.atlassian.confluence.content.render.xhtml.XhtmlException: Missing required attribute: {<http://atlassian.com/resource/identifier}username>"

even though it matches the example in the "Create a page with a task" section of <https://developer.atlassian.com/server/confluence/confluence-rest-api-examples/>

After searching the api doc as well as google, I can't figure out why it doesn't work. Obviously, abc@example.com is just the example. In the real post, it was a known valid user email address/login.

Body in POST

{  
"type" : "page",  
"status" : "current",  
"title" : "TEST1: Page created through postman",  
"space" : { "key" : "EIE" },  
"ancestors": \[{  
"id": 281611148  
}\],  
"body" : {  
"storage" : {  
"representation" : "storage",  
"value": "\<ac:task-list\>\\n\<ac:task\>\\n\<ac:task-status\>incomplete\</ac:task-status\>\\n\<ac:task-body\>\\n\<ac:link\>\<ri:user ri.username='abc@example.com' /\>\</ac:link\>\\nTest action created for Tom\\n\</ac:task-body\>\\n\</ac:task\>\\n\</ac:task-list\>"  
}  
}  
}


Answers:
author: Tom VandenBerge
body: Ignore - figured it out

comments: author: Dirk Jacobus de Klerk
body: Hi [@Tom VandenBerge](/t5/user/viewprofilepage/user-id/1182608)

Could you perhaps share how you managed to sort out the issue?

I am stuck with the same error message?

Cheers


author: Tom VandenBerge
body: Dirk,

I should have posted what I figured out but the solution was completely unexpected and pretty annoying. In summary, the "Create a page with a task" section of <https://developer.atlassian.com/server/confluence/confluence-rest-api-examples/> has to be taken literally including newlines and spaces. That was completely unexpected but apparently the parser would get confused without them.

The Javascript format string for each task would be:

```
'\\n <ac:task>\\n <ac:task-status>incomplete</ac:task-status>\\n<ac:task-body> <ac:link><ri:user ri:username=\'%s\' /></ac:link> %s </ac:task-body>\\n </ac:task>'
```

where %s is the user ID and task text respectively.

Wrap those lines with "\<ac:task-list\>" and "\</ac:task-list\>" and it should work for you.

Hope this helps.


author: Dirk Jacobus de Klerk
body: Hi [@Tom VandenBerge](/t5/user/viewprofilepage/user-id/1182608)

Thank you for getting back to me so quickly.

Unfortunately, my problem lies with the \<ri:user\> part of that string. Since they are deprecating username and userId in the new cloud migrations I no longer have access to those (have to use accountId but there is no support for that yet.)

I got the same error so thought you might have had the same issue.

Thanks for the reply anyway!


author: Tom VandenBerge
body: Oh yes, I remember that I read the username was being deprecated. We're not using that particular application anymore so that fact is not an issue for me right now. I do hope they provide you a solution.