SQL Server / Braze Endpoints / Schedule API Triggered Canvases
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.
-- {
-- "canvas_id": "canvas_identifier",
-- "recipients": [
-- {
-- "user_alias": "example_alias",
-- "external_user_id": "external_user_identifier",
-- "trigger_properties": "",
-- "canvas_entry_properties": {}
-- }
-- ],
-- "audience": {
-- "AND": [
-- {
-- "custom_attribute": {
-- "custom_attribute_name": "eye_color",
-- "comparison": "equals",
-- "value": "blue"
-- }
-- },
-- {
-- "custom_attribute": {
-- "custom_attribute_name": "favorite_foods",
-- "comparison": "includes_value",
-- "value": "pizza"
-- }
-- },
-- {
-- "OR": [
-- {
-- "custom_attribute": {
-- "custom_attribute_name": "last_purchase_time",
-- "comparison": "less_than_x_days_ago",
-- "value": 2
-- }
-- },
-- {
-- "push_subscription_status": {
-- "comparison": "is",
-- "value": "opted_in"
-- }
-- }
-- ]
-- },
-- {
-- "email_subscription_status": {
-- "comparison": "is_not",
-- "value": "subscribed"
-- }
-- },
-- {
-- "last_used_app": {
-- "comparison": "after",
-- "value": "2019-07-22T13:17:55+0000"
-- }
-- }
-- ]
-- },
-- "broadcast": false,
-- "canvas_entry_properties": {},
-- "schedule": {
-- "time": "",
-- "in_local_time": false,
-- "at_optimal_time": false
-- }
-- }
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, 'canvas_id', 'canvas_identifier'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'recipients[0].user_alias', 'example_alias'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'recipients[0].external_user_id', 'external_user_identifier'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'recipients[0].trigger_properties', ''
EXEC sp_OAMethod @json, 'UpdateNewObject', @success OUT, 'recipients[0].canvas_entry_properties'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'audience.AND[0].custom_attribute.custom_attribute_name', 'eye_color'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'audience.AND[0].custom_attribute.comparison', 'equals'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'audience.AND[0].custom_attribute.value', 'blue'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'audience.AND[1].custom_attribute.custom_attribute_name', 'favorite_foods'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'audience.AND[1].custom_attribute.comparison', 'includes_value'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'audience.AND[1].custom_attribute.value', 'pizza'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'audience.AND[2].OR[0].custom_attribute.custom_attribute_name', 'last_purchase_time'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'audience.AND[2].OR[0].custom_attribute.comparison', 'less_than_x_days_ago'
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'audience.AND[2].OR[0].custom_attribute.value', 2
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'audience.AND[2].OR[1].push_subscription_status.comparison', 'is'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'audience.AND[2].OR[1].push_subscription_status.value', 'opted_in'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'audience.AND[3].email_subscription_status.comparison', 'is_not'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'audience.AND[3].email_subscription_status.value', 'subscribed'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'audience.AND[4].last_used_app.comparison', 'after'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'audience.AND[4].last_used_app.value', '2019-07-22T13:17:55+0000'
EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'broadcast', 0
EXEC sp_OAMethod @json, 'UpdateNewObject', @success OUT, 'canvas_entry_properties'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'schedule.time', ''
EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'schedule.in_local_time', 0
EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'schedule.at_optimal_time', 0
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/canvas/trigger/schedule/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 '{
"canvas_id": "canvas_identifier",
"recipients": [{
"user_alias": "example_alias",
"external_user_id": "external_user_identifier",
"trigger_properties": "",
"canvas_entry_properties": {}
}],
"audience": {
"AND": [
{
"custom_attribute": {
"custom_attribute_name": "eye_color",
"comparison": "equals",
"value": "blue"
}
},
{
"custom_attribute": {
"custom_attribute_name": "favorite_foods",
"comparison": "includes_value",
"value": "pizza"
}
},
{
"OR": [
{
"custom_attribute": {
"custom_attribute_name": "last_purchase_time",
"comparison": "less_than_x_days_ago",
"value": 2
}
},
{
"push_subscription_status": {
"comparison": "is",
"value": "opted_in"
}
}
]
},
{
"email_subscription_status": {
"comparison": "is_not",
"value": "subscribed"
}
},
{
"last_used_app": {
"comparison": "after",
"value": "2019-07-22T13:17:55+0000"
}
}
]
},
"broadcast": false,
"canvas_entry_properties": {},
"schedule": {
"time": "",
"in_local_time": false,
"at_optimal_time": false
}
}'
https://rest.iad-01.braze.com/canvas/trigger/schedule/create
Postman Collection Item JSON
{
"name": "Schedule API Triggered Canvases",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Authorization",
"value": "Bearer {{api_key}}",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"canvas_id\": \"canvas_identifier\",\n \"recipients\": [{\n \"user_alias\": \"example_alias\",\n \"external_user_id\": \"external_user_identifier\",\n \"trigger_properties\": \"\",\n \"canvas_entry_properties\": {}\n }],\n \"audience\": {\n \"AND\": [\n {\n \"custom_attribute\": {\n \"custom_attribute_name\": \"eye_color\",\n \"comparison\": \"equals\",\n \"value\": \"blue\"\n }\n },\n {\n \"custom_attribute\": {\n \"custom_attribute_name\": \"favorite_foods\",\n \"comparison\": \"includes_value\",\n \"value\": \"pizza\"\n }\n },\n {\n \"OR\": [\n {\n \"custom_attribute\": {\n \"custom_attribute_name\": \"last_purchase_time\",\n \"comparison\": \"less_than_x_days_ago\",\n \"value\": 2\n }\n },\n {\n \"push_subscription_status\": {\n \"comparison\": \"is\",\n \"value\": \"opted_in\"\n }\n }\n ]\n },\n {\n \"email_subscription_status\": {\n \"comparison\": \"is_not\",\n \"value\": \"subscribed\"\n }\n },\n {\n \"last_used_app\": {\n \"comparison\": \"after\",\n \"value\": \"2019-07-22T13:17:55+0000\"\n }\n }\n ]\n },\n \"broadcast\": false,\n \"canvas_entry_properties\": {},\n \"schedule\": {\n \"time\": \"\",\n \"in_local_time\": false,\n \"at_optimal_time\": false\n }\n}\n "
},
"url": {
"raw": "https://{{instance_url}}/canvas/trigger/schedule/create",
"protocol": "https",
"host": [
"{{instance_url}}"
],
"path": [
"canvas",
"trigger",
"schedule",
"create"
],
"query": [
{
"key": "",
"value": "",
"disabled": true
},
{
"key": "",
"value": "",
"disabled": true
},
{
"key": "",
"value": "",
"disabled": true
},
{
"key": "",
"value": "",
"disabled": true
}
]
},
"description": "Use this endpoint to trigger API Triggered Canvases, which are created on the Dashboard and initiated via the API. You can pass in `canvas_entry_properties` that will be templated into the messages sent by the first steps of the Canvas.\n\nThis endpoint allows you to schedule Canvas messages (up to 90 days in advance) via API Triggered delivery, allowing you to decide what action should trigger the message to be sent. Please note that to send messages with this endpoint, you must have a Canvas ID, created when you build a Canvas.\n\n### Request Parameters\n\n| Parameter | Required | Data Type | Description |\n| --------- | ---------| --------- | ----------- |\n|`canvas_id`|Required|String| See canvas identifier|\n|`send_id` | Optional | String | See send identifier |\n|`recipients` | Optional | Array of recipient objects | See recipients object |\n|`audience` | Optional | Connected audience object | See connected audience |\n|`broadcast` | Optional | Boolean | See broadcast -- defaults to false on 8/31/17, must be set to true if \"recipients\" object is omitted |\n| `trigger_properties` | Optional | Object | Personalization key value pairs for all users in this send; see trigger properties |\n| `schedule` | Required | Schedule object | See schedule object |\n\n## Request Components\n- [Canvas Identifier](https://www.braze.com/docs/api/identifier_types/)\n- [Recipients](https://www.braze.com/docs/api/objects_filters/recipient_object/)\n- [Connected Audience](https://www.braze.com/docs/api/objects_filters/connected_audience/)\n- [Broadcast](https://www.braze.com/docs/api/parameters/#broadcast)\n- [Trigger Properties](https://www.braze.com/docs/api/objects_filters/trigger_properties_object/)\n- [Schedule Object](https://www.braze.com/docs/api/objects_filters/schedule_object/)"
},
"response": [
]
}