Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to create a page from a template with Python using REST API?

Natsuko_Kinoshita March 7, 2018

Hello, I'm trying to create a python script that creates a page from existing template in Confluence, but I get 500 Server Error: Internal Server Error.

Could someone point out where I'm doing wrong in my following code?

 

#!/usr/bin/python
# coding: utf-8
import requests

BASE_URL = "https://xxxx.xxxxx.com"
HEADERS = {"content-type": "application/json"}
AUTH = ("myConfluenceUser", "myConfluencePassword")

def create_draft_page(draftId, pageTitle, spaceKey):
# Use HTTP method POST
response = requests.post(
BASE_URL + "/rest/api/content/blueprint/instance/" + draftId,
auth=AUTH,
params={"title": pageTitle, "spaceKey": spaceKey},
headers=HEADERS)
response.raise_for_status()
return response

def main():
print "-------------- start --------------------"
draftId = "12345678" # An existing draft id for template
create_draft_page(draftId, "My Page Title", "Space Name")
print "-------------- end ----------------------"

if __name__ == "__main__":
main()

 

I am using a following page as my reference.

https://docs.atlassian.com/atlassian-confluence/REST/5.9.6/#d3e392

It says the request format as:

/rest/api/content/blueprint/instance/{draftId}

 with POST method.

 

1 answer

0 votes
Natsuko_Kinoshita March 8, 2018

Could anyone can help me?

I tried using curl to do the same thing above, but with no luck...

curl -X POST -H "Content-Type: application/json" -o myoutput -u user:password http://xxxx:xxxx/rest/api/content/blueprint/instance/12345678

Above will give me the following error.

{"statusCode":500,"message":"java.io.EOFException: No content to map to Object due to end of input"}

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events