# GET /v1/templates/info

> Get the TemplateInfo of a stored template: its merge fields with formats and surrounding text, nested merge blocks and user-defined document properties.

- **Product:** ReportingCloud
- **Section:** Documentation
- **Kind:** Endpoint
- **Path:** ReportingCloud > API Reference > Web API > Templates > /info > GET /v1/templates/info
- **3866 words**
- **Web URL:** https://docs.textcontrol.com/reporting-cloud/reference/web-api/templates/info/get/
- **LLMs URL:** https://docs.textcontrol.com/reporting-cloud/reference/web-api/templates/info/get/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/reporting-cloud/reference/web-api/templates/info/get/llms-full.txt

---

`GET` `https://api.reporting.cloud/v1/templates/info`

### Description

Returns the merge fields and merge blocks of a template in the template storage, to build the data a merge needs. The response lists the merge fields outside blocks, in the main text, headers and footers; the merge blocks with their own fields and the blocks nested in them; and the user document properties of the template. See [Mail Merge](https://docs.textcontrol.com/reporting-cloud/mail-merge/overview/llms-full.txt).

### Examples

#### HTTP

Request:

```bash
curl -u username:password \
  -X GET "https://api.reporting.cloud/v1/templates/info?templateName=sample_invoice.tx"
```

Results:

```json
{
	"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": "#"
		}
	],
	"userDocumentProperties": {}
}
```

The result is shortened to 1 of the 6 merge fields of the item block and 2 of the 33 merge fields at the root level.

#### C#

Request:

```csharp
using System;
using System.Collections.Generic;
using System.Drawing;
using TXTextControl.ReportingCloud;

class RCSamples
{
    public static void GetTemplateInfo(string templateName)
    {
        ReportingCloud rc = new ReportingCloud(
            "username",
            "password",
            new Uri("https://api.reporting.cloud"));

        try
        {
            TemplateInfo templateInfo = rc.GetTemplateInfo(templateName);
            Console.WriteLine(templateInfo.TemplateName);
        }
        catch (Exception e)
        {
            Console.WriteLine("An error occurred: " + e.Message);
        }
    }
}
```

Results:

```text
sample_invoice.tx
```

#### Java

Request:

```java
import com.textcontrol.reportingcloud.MergeBlock;
import com.textcontrol.reportingcloud.MergeField;
import com.textcontrol.reportingcloud.ReportingCloud;
import com.textcontrol.reportingcloud.TemplateInfo;

import java.io.IOException;

public class ReportingCloudSample {
    public static void main(String[] args) throws IOException {
        ReportingCloud r = new ReportingCloud("username", "password");
        TemplateInfo templateInfo = r.getTemplateInfo("sample_invoice.tx");

        System.out.println("Template: " + templateInfo.getTemplateName());
        for (MergeField mergeField : templateInfo.getMergeFields()) {
            System.out.println("Merge field: " + mergeField.getName());
        }
        for (MergeBlock mergeBlock : templateInfo.getMergeBlocks()) {
            System.out.println("Merge block: " + mergeBlock.getName());
        }
    }
}
```

Results:

```text
Template: sample_invoice.tx
Merge field: yourcompany_companyname
Merge field: invoice_no
Merge block: item
```

#### Ruby

Request:

```ruby
#!/usr/bin/env ruby

require "txtextcontrol/reportingcloud"

reporting_cloud = TXTextControl::ReportingCloud::ReportingCloud.new("username", "password")
template_info = reporting_cloud.get_template_info("sample_invoice.tx")

puts "Template: #{template_info.template_name}"
template_info.merge_fields.each { |merge_field| puts "Merge field: #{merge_field.name}" }
template_info.merge_blocks.each { |merge_block| puts "Merge block: #{merge_block.name}" }
```

Results:

```text
Template: sample_invoice.tx
Merge field: yourcompany_companyname
Merge field: invoice_no
Merge block: item
```

#### PHP

Request:

```php
<?php

require_once __DIR__ . '/vendor/autoload.php';

use TextControl\ReportingCloud\ReportingCloud;

$reportingCloud = new ReportingCloud([
    'api_key' => (string) getenv('REPORTINGCLOUD_API_KEY'),
]);

var_dump($reportingCloud->getTemplateInfo('sample_invoice.tx'));
```

Results:

```text
array(4) {
  ["template_name"]=>
  string(17) "sample_invoice.tx"
  ["merge_blocks"]=>
  array(1) {
    [0]=>
    array(3) {
      ["name"]=>
      string(4) "item"
      ["merge_fields"]=>
      array(1) {
        [0]=>
        array(7) {
          ["date_time_format"]=>
          string(0) ""
          ["name"]=>
          string(3) "qty"
          ["numeric_format"]=>
          string(0) ""
          ["preserve_formatting"]=>
          bool(false)
          ["text"]=>
          string(7) "«qty»"
          ["text_after"]=>
          string(0) ""
          ["text_before"]=>
          string(0) ""
        }
      }
      ["merge_blocks"]=>
      array(0) {
      }
    }
  }
  ["merge_fields"]=>
  array(2) {
    [0]=>
    array(7) {
      ["date_time_format"]=>
      string(0) ""
      ["name"]=>
      string(23) "yourcompany_companyname"
      ["numeric_format"]=>
      string(0) ""
      ["preserve_formatting"]=>
      bool(false)
      ["text"]=>
      string(27) "«YOURCOMPANY_COMPANYNAME»"
      ["text_after"]=>
      string(0) ""
      ["text_before"]=>
      string(0) ""
    }
    [1]=>
    array(7) {
      ["date_time_format"]=>
      string(0) ""
      ["name"]=>
      string(10) "invoice_no"
      ["numeric_format"]=>
      string(0) ""
      ["preserve_formatting"]=>
      bool(false)
      ["text"]=>
      string(14) "«invoice_no»"
      ["text_after"]=>
      string(0) ""
      ["text_before"]=>
      string(1) "#"
    }
  }
  ["user_document_properties"]=>
  array(0) {
  }
}
```

### Authorization

This endpoint requires a "ReportingCloud-APIKey" or a "Basic" user authorization to access the user account, data and templates. Only one of these two methods is required.

[API Keys](https://docs.textcontrol.com/reporting-cloud/installation/api-keys/llms-full.txt) describes how to create an API key, and [Authentication](https://docs.textcontrol.com/reporting-cloud/document-processing/authentication/llms-full.txt) explains both header forms.

#### ReportingCloud-APIKey

| Header field | Description |
|---|---|
| Authorization | **Required**. A valid ReportingCloud account is required. The Authorization field is constructed as follows: An API key needs to be generated in the portal or with [PUT /v1/account/apikey](https://docs.textcontrol.com/reporting-cloud/reference/web-api/account/apikey/put/llms-full.txt). The authorization method and a space, "ReportingCloud-APIKey ", is then put before the actual API key string. For example: `Authorization: ReportingCloud-APIKey oMDM4MrAqL9QEOpyzupnQW5NjvCNtvE5cVDaaLqxI` |

#### Basic

| Header field | Description |
|---|---|
| Authorization | **Required**. A valid ReportingCloud account is required. The Authorization field is constructed as follows: The user name and password are combined into a string separated by a colon, for example `username:password`. The resulting string is encoded using the RFC2045-MIME variant of Base64, except not limited to 76 char/line. The authorization method and a space, "Basic ", is then put before the encoded string. For example: `Authorization: Basic QWxhZGRpbjpPcGVuU2VzYW1l` |

### Request Parameters

| Name | Type | Value | Optional |
|---|---|---|---|
| templateName | String | The filename of the template in the template storage whose information is returned. The name is matched case-insensitively. | no |

### Success Response

| Status | Description |
|---|---|
| 200 | On success, the HTTP status code in the response header is 200 (OK). The response body contains a ReportingCloud [TemplateInfo](#success-response) object. |

#### TemplateInfo

| Name | Type | Value | Optional |
|---|---|---|---|
| templateName | String | The template name as the request gives it. Since template names are matched case-insensitively, its case can differ from the name in the template storage. | no |
| mergeBlocks | List of ReportingCloud [MergeBlock](#success-response) objects | Contains the merge blocks at the root level of the template. A nested merge block is listed in the mergeBlocks of the block that contains it. | no |
| mergeFields | List of ReportingCloud [MergeField](#success-response) objects | Contains the merge fields at the root level of the template, outside of merge blocks, including those of headers and footers. A field that occurs more than once is listed once per occurrence. | no |
| userDocumentProperties | Object | The user-defined (custom) document properties of the template, with the property names as keys and their values as String, Number or Boolean values. Date properties are left out. An empty object if the template has none. | no |

#### MergeBlock

| Name | Type | Value | Optional |
|---|---|---|---|
| name | String | The name of the MergeBlock. | no |
| mergeBlocks | List of ReportingCloud [MergeBlock](#success-response) objects | Contains the merge blocks nested in the merge block. | no |
| mergeFields | List of ReportingCloud [MergeField](#success-response) objects | Contains the merge fields of the merge block, outside of the merge blocks nested in it. | no |

#### MergeField

| Name | Type | Value | Optional |
|---|---|---|---|
| dateTimeFormat | String | Specifies a string format which is applied to date / time values (the `\@` switch of the field). | no |
| name | String | The name of the merge field. | no |
| numericFormat | String | Specifies a string format which is applied to numeric values (the `\#` switch of the field). | no |
| preserveFormatting | Boolean | Specifies whether the formatting is preserved (the `\* MERGEFORMAT` switch of the field). | no |
| text | String | The text the field shows in the template, such as «name». | no |
| textAfter | String | The text after the field (the `\f` switch of the field). | no |
| textBefore | String | The text before the field (the `\b` switch of the field). | no |

### Error Response

| Status | Description |
|---|---|
| 400 | A 400 (Bad Request) is returned, if the template doesn't exist in the template storage or templateName is empty. |
| 403 | A 403 (Forbidden) is returned, if the user is not authorized. |
| 404 | A 404 (Not Found) is returned, if a required query parameter is missing. |
| 405 | A 405 (Method Not Allowed) is returned, if the request uses another HTTP method than GET. The Allow header of the response names GET. |
| 500 | A 500 (Internal Server Error) is returned, if the request has no Authorization header, an empty one or one that is not the authorization method, a space and the credentials. |

---

## Nearby

- **Previous:** [/v1/templates/info](https://docs.textcontrol.com/reporting-cloud/reference/web-api/templates/info/llms-full.txt)
- **Next:** [/v1/templates/list](https://docs.textcontrol.com/reporting-cloud/reference/web-api/templates/list/llms-full.txt)
