# Activate a transactional template version.

## API Overview

Represents the code for a particular transactional template. Each transactional template can have multiple versions, each version with its own subject and content. Each user can have up to 300 versions across all templates.

For more information about transactional templates, please see our [Transactional Templates documentation](/docs/sendgrid/ui/sending-email/how-to-send-an-email-with-dynamic-templates). You can also manage your Transactional Templates in the [Dynamic Templates section of the Twilio SendGrid App](https://mc.sendgrid.com/dynamic-templates).

## Operation overview

```json
{"path":"https://api.sendgrid.com/v3/templates/{template_id}/versions/{version_id}/activate","method":"post","servers":[{"url":"https://api.sendgrid.com","description":"for global users and subusers"},{"url":"https://api.eu.sendgrid.com","description":"for EU regional subusers"}]}
```

**This endpoint allows you to activate a version of one of your templates.**

## Operation details

### Authentication

API Key

### Headers

```json
[{"in":"header","name":"Authorization","required":true,"default":"Bearer <<YOUR_API_KEY_HERE>>","schema":{"type":"string"}},{"name":"on-behalf-of","in":"header","description":"The `on-behalf-of` header allows you to make API calls from a parent account on behalf of the parent's Subusers or customer accounts. You will use the parent account's API key when using this header. When making a call on behalf of a customer account, the property value should be \"account-id\" followed by the customer account's ID (e.g., `on-behalf-of: account-id <account-id>`). When making a call on behalf of a Subuser, the property value should be the Subuser's username (e.g., `on-behalf-of: <subuser-username>`). See [**On Behalf Of**](/docs/sendgrid/api-reference/how-to-use-the-sendgrid-v3-api/on-behalf-of) for more information.","required":false,"schema":{"type":"string"},"refName":"#/components/parameters/OnBehalfOf","modelName":"__components_parameters_OnBehalfOf"}]
```

### Path parameters

```json
[{"name":"template_id","in":"path","description":"The ID of the original template","required":true,"schema":{"type":"string","format":"uuid"}},{"name":"version_id","in":"path","description":"The ID of the template version","required":true,"schema":{"type":"string","format":"uuid"}}]
```

### Responses

```json
[{"responseCode":"200","schema":{"description":"","content":{"application/json":{"schema":{"title":"Transactional Templates: Version Output","type":"object","required":["name","subject"],"refName":"TransactionalTemplateVersionOutput","modelName":"TransactionalTemplateVersionOutput","properties":{"warnings":{"type":"array","items":{"title":"Warning","type":"object","example":{"message":"A sample warning message."},"refName":"TransactionalTemplateWarning","modelName":"TransactionalTemplateWarning","properties":{"message":{"type":"string","description":"Warning message for the user"}}}},"active":{"type":"integer","description":"Set the version as the active version associated with the template. Only one version of a template can be active. The first version created for a template will automatically be set to Active.","enum":[0,1],"refName":"Active1","modelName":"Active1"},"name":{"type":"string","description":"Name of the transactional template version.","maxLength":100},"html_content":{"type":"string","description":"The HTML content of the Design."},"plain_content":{"type":"string","description":"Plain text content of the Design."},"generate_plain_content":{"type":"boolean","description":"If true, plain_content is always generated from html_content. If false, plain_content is not altered.","default":true},"subject":{"type":"string","description":"Subject of the new transactional template version.","maxLength":255},"editor":{"type":"string","description":"The editor used in the UI.","enum":["code","design"],"refName":"Editor1","modelName":"Editor1"},"test_data":{"type":"string","description":"For dynamic templates only, the mock json data that will be used for template preview and test sends."},"id":{"type":"string","description":"ID of the transactional template version.","format":"uuid"},"template_id":{"type":"string","description":"ID of the transactional template."},"updated_at":{"type":"string","description":"The date and time that this transactional template version was updated."},"thumbnail_url":{"type":"string","description":"A Thumbnail preview of the template's html content."}}},"examples":{"response":{"value":{"id":"8aefe0ee-f12b-4575-b5b7-c97e21cb36f3","template_id":"ddb96bbc-9b92-425e-8979-99464621b543","active":1,"name":"example_version_name","html_content":"<%body%>","plain_content":"<%body%>","generate_plain_content":true,"subject":"<%subject%>","updated_at":"2019-03-13 18:56:33","editor":"code"}}}}}}}]
```

Activate a transactional template version.

```js
const client = require("@sendgrid/client");
client.setApiKey(process.env.SENDGRID_API_KEY);

const template_id = "f15982c1-a82c-4e87-a6b2-a4a63b4b7644";
const version_id = "f15982c1-a82c-4e87-a6b2-a4a63b4b7644";

const request = {
  url: `/v3/templates/${template_id}/versions/${version_id}/activate`,
  method: "POST",
};

client
  .request(request)
  .then(([response, body]) => {
    console.log(response.statusCode);
    console.log(response.body);
  })
  .catch((error) => {
    console.error(error);
  });
```

```python
import os
from sendgrid import SendGridAPIClient


sg = SendGridAPIClient(os.environ.get("SENDGRID_API_KEY"))

template_id = "f15982c1-a82c-4e87-a6b2-a4a63b4b7644"
version_id = "f15982c1-a82c-4e87-a6b2-a4a63b4b7644"

response = (
    sg.client.templates._(template_id).versions._(version_id).activate.post()
)

print(response.status_code)
print(response.body)
print(response.headers)
```

```csharp
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using SendGrid;

public class Program {
    public static async Task Main() {
        string apiKey = Environment.GetEnvironmentVariable("SENDGRID_API_KEY");
        var client = new SendGridClient(apiKey);

        var templateId = "f15982c1-a82c-4e87-a6b2-a4a63b4b7644";
        var versionId = "f15982c1-a82c-4e87-a6b2-a4a63b4b7644";

        var response = await client.RequestAsync(
            method: SendGridClient.Method.POST,
            urlPath: $"templates/{templateId}/versions/{versionId}/activate");

        Console.WriteLine(response.StatusCode);
        Console.WriteLine(response.Body.ReadAsStringAsync().Result);
        Console.WriteLine(response.Headers.ToString());
    }
}
```

```java
import com.sendgrid.*;
import java.io.IOException;

public class Example {
    public static void main(String[] args) throws IOException {
        try {
            SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
            Request request = new Request();
            request.setMethod(Method.POST);
            request.setEndpoint("/templates/f15982c1-a82c-4e87-a6b2-a4a63b4b7644/versions/"
                                + "f15982c1-a82c-4e87-a6b2-a4a63b4b7644/activate");
            Response response = sg.api(request);
            System.out.println(response.getStatusCode());
            System.out.println(response.getBody());
            System.out.println(response.getHeaders());
        } catch (IOException ex) {
            throw ex;
        }
    }
}
```

```go
package main

import (
	"fmt"
	"github.com/sendgrid/sendgrid-go"
	"os"
)

func main() {
	apiKey := os.Getenv("SENDGRID_API_KEY")
	host := "https://api.sendgrid.com"
	request := sendgrid.GetRequest(apiKey, "/v3/templates/f15982c1-a82c-4e87-a6b2-a4a63b4b7644/versions/f15982c1-a82c-4e87-a6b2-a4a63b4b7644/activate", host)
	request.Method = "POST"
	response, err := sendgrid.API(request)
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	} else {
		fmt.Println(response.StatusCode)
		fmt.Println(response.Body)
		fmt.Println(response.Headers)
	}
}
```

```php
<?php
// Uncomment the next line if you're using a dependency loader (such as Composer) (recommended)
// require 'vendor/autoload.php';

// Uncomment next line if you're not using a dependency loader (such as Composer)
// require_once '<PATH TO>/sendgrid-php.php';

$apiKey = getenv("SENDGRID_API_KEY");
$sg = new \SendGrid($apiKey);
$template_id = "f15982c1-a82c-4e87-a6b2-a4a63b4b7644";
$version_id = "f15982c1-a82c-4e87-a6b2-a4a63b4b7644";

try {
    $response = $sg->client
        ->templates()
        ->_($template_id)
        ->versions()
        ->_($version_id)
        ->activate()
        ->post();
    print $response->statusCode() . "\n";
    print_r($response->headers());
    print $response->body() . "\n";
} catch (Exception $ex) {
    echo "Caught exception: " . $ex->getMessage();
}
```

```ruby
require 'sendgrid-ruby'
include SendGrid

sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
template_id = "f15982c1-a82c-4e87-a6b2-a4a63b4b7644"
version_id = "f15982c1-a82c-4e87-a6b2-a4a63b4b7644"

response = sg.client.templates._(template_id).versions._(version_id).activate.post()
puts response.status_code
puts response.headers
puts response.body
```

```bash
curl -X POST "https://api.sendgrid.com/v3/templates/f15982c1-a82c-4e87-a6b2-a4a63b4b7644/versions/f15982c1-a82c-4e87-a6b2-a4a63b4b7644/activate" \
--header "Authorization: Bearer $SENDGRID_API_KEY"
```
