We just released a new endpoint to the ReportingCloud Web API:

http://api.reporting.cloud/v1/templates/info

This endpoint returns information about a template located in the template storage. It returns a JSON structure with the template name, the contained merge fields, the nested merge block structure and included merge fields of the merge blocks.

The following sample CURL shows the usage and the return value:

curl -u username:password \
-X GET "https://api.reporting.cloud/v1/templates/info?templateName=sample_invoice.tx
{
"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 wrappers implement a new TemplateInfo object that returns the merge block and merge field structure like in this sample:

using System;
using System.Collections.Generic;
using System.Drawing;
using TXTextControl.ReportingCloud;
class RCSamples
{
public static void GetTemplateThumbnails(string templateName)
{
ReportingCloud rc = new ReportingCloud(
"username",
"password",
new Uri("https://api.reporting.cloud"));
try
{
TemplateInfo templateInfo = rc.GetTemplateInfo(sTempFilename);
Console.WriteLine(templateInfo.TemplateName);
}
catch (Exception e)
{
Console.WriteLine("An error occurred: " + e.Message);
}
}
}
sample_invoice.tx

This new method allows you to retrieve the contained merge fields of a template. Consider the following scenario: You would like to create an HTML form with input elements based on merge fields of a template. Using the templates/info endpoint, you can loop through all fields in order to create input form elements for user input. After the users completed this HTML form, you can merge back the data into the template in order to create a resulting document.

Start today with ReportingCloud and sign up for a free trial account.

Happy coding!