Chilkat Online Tools

DataFlex / Braze Endpoints / Schedule API Triggered Campaigns

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.

    // {
    //   "campaign_id": "campaign_identifier",
    //   "send_id": "send_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,
    //   "trigger_properties": {},
    //   "schedule": {
    //     "time": "",
    //     "in_local_time": false,
    //     "at_optimal_time": false
    //   }
    // }

    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End
    Get ComUpdateString Of hoJson "campaign_id" "campaign_identifier" To iSuccess
    Get ComUpdateString Of hoJson "send_id" "send_identifier" To iSuccess
    Get ComUpdateString Of hoJson "recipients[0].user_alias" "example_alias" To iSuccess
    Get ComUpdateString Of hoJson "recipients[0].external_user_id" "external_user_identifier" To iSuccess
    Get ComUpdateNewObject Of hoJson "recipients[0].trigger_properties" To iSuccess
    Get ComUpdateNewObject Of hoJson "recipients[0].canvas_entry_properties" To iSuccess
    Get ComUpdateString Of hoJson "audience.AND[0].custom_attribute.custom_attribute_name" "eye_color" To iSuccess
    Get ComUpdateString Of hoJson "audience.AND[0].custom_attribute.comparison" "equals" To iSuccess
    Get ComUpdateString Of hoJson "audience.AND[0].custom_attribute.value" "blue" To iSuccess
    Get ComUpdateString Of hoJson "audience.AND[1].custom_attribute.custom_attribute_name" "favorite_foods" To iSuccess
    Get ComUpdateString Of hoJson "audience.AND[1].custom_attribute.comparison" "includes_value" To iSuccess
    Get ComUpdateString Of hoJson "audience.AND[1].custom_attribute.value" "pizza" To iSuccess
    Get ComUpdateString Of hoJson "audience.AND[2].OR[0].custom_attribute.custom_attribute_name" "last_purchase_time" To iSuccess
    Get ComUpdateString Of hoJson "audience.AND[2].OR[0].custom_attribute.comparison" "less_than_x_days_ago" To iSuccess
    Get ComUpdateInt Of hoJson "audience.AND[2].OR[0].custom_attribute.value" 2 To iSuccess
    Get ComUpdateString Of hoJson "audience.AND[2].OR[1].push_subscription_status.comparison" "is" To iSuccess
    Get ComUpdateString Of hoJson "audience.AND[2].OR[1].push_subscription_status.value" "opted_in" To iSuccess
    Get ComUpdateString Of hoJson "audience.AND[3].email_subscription_status.comparison" "is_not" To iSuccess
    Get ComUpdateString Of hoJson "audience.AND[3].email_subscription_status.value" "subscribed" To iSuccess
    Get ComUpdateString Of hoJson "audience.AND[4].last_used_app.comparison" "after" To iSuccess
    Get ComUpdateString Of hoJson "audience.AND[4].last_used_app.value" "2019-07-22T13:17:55+0000" To iSuccess
    Get ComUpdateBool Of hoJson "broadcast" False To iSuccess
    Get ComUpdateNewObject Of hoJson "trigger_properties" To iSuccess
    Get ComUpdateString Of hoJson "schedule.time" "" To iSuccess
    Get ComUpdateBool Of hoJson "schedule.in_local_time" False To iSuccess
    Get ComUpdateBool Of hoJson "schedule.at_optimal_time" False 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/campaigns/trigger/schedule/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 '{
  "campaign_id": "campaign_identifier",
  "send_id": "send_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,
  "trigger_properties": {},
  "schedule": {
    "time": "",
    "in_local_time": false,
    "at_optimal_time": false
  }
}'
https://rest.iad-01.braze.com/campaigns/trigger/schedule/create

Postman Collection Item JSON

{
  "name": "Schedule API Triggered Campaigns",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      },
      {
        "key": "Authorization",
        "value": "Bearer {{api_key}}",
        "type": "text"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n  \"campaign_id\": \"campaign_identifier\",\n  \"send_id\": \"send_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  \"trigger_properties\": {},\n  \"schedule\": {\n    \"time\": \"\",\n    \"in_local_time\": false,\n    \"at_optimal_time\": false\n  }\n}\n"
    },
    "url": {
      "raw": "https://{{instance_url}}/campaigns/trigger/schedule/create",
      "protocol": "https",
      "host": [
        "{{instance_url}}"
      ],
      "path": [
        "campaigns",
        "trigger",
        "schedule",
        "create"
      ]
    },
    "description": "Use this endpoint to trigger API Triggered Campaigns, which are created on the Dashboard and initiated via the API. You can pass in `trigger_properties` that will be templated into the message itself.\n\nThis endpoint allows you to send Campaign 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 Campaign ID, created when you build an API Triggered Campaign.\n\n### Request Parameters\n\n| Parameter | Required | Data Type | Description |\n| --------- | ---------| --------- | ----------- |\n|`campaign_id`|Required|String| See campaign 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- [Campaign 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": [
  ]
}