Retrieving Template Information Using the ReportingCloud Web API
ReportingCloud provides an extensive API to manage templates. You can upload, list, count, delete and download templates from the ReportingCloud template storage. But it also provides endpoints to retrieve data structure information from a template. The endpoint template/info returns information about the template including the merge field and merge block structure in a hierarchical form. https://api.reporting.cloud/v1/templates/info After calling this method with the template name as a…

ReportingCloud provides an extensive API to manage templates. You can upload, list, count, delete and download templates from the ReportingCloud template storage. But it also provides endpoints to retrieve data structure information from a template.
The endpoint template/info returns information about the template including the merge field and merge block structure in a hierarchical form.
https://api.reporting.cloud/v1/templates/info
After calling this method with the template name as a request parameter, it returns a JSON string with the template information similar to this:
{
"templateName": "sample_invoice.tx",
"mergeBlocks": [
{
"name": "item",
"mergeFields": [
{
"dateTimeFormat": "",
"name": "qty",
"numericFormat": "",
"preserveFormatting": false,
"text": "«qty»",
"textAfter": "",
"textBefore": ""
}
],
"mergeBlocks": []
}
],
"mergeFields": [
{
"dateTimeFormat": "",
"name": "yourcompany_companyname",
"numericFormat": "",
"preserveFormatting": false,
"text": "«YOURCOMPANY_COMPANYNAME»",
"textAfter": "",
"textBefore": ""
},
{
"dateTimeFormat": "",
"name": "invoice_no",
"numericFormat": "",
"preserveFormatting": false,
"text": "«invoice_no»",
"textAfter": "",
"textBefore": "#"
}
]
}
The returned object is of type TemplateInfo which contains all fields at root level and all nested merge blocks including contained merge fields:
TemplateInfo Object
Key | Value Type | Value Description |
---|---|---|
templateName | String | The filename of the template in the template storage. |
mergeBlocks | List of ReportingCloud MergeBlock objects | Contains all merge blocks in the template. |
mergeFields | List of ReportingCloud MergeField objects | Contains all merge fields in the template. |
MergeBlock Object
Key | Value Type | Value Description |
---|---|---|
name | String | The name of the MergeBlock. |
mergeBlocks | List of ReportingCloud MergeBlock objects | Contains all merge blocks in the template. |
mergeFields | List of ReportingCloud MergeField objects | Contains all merge fields in the template. |
MergeField Object
Key | Value Type | Value Description |
---|---|---|
dateTimeFormat | String | Specifies a string format which is applied to date / time values. |
name | String | Gets and sets the name of the field. |
numericFormat | String | Specifies a string format which is applied to numeric values. |
preserveFormatting | Boolean | Specifies whether the formatting is preserved. |
text | String | Gets and sets the text of the field. |
textAfter | String | Gets and sets the text after the field. |
textBefore | String | Gets and sets the text before the field. |
In most cases, hierarchical data is used to design the template. But there are also use cases where data is shaped based on the data structure in a template. The work flow would be similar to this:
- Retrieve template information
- Create data object based on contained data structure
- Merge template with newly created pre-shaped data object
To illustrate how to iterate through the hierarchical data, the following code shows how to fill a tree view in .NET using the .NET ReportingCloud wrapper:
private void addBlockToTreeView(List<MergeBlock> blocks, TreeNode node)
{
foreach (MergeBlock block in blocks)
{
TreeNode curNode;
if (node == null)
curNode = treeView1.Nodes.Add(block.Name);
else
curNode = node.Nodes.Add(block.Name);
foreach (MergeField field in block.MergeFields)
{
curNode.Nodes.Add(field.Name);
}
if (block.MergeBlocks != null)
addBlockToTreeView(block.MergeBlocks, curNode);
}
}
The following screenshot shows the populated tree view in a sample .NET Windows Forms application:

If you want to test this on your own, register today for a free 30-day trial license.
Happy coding!
Cloud
Are we moving to the cloud? This question is changing from "if" to "when" and "how". Text Control ReportingCloud brings complete reporting functionality to the cloud so all developers can use it, irrespective of the platform or language they're using. Its highly RESTful API can be used to merge Microsoft Word compatible templates with JSON data from all clients including .NET, Javascript, PHP, Node.JS, jQuery, Ruby, Python, Android, Java and iOS.
Related Posts
ReportingCloud Monthly Payment Available
We just released ReportingCloud monthly subscriptions that will be auto-renewed, if not cancelled.
Proofing Tools Available As ReportingCloud Web API Endpoints
We just rolled out 3 new ReportingCloud endpoints to integrate spell checking functionality to your cloud-based applications in more than fifty languages.
All Google Fonts Now Available in ReportingCloud
Making the web more beautiful, fast, and open through great typography. This is the motto of Google Fonts. The advantage of ReportingCloud is a consistent rendering of documents.
New ReportingCloud MergeSettings Option: Merge HTML Content into Merge Fields
One of the most requested features for ReportingCloud is a way to merge formatted content into merge fields. We have added this feature to the API and rolled it out last weekend. The MergeSettings…
Merging Nested Repeating Blocks in ReportingCloud
Thanks to the data source excerpt file concept, it is very easy to create templates with complex structures such as nested repeating blocks. A data source excerpt file is used to fill the…