# GET /v1/templates/download

> Download a stored template by templateName from ReportingCloud as a Base64-encoded string and save it to a file in .NET, Java, Ruby or PHP.

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

---

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

### Description

Returns a template from the template storage: the file as it was uploaded, as a Base64 string in a JSON string. Decode the string to get the file in its format, such as DOCX or TX. See [Managing Templates](https://docs.textcontrol.com/reporting-cloud/document-processing/templates/llms-full.txt).

### Examples

#### HTTP

Request:

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

Results:

```json
"CAcBAA4AAAAAAAAAAAA7AwIAqwBZAE8AVQBSAEMATwBNAFAA...AAAAQAAAAEAHAAAAAAAAAAAA"
```

#### C#

Request:

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

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

        try
        {
            byte[] bTemplateData = rc.DownloadTemplate(templateName);
            File.WriteAllBytes(templateName, bTemplateData);
            Console.WriteLine(templateName + " has been downloaded.");
        }
        catch (Exception e)
        {
            Console.WriteLine("An error occurred: " + e.Message);
        }
    }
}
```

Results:

```text
sample_invoice.tx has been downloaded.
```

#### Java

Request:

```java
import com.textcontrol.reportingcloud.ReportingCloud;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

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

        String filename = "downloaded.tx";
        Files.write(Paths.get(filename), templateData);
        System.out.println("Template was written to " + filename + ".");
    }
}
```

Results:

```text
Template was written to downloaded.tx.
```

#### Ruby

Request:

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

require "txtextcontrol/reportingcloud"
require "base64"

reporting_cloud = TXTextControl::ReportingCloud::ReportingCloud.new("username", "password")
template_name = "sample_invoice.tx"
template_data_b64 = reporting_cloud.download_template(template_name)

File.open(File.dirname(__FILE__) + "/#{template_name}", 'wb') do |f|
  f.write(Base64.strict_decode64(template_data_b64))
end

puts "Template was written to #{template_name}."
```

Results:

```text
Template was written to sample_invoice.tx.
```

#### PHP

Request:

```php
<?php

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

use TextControl\ReportingCloud\ReportingCloud;

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

$templateName = 'sample_invoice.tx';

$binaryData = $reportingCloud->downloadTemplate($templateName);

$destinationFilename = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $templateName;

file_put_contents($destinationFilename, $binaryData);

var_dump("{$templateName} was written to {$destinationFilename}");
```

Results:

```text
string(55) "sample_invoice.tx was written to /tmp/sample_invoice.tx"
```

### 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 name of the template in the template storage. The name is not case-sensitive. | no |

### Success Response

| Status | Description |
|---|---|
| 200 | On success, the HTTP status code in the response header is 200 (OK). The response body contains the template, in the format it was uploaded in, as a Base64 encoded JSON string. |

### 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/download](https://docs.textcontrol.com/reporting-cloud/reference/web-api/templates/download/llms-full.txt)
- **Next:** [/v1/templates/exists](https://docs.textcontrol.com/reporting-cloud/reference/web-api/templates/exists/llms-full.txt)
