Chilkat Online Tools

SQL Server / Braze Endpoints / Update Email Template

Back to Collection Items

-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    -- Important: Do not use nvarchar(max).  See the warning about using nvarchar(max).
    DECLARE @sTmp0 nvarchar(4000)
    -- This example assumes the Chilkat API to have been previously unlocked.
    -- See Global Unlock Sample for sample code.

    DECLARE @http int
    -- Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

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

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

    -- {
    --   "email_template_id": "email_template_id",
    --   "template_name": "Weekly Newsletter",
    --   "subject": "This Week's Styles",
    --   "body": "Check out this week's digital lookbook to inspire your outfits. Take a look at https://www.braze.com/",
    --   "plaintext_body": "This is the updated text within my email body and here is a link to https://www.braze.com/.",
    --   "preheader": "We want you to have the best looks this Summer",
    --   "tags": [
    --     "Tag1",
    --     "Tag2"
    --   ]
    -- }

    DECLARE @json int
    -- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT

    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'email_template_id', 'email_template_id'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'template_name', 'Weekly Newsletter'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'subject', 'This Week''s Styles'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'body', 'Check out this week''s digital lookbook to inspire your outfits. Take a look at https://www.braze.com/'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'plaintext_body', 'This is the updated text within my email body and here is a link to https://www.braze.com/.'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'preheader', 'We want you to have the best looks this Summer'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'tags[0]', 'Tag1'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'tags[1]', 'Tag2'

    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Content-Type', 'application/json'
    -- Adds the "Authorization: Bearer {{api_key}}" header.
    EXEC sp_OASetProperty @http, 'AuthToken', '{{api_key}}'

    DECLARE @resp int
    EXEC sp_OAMethod @http, 'PostJson3', @resp OUT, 'https://rest.iad-01.braze.com/templates/email/update', 'application/json', @json
    EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT
    IF @iTmp0 = 0
      BEGIN
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @json
        RETURN
      END

    EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
    PRINT @iTmp0
    EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT
    PRINT @sTmp0
    EXEC @hr = sp_OADestroy @resp


    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @json


END
GO

Curl Command

curl -X POST
	-H "Content-Type: application/json"
	-H "Authorization: Bearer {{api_key}}"
	-d '{
  "email_template_id": "email_template_id",
  "template_name": "Weekly Newsletter",
  "subject": "This Week\'s Styles",
  "body": "Check out this week\'s digital lookbook to inspire your outfits. Take a look at https://www.braze.com/",
  "plaintext_body": "This is the updated text within my email body and here is a link to https://www.braze.com/.",
  "preheader": "We want you to have the best looks this Summer",
  "tags": ["Tag1", "Tag2"]
}'
https://rest.iad-01.braze.com/templates/email/update

Postman Collection Item JSON

{
  "name": "Update Email Template",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "type": "text",
        "value": "application/json"
      },
      {
        "key": "Authorization",
        "type": "text",
        "value": "Bearer {{api_key}}"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n  \"email_template_id\": \"email_template_id\",\n  \"template_name\": \"Weekly Newsletter\",\n  \"subject\": \"This Week's Styles\",\n  \"body\": \"Check out this week's digital lookbook to inspire your outfits. Take a look at https://www.braze.com/\",\n  \"plaintext_body\": \"This is the updated text within my email body and here is a link to https://www.braze.com/.\",\n  \"preheader\": \"We want you to have the best looks this Summer\",\n  \"tags\": [\"Tag1\", \"Tag2\"]\n}"
    },
    "url": {
      "raw": "https://rest.iad-01.braze.com/templates/email/update",
      "protocol": "https",
      "host": [
        "rest",
        "iad-01",
        "braze",
        "com"
      ],
      "path": [
        "templates",
        "email",
        "update"
      ]
    },
    "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\n> Use the endpoints below to update email templates on the Braze dashboard. You can access an email template's `email_template_id` by navigating to it on the Templates and Media page. The email template creation API endpoint will also return an `email_template_id` reference.<br><br>All fields other than the `email_template_id` are optional, but you must specify at least one field to update.\n\n### Request Parameters\n| Parameter | Required | Data Type | Description |\n| --------- | ---------| --------- | ----------- |\n|`email_template_id`| Required |String|Your email template's API Identifier.|\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### Request Components\n- [Template Identifier](https://www.braze.com/docs/api/identifier_types/)\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.`\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": [
  ]
}