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

Help with adding comments to Confluence page using REST API

jag kap September 2, 2015

I am trying to add a comment to a confluence Page through REST API. But I gives me a "The specified HTTP method is not allowed for the requested resource." error.

This is what I am trying to do.

from json import dumps, load
from base64 import b64encode
from urllib2 import Request, urlopen

username = "admin"
password = "q*****3"


newTestValues = dumps({
"type":"comment",
"body": "Only single comment at a time"
})
headers = {"Authorization": " Basic " + b64encode(username + ":" + password), "Content-Type": "application/json"}

try:
pageData = json.dumps({
"type":"comment",
"title":"Meeting notes : Staffing discussion - expanded support and development",
"body":{
"storage":{
"value":"<p>wwwwwwoooooooowwwwwww</p>",
"representation":"storage"
}
}
}
)
request = Request('https://j***************a.atlassian.net/wiki/rest/api/latest/content/1146976/child',data=pageData,headers=headers)
js_res = urlopen(request)
objResponse = load(js_res)
print objResponse
except urllib2.HTTPError, error:
print error.read()

 

 

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

8 votes
Answer accepted
rsperafico
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 2, 2015

Hello Jag,

Thank you for your question.

You could run the following:

import requests, json
 
# PAGE_ID, get from https://DOMAIN.atlassian.net/wiki/rest/api/content

pageData = {
    'body':{
        'storage':{
            'value':"&lt;p&gt;A new comment test&lt;/p&gt;",
            'representation':'storage'
        }
    },
    'container':{
        'type':'page',
        'id':'PAGE_ID'
    },
    'type':'comment', 
}    

r = requests.post('https://DOMAIN.atlassian.net/wiki/rest/api/content',
    data=json.dumps(pageData),
    auth=('USERNAME','PASSWORD'),
    headers=({'Content-Type':'application/json'}))

printResponse(r)

 

If you find this answer useful, I would kindly ask you to accept it so the same will be visible to others who might be facing the same issue you have inquired.

Thank you for your understanding.

Kind regards,
Rafael P. Sperafico
Atlassian Support

0 votes
Bernie Maier January 20, 2016

im trying to append a comment to a comment using (PHP)

    $j['type'] = 'comment';

    $j['space']['key'] = <SPACEKEY>;

    $j['container']['id'] = <PARENTCONTENID>;

    $j['container']['type'] = 'comment';

    $j['body']['storage']['value'] = '<p>content ...</p>';

    $j['body']['storage']['representation'] = 'storage';

 

 curl post is ok - comment object is created -  but it is not showen in the frontend!?

any idea smile
b

 

TAGS
AUG Leaders

Atlassian Community Events