Chilkat Online Tools

SQL Server / Braze Endpoints / Create Content Block

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.

    -- {
    --   "name": "content_block",
    --   "description": "This is my content block",
    --   "content": "HTML content within block",
    --   "state": "draft",
    --   "tags": [
    --     "marketing"
    --   ]
    -- }

    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, 'name', 'content_block'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'description', 'This is my content block'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'content', 'HTML content within block'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'state', 'draft'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'tags[0]', 'marketing'

    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/content_blocks/create', '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 '{
  "name": "content_block",
  "description": "This is my content block",
  "content": "HTML content within block",
  "state": "draft",
  "tags": ["marketing"]
}'
https://rest.iad-01.braze.com/content_blocks/create

Postman Collection Item JSON

{
  "name": "Create Content Block",
  "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  \"name\": \"content_block\",\n  \"description\": \"This is my content block\",\n  \"content\": \"HTML content within block\",\n  \"state\": \"draft\",\n  \"tags\": [\"marketing\"]\n}\n"
    },
    "url": {
      "raw": "https://{{instance_url}}/content_blocks/create",
      "protocol": "https",
      "host": [
        "{{instance_url}}"
      ],
      "path": [
        "content_blocks",
        "create"
      ]
    },
    "description": "This endpoint will create a Content Block.\n\n### Request Parameters\n\n| Parameter | Required | Data Type | Description |\n|---|---|---|---|\n| `name` | Yes | String | Must be less than 100 characters. |\n| `description` | No | String | The description of the content block. Must be less than 250 characters. |\n| `content` | Yes | String | HTML or text content within Content Block.\n| `state` | Optional | String | Choose \"active\" or \"draft\". Defaults to \"active\" if not specified. |\n| `tags` | No | Array of strings | Tags must already exist. |\n\n### Successful Response Properties\n\n```json\n{\n  \"content_block_id\": \"newly-generated-block-id\",\n  \"liquid_tag\": \"generated-block-tag-from-name\",\n  \"created_at\": \"time-created-in-iso\",\n  \"message\": success\n}\n```\n\n### Possible Errors\n- `Content cannot be blank.`\n\n- `Content must be a string.`\n\n- `Content must be smaller than 51200.`\nThe content in your content block must be less than 50kb total.\n\n- `Unable to parse liquid string.`\nThe liquid provided is not valid or parsable. Please try again or reach out to support.\n\n- `Content Block cannot be referenced within itself.`\n\n- `Content Block description cannot be blank.`\n\n- `Content Block description must be a string.`\n\n- `Content block description must be shorter than 250`\nYour content block description must be less than 250 characters. \n\n- `Content Block name cannot be blank.`\n\n- `Content Block name must be a shorter than 100.`\nYour content block name must be shorter than 100 characters. \n\n- `Content Block name can only contain alphanumeric characters.`\nContent Block names can include any of the following characters: the letters (capitalized or lowercase) `A` through `Z`, the numbers `0` through `9`, dashes `-`, and underscores `_`. It cannot contain non-alphanumeric characters like emojis, `!`, `@`, `~`, `&`, and other \"special\" characters.\n\n- `Content Block with this name already exists.`\n\n- `Content Block state must be either Active or Draft.`\n\n- `Tags must be an array.`\n\n- `All Tags must be Strings.`\n\n- `Some Tags could not be found.`"
  },
  "response": [
  ]
}