Chilkat Online Tools

PureBasic / Braze Endpoints / Create Scheduled Messages

Back to Collection Items

IncludeFile "CkJsonObject.pb"
IncludeFile "CkHttp.pb"
IncludeFile "CkHttpResponse.pb"

Procedure ChilkatExample()

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

    http.i = CkHttp::ckCreate()
    If http.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success.i

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

    ; The following JSON is sent in the request body.

    ; {
    ;   "broadcast": "false",
    ;   "external_user_ids": "external_user_identifiers",
    ;   "user_aliases": {
    ;     "alias_name": "example_name",
    ;     "alias_label": "example_label"
    ;   },
    ;   "segment_id": "segment_identifiers",
    ;   "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"
    ;         }
    ;       }
    ;     ]
    ;   },
    ;   "campaign_id": "campaign_identifier",
    ;   "send_id": "send_identifier",
    ;   "override_messaging_limits": false,
    ;   "recipient_subscription_state": "subscribed",
    ;   "schedule": {
    ;     "time": "",
    ;     "in_local_time": true,
    ;     "at_optimal_time": true
    ;   },
    ;   "messages": {
    ;     "apple_push": "(optional, Apple Push Object)",
    ;     "android_push": "(optional, Android Push Object)",
    ;     "windows_push": "(optional, Windows Phone 8 Push Object)",
    ;     "windows8_push": "(optional, Windows Universal Push Object)",
    ;     "kindle_push": "(optional, Kindle/FireOS Push Object)",
    ;     "web_push": "(optional, Web Push Object)",
    ;     "email": "(optional, Email object)",
    ;     "webhook": "(optional, Webhook object)",
    ;     "content_card": "(optional, Content Card Object)"
    ;   }
    ; }

    json.i = CkJsonObject::ckCreate()
    If json.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckUpdateString(json,"broadcast","false")
    CkJsonObject::ckUpdateString(json,"external_user_ids","external_user_identifiers")
    CkJsonObject::ckUpdateString(json,"user_aliases.alias_name","example_name")
    CkJsonObject::ckUpdateString(json,"user_aliases.alias_label","example_label")
    CkJsonObject::ckUpdateString(json,"segment_id","segment_identifiers")
    CkJsonObject::ckUpdateString(json,"audience.AND[0].custom_attribute.custom_attribute_name","eye_color")
    CkJsonObject::ckUpdateString(json,"audience.AND[0].custom_attribute.comparison","equals")
    CkJsonObject::ckUpdateString(json,"audience.AND[0].custom_attribute.value","blue")
    CkJsonObject::ckUpdateString(json,"audience.AND[1].custom_attribute.custom_attribute_name","favorite_foods")
    CkJsonObject::ckUpdateString(json,"audience.AND[1].custom_attribute.comparison","includes_value")
    CkJsonObject::ckUpdateString(json,"audience.AND[1].custom_attribute.value","pizza")
    CkJsonObject::ckUpdateString(json,"audience.AND[2].OR[0].custom_attribute.custom_attribute_name","last_purchase_time")
    CkJsonObject::ckUpdateString(json,"audience.AND[2].OR[0].custom_attribute.comparison","less_than_x_days_ago")
    CkJsonObject::ckUpdateInt(json,"audience.AND[2].OR[0].custom_attribute.value",2)
    CkJsonObject::ckUpdateString(json,"audience.AND[2].OR[1].push_subscription_status.comparison","is")
    CkJsonObject::ckUpdateString(json,"audience.AND[2].OR[1].push_subscription_status.value","opted_in")
    CkJsonObject::ckUpdateString(json,"audience.AND[3].email_subscription_status.comparison","is_not")
    CkJsonObject::ckUpdateString(json,"audience.AND[3].email_subscription_status.value","subscribed")
    CkJsonObject::ckUpdateString(json,"audience.AND[4].last_used_app.comparison","after")
    CkJsonObject::ckUpdateString(json,"audience.AND[4].last_used_app.value","2019-07-22T13:17:55+0000")
    CkJsonObject::ckUpdateString(json,"campaign_id","campaign_identifier")
    CkJsonObject::ckUpdateString(json,"send_id","send_identifier")
    CkJsonObject::ckUpdateBool(json,"override_messaging_limits",0)
    CkJsonObject::ckUpdateString(json,"recipient_subscription_state","subscribed")
    CkJsonObject::ckUpdateString(json,"schedule.time","")
    CkJsonObject::ckUpdateBool(json,"schedule.in_local_time",1)
    CkJsonObject::ckUpdateBool(json,"schedule.at_optimal_time",1)
    CkJsonObject::ckUpdateString(json,"messages.apple_push","(optional, Apple Push Object)")
    CkJsonObject::ckUpdateString(json,"messages.android_push","(optional, Android Push Object)")
    CkJsonObject::ckUpdateString(json,"messages.windows_push","(optional, Windows Phone 8 Push Object)")
    CkJsonObject::ckUpdateString(json,"messages.windows8_push","(optional, Windows Universal Push Object)")
    CkJsonObject::ckUpdateString(json,"messages.kindle_push","(optional, Kindle/FireOS Push Object)")
    CkJsonObject::ckUpdateString(json,"messages.web_push","(optional, Web Push Object)")
    CkJsonObject::ckUpdateString(json,"messages.email","(optional, Email object)")
    CkJsonObject::ckUpdateString(json,"messages.webhook","(optional, Webhook object)")
    CkJsonObject::ckUpdateString(json,"messages.content_card","(optional, Content Card Object)")

    resp.i = CkHttp::ckPostJson3(http,"https://rest.iad-01.braze.com/messages/schedule/create","application/json",json)
    If CkHttp::ckLastMethodSuccess(http) = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkJsonObject::ckDispose(json)
        ProcedureReturn
    EndIf

    Debug Str(CkHttpResponse::ckStatusCode(resp))
    Debug CkHttpResponse::ckBodyStr(resp)
    CkHttpResponse::ckDispose(resp)



    CkHttp::ckDispose(http)
    CkJsonObject::ckDispose(json)


    ProcedureReturn
