# List all templates

Lists all templates of an user.

You can filter and customize the results using various query parameters.

## Query Parameters

| Parameter         | Type     | Default | Description                                       |
|-------------------|----------|---------|---------------------------------------------------|
| `query`           | string   | -       | Filter templates by name                           |
| `page`            | integer  | 0       | Page number for pagination                        |
| `limit`           | integer  | 25      | Number of results per page                        |
| `width`           | integer  | -       | Filter templates by width                         |
| `height`          | integer  | -       | Filter templates by height                        |
| `tags`            | string   | -       | Filter templates by tags (comma-separated)       |
| `externalId`      | string   | -       | Filter templates by external ID                   |
| `includeLayers`   | boolean  | false   | Include template layers in response               |
| `includePages`    | boolean  | false   | Include template pages and layers in response     |

## Response

Each template in the response includes the following notable fields:

| Field         | Type    | Description                                                                                |
|---------------|---------|--------------------------------------------------------------------------------------------|
| `background`  | string  | The background color of the template (e.g., `#ffffff` or `rgb(255, 255, 255)`)           |
| `layers`      | array   | List of template layers (only included when `includeLayers=true`)                          |
| `pages`       | array   | List of template pages with their layers (only included when `includePages=true`)          |

## Sample Request

Here’s a sample request to list all user’s templates:

```
GET /v1/templates
```

### JavaScript

```
fetch(`https://api.templated.io/v1/templates`, {
  method: 'GET',
  headers: {
    'Authorization': `Bearer ${API_KEY}`
  },
  // Example with all query parameters
  params: {
    query: 'Template Name',
    page: 0,
    limit: 25,
    width: 1920,
    height: 1080,
    tags: 'tag1,tag2',
    externalId: 'my-external-id',
    includeLayers: true
  }
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
```

### Python

```
import requests

api_key = 'API_KEY'

url = 'https://api.templated.io/v1/templates'

# Example with all query parameters
params = {
  'query': 'Template Name',
  'page': 0,
  'limit': 25,
  'width': 1920,
  'height': 1080,
  'externalId': 'my-external-id',
  'includeLayers': True
}

headers = {'Authorization': f'Bearer {api_key}'}

response = requests.get(url, params=params, headers=headers)
if response.status_code == 200:
    print(response.json())
else:
    print('Request failed. Response code:', response.status_code)
    print(response.text)
```

### Java

```
import java.net.HttpURLConnection;
import java.net.URL;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URLEncoder;

public class ListTemplates {
    public static void main(String[] args) {
        try {
            String apiKey = "API_KEY";
            // Example with all query parameters
            String queryParams = String.format("?query=%s&page=%d&limit=%d&width=%d&height=%d&externalId=%s&includeLayers=%b",
                URLEncoder.encode("Template Name", "UTF-8"),
                0,
                25,
                1920,
                1080,
                URLEncoder.encode("my-external-id", "UTF-8"),
                true
            );
            URL url = new URL("https://api.templated.io/v1/templates" + queryParams);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setRequestMethod("GET");
            connection.setRequestProperty("Authorization", "Bearer " + apiKey);
            int responseCode = connection.getResponseCode();
            if (responseCode == HttpURLConnection.HTTP_OK) {
                BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
                String inputLine;
                StringBuilder response = new StringBuilder();
                while ((inputLine = in.readLine()) != null) {
                    response.append(inputLine);
                }
                in.close();
                System.out.println(response.toString());
            } else {
                System.out.println("Request failed. Response Code: " + responseCode);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
```

### PHP

```
<?php
$apiKey = 'API_KEY';
// Example with all query parameters
$params = array(
    'query' => 'Template Name',
    'page' => 0,
    'limit' => 25,
    'width' => 1920,
    'height' => 1080,
    'externalId' => 'my-external-id',
    'includeLayers' => 'true'
);
$url = "https://api.templated.io/v1/templates?" . http_build_query($params);
$options = [
    'http' => [
        'header' => "Authorization: Bearer {\$apiKey}\r\n",
        'method' => 'GET'
    ]
];
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result === FALSE) {
    echo "Error fetching data";
} else {
    $data = json_decode($result, true);
    print_r($data);
}
?>
```
