Chilkat Online Tools

DataFlex / Braze Endpoints / Create Email Template

Back to Collection Items

Use ChilkatAx-win32.pkg

Procedure Test
    Handle hoHttp
    Boolean iSuccess
    Variant vJson
    Handle hoJson
    Variant vResp
    Handle hoResp
    String sTemp1
    Integer iTemp1
    Boolean bTemp1

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

    Get Create (RefClass(cComChilkatHttp)) To hoHttp
    If (Not(IsComObjectCreated(hoHttp))) Begin
        Send CreateComObject of hoHttp
    End

    // 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"
    //   ]
    // }

    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End
    Get ComUpdateString Of hoJson "template_name" "email_template_name" To iSuccess
    Get ComUpdateString Of hoJson "subject" "Welcome to my email template!" To iSuccess
    Get ComUpdateString Of hoJson "body" "This is the text within my email body and https://www.braze.com/ here is a link to Braze.com." To iSuccess
    Get ComUpdateString Of hoJson "plaintext_body" "This is the text within my email body and here is a link to https://www.braze.com/." To iSuccess
    Get ComUpdateString Of hoJson "preheader" "My preheader is pretty cool." To iSuccess
    Get ComUpdateString Of hoJson "tags[0]" "Tag1" To iSuccess
    Get ComUpdateString Of hoJson "tags[1]" "Tag2" To iSuccess

    Send ComSetRequestHeader To hoHttp "Content-Type" "application/json"
    // Adds the "Authorization: Bearer {{api_key}}" header.
    Set ComAuthToken Of hoHttp To "{{api_key}}"

    Get pvComObject of hoJson to vJson
    Get ComPostJson3 Of hoHttp "https://rest.iad-01.braze.com/templates/email/create" "application/json" vJson To vResp
    If (IsComObject(vResp)) Begin
        Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
        Set pvComObject Of hoResp To vResp
    End
    Get ComLastMethodSuccess Of hoHttp To bTemp1
    If (bTemp1 = False) Begin
        Get ComLastErrorText Of hoHttp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComStatusCode Of hoResp To iTemp1
    Showln iTemp1
    Get ComBodyStr Of hoResp To sTemp1
    Showln sTemp1
    Send Destroy of hoResp


End_Procedure

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": [
  ]
}