Tornado Get Template Structure using Python

This example shows how to get the structure of a template in JSON format using Python.  It calls the Docmosis REST API to return a response describing the fields, images and sections of the template.

The sample code includes the instructions to get started. You will need a Free Trial to install and run Tornado.

# This sample code shows how to get the structure of the "WelcomeTemplate.doc" template in JSON format
# via the local Tornado server (localhost:8080).

# If you wish to test via a web proxy server, set useProxy to True and see the proxies settings below to enable it.

import requests
import json
import datetime

accessKey=''
templateName='WelcomeTemplate.doc'

useProxy = False
proxies = {'http': 'http://username:password@ip:port',
           'https': 'http://username:password@ip:port'}

# Create request
payload = 'accessKey=' + accessKey + '&templateName=' + templateName
headers = {'content-type': 'application/x-www-form-urlencoded'}

# Make request
if useProxy:
  r = requests.post("http://localhost:8080/rs/getTemplateStructure", data=payload, headers=headers, proxies=proxies)
else:
  r = requests.post("http://localhost:8080/rs/getTemplateStructure", data=payload, headers=headers)

# Process response
if r.status_code == 200:
  jsonResponse = r.json()
  if 'templateStructure' in jsonResponse:
    print(json.dumps(jsonResponse['templateStructure'], indent=4, sort_keys=True))
else:
  print("Failed")
  print(r.text)
 

Feedback

Invalid Input

Sorry, this field will only accept letters and numbers, and not special characters, to limit spam.

Sorry, this field will only accept letters and numbers, and not special characters, to limit spam.

Invalid Input

Applies To

Docmosis-Java Tornado Cloud
Version(s) - ALL -