Home/Atlassian REST API reference
Jira and Confluence Cloud REST API
Restrict who can see a Jira comment through the REST API
A comment can be limited to a group or a project role by adding a visibility object next to the body in POST or PUT /rest/api/3/issue/{issueIdOrKey}/comment. The object takes a type of group or role and a value. A value that matches nothing is rejected with a 400 keyed commentLevel, and a comment without the object carries no visibility key in the response.
Endpoints
| Method | Path | What it does |
|---|---|---|
POST | /rest/api/3/issue/{issueIdOrKey}/comment | Adds a comment, optionally with a visibility object. |
PUT | /rest/api/3/issue/{issueIdOrKey}/comment/{id} | Updates a comment and can change its visibility. |
GET | /rest/api/3/issue/{issueIdOrKey}/comment | Lists comments the caller is allowed to see. |
GET | /rest/api/3/project/{projectIdOrKey}/role | Lists the roles of a project. |
Examples
POST /rest/api/3/issue/{issueIdOrKey}/comment
Asks for a comment visible only to a role called Administrators. No role has that name in the project, so the call fails.
curl
curl -X POST \
-u "you@example.com:$ATLASSIAN_API_TOKEN" \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
--data '{
"body": {
"type": "doc",
"version": 1,
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "Visible to a role only."
}
]
}
]
},
"visibility": {
"type": "role",
"value": "Administrators"
}
}' \
'https://your-domain.atlassian.net/rest/api/3/issue/{issueIdOrKey}/comment'Python (requests)
import os
import requests
EMAIL = "you@example.com"
r = requests.post(
'https://your-domain.atlassian.net/rest/api/3/issue/{issueIdOrKey}/comment',
auth=(EMAIL, os.environ["ATLASSIAN_API_TOKEN"]),
headers={'Accept': 'application/json'},
json={'body': {'type': 'doc',
'version': 1,
'content': [{'type': 'paragraph',
'content': [{'type': 'text',
'text': 'Visible to a role only.'}]}]},
'visibility': {'type': 'role', 'value': 'Administrators'}},
)
print(r.status_code, r.text)Response: HTTP 400
{
"errorMessages": [],
"errors": {
"commentLevel": "Role with id: Administrators does not exist."
}
}Sent to Atlassian Cloud on .
POST /rest/api/3/issue/{issueIdOrKey}/comment
The same call without visibility. The stored comment shows no visibility key and jsdPublic stays true.
curl
curl -X POST \
-u "you@example.com:$ATLASSIAN_API_TOKEN" \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
--data '{
"body": {
"type": "doc",
"version": 1,
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "First comment through the REST API."
}
]
}
]
}
}' \
'https://your-domain.atlassian.net/rest/api/3/issue/{issueIdOrKey}/comment'Python (requests)
import os
import requests
EMAIL = "you@example.com"
r = requests.post(
'https://your-domain.atlassian.net/rest/api/3/issue/{issueIdOrKey}/comment',
auth=(EMAIL, os.environ["ATLASSIAN_API_TOKEN"]),
headers={'Accept': 'application/json'},
json={'body': {'type': 'doc',
'version': 1,
'content': [{'type': 'paragraph',
'content': [{'type': 'text',
'text': 'First comment through the REST API.'}]}]}},
)
print(r.status_code, r.text)Response: HTTP 201
{
"id": "11103",
"jsdPublic": true
}Sent to Atlassian Cloud on .
GET /rest/api/3/issue/{issueIdOrKey}/comment
Every comment in the list has the same shape, and none of them has a visibility key because none was set.
curl
curl -G \
-u "you@example.com:$ATLASSIAN_API_TOKEN" \
-H 'Accept: application/json' \
--data-urlencode 'maxResults=2' \
--data-urlencode 'orderBy=-created' \
'https://your-domain.atlassian.net/rest/api/3/issue/{issueIdOrKey}/comment'Python (requests)
import os
import requests
EMAIL = "you@example.com"
r = requests.get(
'https://your-domain.atlassian.net/rest/api/3/issue/{issueIdOrKey}/comment',
auth=(EMAIL, os.environ["ATLASSIAN_API_TOKEN"]),
headers={'Accept': 'application/json'},
params={'maxResults': '2', 'orderBy': '-created'},
)
print(r.status_code, r.text)Response: HTTP 200
{
"total": 2,
"comments": [
{
"id": "11104",
"jsdPublic": true
},
{
"id": "11103",
"jsdPublic": true
}
]
}Sent to Atlassian Cloud on .
GET /rest/api/3/project/WEB/role
The roles the project really has. The name used above, Administrators, is not among them.
curl
curl \
-u "you@example.com:$ATLASSIAN_API_TOKEN" \
-H 'Accept: application/json' \
'https://your-domain.atlassian.net/rest/api/3/project/WEB/role'Python (requests)
import os
import requests
EMAIL = "you@example.com"
r = requests.get(
'https://your-domain.atlassian.net/rest/api/3/project/WEB/role',
auth=(EMAIL, os.environ["ATLASSIAN_API_TOKEN"]),
headers={'Accept': 'application/json'},
)
print(r.status_code, r.text)Response: HTTP 200
{
"atlassian-addons-project-access": "https://your-domain.atlassian.net/rest/api/3/project/10066/role/10083",
"Administrator": "https://your-domain.atlassian.net/rest/api/3/project/10066/role/10079",
"jira-guest-member": "https://your-domain.atlassian.net/rest/api/3/project/10066/role/10082",
"Viewer": "https://your-domain.atlassian.net/rest/api/3/project/10066/role/10081",
"Member": "https://your-domain.atlassian.net/rest/api/3/project/10066/role/10080"
}Sent to Atlassian Cloud on .
How it behaves
- visibility with type role and value Administrators gave 400 with errors.commentLevel set to "Role with id: Administrators does not exist.". The message calls the value an id.
- The roles of the project WEB, taken from the role listing, are atlassian-addons-project-access, Administrator, jira-guest-member, Viewer and Member. The value sent, Administrators, matches none of them.
- A comment posted without a visibility object returns 201 and the response has no visibility key at all, only jsdPublic: true.
Pitfalls
- Check the role against GET /rest/api/3/project/{projectIdOrKey}/role first. A near miss such as Administrators for Administrator is a 400, not a silent public comment.
- A group is identified by name or by identifier. The spec warns that a group name is mutable and recommends the identifier.
- The error is reported under commentLevel, not under visibility, so a client that only maps errors to request fields will lose the message.
Questions and answers
Do I send the role name or its id?
The spec describes value as the name of the group or role. The 400 above words it as an id, and no run with a valid role was made, so verify against your own project before relying on either.