EndProcedure

Curl Command

curl -X POST
	-d '{
    "broadcast": "false",
    "external_user_ids": "external_user_identifiers",
    "user_aliases": {
      "alias_name" : "example_name",
      "alias_label" : "example_label"
    },
    "segment_id": "segment_identifiers",
  "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"
        }
      }
    ]
  },
    "campaign_id": "campaign_identifier",
    "send_id": "send_identifier",
    "override_messaging_limits": false,
  "recipient_subscription_state": "subscribed",
  "schedule": {
    "time": "",
    "in_local_time": true,
    "at_optimal_time": true
  },
  "messages": {
    "apple_push": (optional, Apple Push Object),
    "android_push": (optional, Android Push Object),
    "windows_push": (optional, Windows Phone 8 Push Object),
    "windows8_push": (optional, Windows Universal Push Object),
    "kindle_push": (optional, Kindle/FireOS Push Object),
    "web_push": (optional, Web Push Object),
    "email": (optional, Email object)
    "webhook": (optional, Webhook object)
    "content_card": (optional, Content Card Object)
  }
}\''
https://rest.iad-01.braze.com/messages/schedule/create

Postman Collection Item JSON

{
  "name": "Create Scheduled Messages",
  "request": {
    "method": "POST",
    "header": [
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"broadcast\": \"false\",\n    \"external_user_ids\": \"external_user_identifiers\",\n    \"user_aliases\": {\n      \"alias_name\" : \"example_name\",\n      \"alias_label\" : \"example_label\"\n    },\n    \"segment_id\": \"segment_identifiers\",\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    \"campaign_id\": \"campaign_identifier\",\n    \"send_id\": \"send_identifier\",\n    \"override_messaging_limits\": false,\n  \"recipient_subscription_state\": \"subscribed\",\n  \"schedule\": {\n    \"time\": \"\",\n    \"in_local_time\": true,\n    \"at_optimal_time\": true\n  },\n  \"messages\": {\n    \"apple_push\": (optional, Apple Push Object),\n    \"android_push\": (optional, Android Push Object),\n    \"windows_push\": (optional, Windows Phone 8 Push Object),\n    \"windows8_push\": (optional, Windows Universal Push Object),\n    \"kindle_push\": (optional, Kindle/FireOS Push Object),\n    \"web_push\": (optional, Web Push Object),\n    \"email\": (optional, Email object)\n    \"webhook\": (optional, Webhook object)\n    \"content_card\": (optional, Content Card Object)\n  }\n}'"
    },
    "url": {
      "raw": "https://{{instance_url}}/messages/schedule/create",
      "protocol": "https",
      "host": [
        "{{instance_url}}"
      ],
      "path": [
        "messages",
        "schedule",
        "create"
      ]
    },
    "description": "Use this endpoint to send messages directly from the API.\n\nThe create schedule endpoint allows you to schedule a Campaign, Canvas, or other message to be sent at a designated time (up to 90 days in the future) and provides you with an identifier to reference that message for updates. If you are targeting a segment, a record of your request will be stored in the Developer Console after all scheduled messages have been sent.\n\n### Request Parameters\n\n| Parameter | Required | Data Type | Description |\n| --------- | ---------| --------- | ----------- |\n| `broadcast` | Optional | Boolean | See broadcast -- defaults to false on 8/31/17, must be set to true if \"recipients\" object is omitted |\n| `external_user_ids` | Optional | Array of strings | See external user identifier |\n| `user_aliases` | Optional | Array of user alias objects | See user alias object |\n| `audience` | Optional | Connected audience object | See connected audience |\n| `segment_id` | Optional | String | See segment identifier |\n| `campaign_id`|Required|String| See campaign identifier|\n| `recipients` | Optional | Array of recipient objects | See recipients object |\n| `send_id` | Optional | String | See send identifier | \n| `override_messaging_limits` | Optional | Boolean | Ignore global rate limits for campaigns, defaults to false |\n| `recipient_subscription_state` | Optional | String | Use this to send messages to only users who have opted in ('opted_in'), only users who have subscribed or are opted in ('subscribed') or to all users, including unsubscribed users ('all'), the latter being useful for transactional email messaging. Defaults to 'subscribed' |\n| `schedule` | Required | Schedule object | See schedule object |\n| `messages` | Optional | Messaging object | See messaging object |\n\n### Request Components\n- [Broadcast](https://www.braze.com/docs/api/parameters/#broadcast)\n- [User Alias Object](https://www.braze.com/docs/api/objects_filters/user_alias_object/)\n- [Connected Audience](https://www.braze.com/docs/api/objects_filters/connected_audience/)\n- [Segment Identifier](https://www.braze.com/docs/api/identifier_types/)\n- [Campaign Identifier](https://www.braze.com/docs/api/identifier_types/)\n- [Schedule Object](https://www.braze.com/docs/api/objects_filters/schedule_object/)\n- [API Parameters](https://www.braze.com/docs/api/parameters)\n\n### Available Messaging Objects\n\n- [Android Objects](https://www.braze.com/docs/api/objects_filters/android_objects/)\n- [Apple Objects](https://www.braze.com/docs/api/objects_filters/apple_objects/)\n- [Content Cards Object](https://www.braze.com/docs/api/objects_filters/content_cards_object/)\n- [Email Object](https://www.braze.com/docs/api/objects_filters/email_object/)\n- [Kindle or FireOS Object](https://www.braze.com/docs/api/objects_filters/kindle_and_fireos_object/)\n- [SMS Object](https://www.braze.com/docs/api/objects_filters/sms_object/)\n- [Web Objects](https://www.braze.com/docs/api/objects_filters/web_objects/)\n- [Webhook Object](https://www.braze.com/docs/api/objects_filters/webhook_object/)\n- [Windows Objects](https://www.braze.com/docs/api/objects_filters/windows_objects/)"
  },
  "response": [
  ]
}