Chilkat Online Tools

delphiDll / Braze Endpoints / Create Email Template

Back to Collection Items

var
http: HCkHttp;
success: Boolean;
json: HCkJsonObject;
resp: HCkHttpResponse;

begin
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

http := CkHttp_Create();

// Use this online tool to generate code from sample JSON: Generate Code to Create JSON

// The following JSON is sent in the request body.

// {
//   "template_name": "email_template_name",
//   "subject": "Welcome to my email template!",
//   "body": "This is the text within my email body and https://www.braze.com/ here is a link to Braze.com.",
//   "plaintext_body": "This is the text within my email body and here is a link to https://www.braze.com/.",
//   "preheader": "My preheader is pretty cool.",
//   "tags": [
//     "Tag1",
//     "Tag2"
//   ]
// }

json := CkJsonObject_Create();
CkJsonObject_UpdateString(json,'template_name','email_template_name');
CkJsonObject_UpdateString(json,'subject','Welcome to my email template!');
CkJsonObject_UpdateString(json,'body','This is the text within my email body and https://www.braze.com/ here is a link to Braze.com.');
CkJsonObject_UpdateString(json,'plaintext_body','This is the text within my email body and here is a link to https://www.braze.com/.');
CkJsonObject_UpdateString(json,'preheader','My preheader is pretty cool.');
CkJsonObject_UpdateString(json,'tags[0]','Tag1');
CkJsonObject_UpdateString(json,'tags[1]','Tag2');

CkHttp_SetRequestHeader(http,'Content-Type','application/json');
// Adds the "Authorization: Bearer {{api_key}}" header.
CkHttp_putAuthToken(http,'{{api_key}}');

resp := CkHttp_PostJson3(http,'https://rest.iad-01.braze.com/templates/email/create','application/json',json);
if (CkHttp_getLastMethodSuccess(http) = False) then
  begin
    Memo1.Lines.Add(CkHttp__lastErrorText(http));
    Exit;
  end;

Memo1.Lines.Add(IntToStr(CkHttpResponse_getStatusCode(resp)));
Memo1.Lines.Add(CkHttpResponse__bodyStr(resp));
CkHttpResponse_Dispose(resp);

CkHttp_Dispose(http);
CkJsonObject_Dispose(json);

Curl Command

curl -X POST
	-H "Content-Type: application/json"
	-H "Authorization: Bearer {{api_key}}"
	-d '{
  "template_name": "email_template_name",
  "subject": "Welcome to my email template!",
  "body": "This is the text within my email body and https://www.braze.com/ here is a link to Braze.com.",
  "plaintext_body": "This is the text within my email body and here is a link to https://www.braze.com/.",
  "preheader": "My preheader is pretty cool.",
  "tags": ["Tag1", "Tag2"]
}'
https://rest.iad-01.braze.com/templates/email/create

Postman Collection Item JSON

{
  "name": "Create Email Template",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json",
        "type": "text"
      },
      {
        "key": "Authorization",
        "value": "Bearer {{api_key}}",
        "type": "text"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n  \"template_name\": \"email_template_name\",\n  \"subject\": \"Welcome to my email template!\",\n  \"body\": \"This is the text within my email body and https://www.braze.com/ here is a link to Braze.com.\",\n  \"plaintext_body\": \"This is the text within my email body and here is a link to https://www.braze.com/.\",\n  \"preheader\": \"My preheader is pretty cool.\",\n  \"tags\": [\"Tag1\", \"Tag2\"]\n}"
    },
    "url": {
      "raw": "https://{{instance_url}}/templates/email/create",
      "protocol": "https",
      "host": [
        "{{instance_url}}"
      ],
      "path": [
        "templates",
        "email",
        "create"
      ]
    },
    "description": "Use the Template REST APIs to programmatically manage the email templates that you have stored on the Braze dashboard, on the Templates & Media page. Braze provides two endpoints for creating and updating your email templates.\n\nUsers' email subscription status can be updated and retrieved via Braze using a RESTful API. You can use the API to set up bi-directional sync between Braze and other email systems or your own database. All API requests are made over HTTPS.\n\nUse the endpoints below to create email templates on the Braze dashboard. These templates will be available on the Templates and Media page. The response from this endpoint will include a field for `email_template_id`, which can be used to update the template in subsequent API calls.\n\n### Request Parameters\n\n| Parameter | Required | Data Type | Description |\n| --------- | ---------| --------- | ----------- |\n|`template_name`|Optional|String|The name of your email template|\n|`subject`|Optional|String|The email template subject line|\n|`body`|Optional|String|The email template body that may include HTML|\n|`plaintext_body`|Optional|String|A plaintext version of the email template body|\n|`preheader`|Optional|String|The email preheader used to generate previews in some clients|\n|`tags`|Optional|String|Tags must already exist|\n|`should_inline_css`|Optional|Boolean|Enables or disables the 'inline_css' feature per template.  If  not provided, Braze will use the default setting for the AppGroup.  One of 'true' or 'false' is expected|\n\n### Possible Errors\n- `Template Name is required`\n\n- `Tags must be an array.`\n\n- `All Tags must be Strings.`\n\n- `Some Tags could not be found.` - A tag was specified which doesn't exist in this environment.\n\n- `Email must have valid content block names.` - The email contains Content Blocks which do not exist in this environment.\n\n- `\"Invalid value for 'should_inline_css'.  One of 'true' or 'false' was expected\"` - 'should_inline_css' accepts boolean characters only.  The error likely is being shown as the value is being sent as a 'string'."
  },
  "response": [
  ]
}