How can I find the parameter names for REST API in python?

I am using Confluence V6.0 and I am writing my first python scripts with REST API.

My problem: I don't know how the input parameters in POST calls are named.

Example:

To upload an attachment, the documentation gives examples using curl and multiple -F parameters:

curl -D- -u admin:admin -X POST -H "X-Atlassian-Token: nocheck" -F "file=@myfile.txt"\ 
-F "minorEdit=true" -F "comment=This is my File"\
 http://myhost/rest/api/content/123/child/attachment

In this forum I found a python example which showed that the requests.post function is called with the parameters files= and headers=:

r = requests.post(url, auth=('[USERNAME]', '[PASSWORD]'), files=files, headers=headers)

(see Rafael Sperafico's answer to
How to upload attachment to an Issue using the REST API in Python??)

But: Where do I find these parameter names (and others) in the documentation? E.g. how can I add a comment or the ContentType?

Is there anywhere a complete description of the REST API functions giving not only examples but all the possible parameters?

1 answer

0 vote

Hello Jean Bausch,

Basically, you need to understand how Python works and how you can do GET, POST, PUST, DELETE requests from it. I would recommend you on reading the Python documentation on:

Regarding on adding a comment, please find below an example on how to add the comment "A new comment from Python requests" to the page ID "16744450":

import requests, json


def printResponse(r):
    print '{} {}\n'.format(json.dumps(r.json(), sort_keys=True, indent=4, separators=(',', ': ')), r)

pageData = {
    'body':{
        'storage':{
            'value':"<p>A new comment from Python requests</p>",
            'representation':'storage'
        }
    },
    'container':{
        'type':'page',
        'id':'16744450'
    },
    'type':'comment', 
}
    
# print json.dumps(pageData)    
    
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)

Kind regards,

Rafael

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Published 10 hours ago in Confluence

Think you know shares vs. @mentions in Confluence? Take this collab quiz.

To anyone who doubts that Atlassians are a little too obsessed with collaboration, and tools related thereto, let me describe a recent discussion we had (which took place on our internal Confluence, ...

92 views 2 4
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you