Broadcast

Method to trigger broadcast messages using java SDK

You can use this method to send instant notifications to a list of users.

Pre-requisites

Create a list of users

Data Structure of Broadcast body

Brodcast body with all possible configurations

broadcast_body = {
  "list_id": "_list_id_",
  "template": "_template_slug_",
  "notification_category": "_",
  "channels": [],
  "delay": "_time_delay_",
  "trigger_at": "_ISO_timestamp_",
  "data": {
    "key1": "value1",
    "key2": "value2"

  }

Broadcast body field description:

ParameterDescriptionFormatObligation
list_idlist of users that you want to send broadcast messages to.textMandatory
templateIt is the unique slug of the template created on SuprSend platform. You can get this slug by clicking on the clipboard icon next to the Template name on SuprSend templates page.
It is the same for all channels
textMandatory
notification_categoryYou can understand more about them in the Notification Category documentationsystem / transactional / promotionalMandatory
channelsUser channels on which the broadcast messages to be sent. If not provided, it will trigger message on all available channels in user profile.
Currently, broadcast is supported in iospush and androidpush channel. So, please specify these channels in your broadcast body
comma-separated-stringOptional
delayBroadcast will be halted for the time mentioned in delay, and become active once the delay period is over.XXdXXhXXmXXs or if its number (n) then delay is in seconds (n)Optional
trigger_atTrigger broadcast on a specific date-timedate string in ISO 8601
eg. "2021-08-27T20:14:51.643Z"
Optional
datavariable data defined in templatesJSON
"data":
{ "key": {
"key": "value",
"key": "value"
}
},
Optional

Sample broadcast body

broadcast_body = {
  "list_id": "bulk_list",
  "template": "purchase-confirmation",
  "notification_category": "transactional",
  "channels": ["iospush"],
  # "delay": 30,
  # "trigger_at": "2022-12-27T11:14:51.643Z",
  "data": {
    "amount": "$100",
    "product_name": "Medicines"
  }

Triggering Broadcast

You can trigger broadcast using suprClient.subscriberLists.broadcast() method.

import org.json.JSONObject;

import suprsend.Suprsend;
import suprsend.SuprsendAPIException;
import suprsend.SubscriberListBroadcast;
import suprsend.SuprsendValidationError;

public class Lists {
  public static void main(String[] args) throws Exception {
    broadcast();
  }
  
  private static Subscriber broadcast() throws SuprsendException {
        Suprsend suprsendClient = new Suprsend("_workspace_key_", "_workspace_secret_");
        
    // Create broadcast body
    String listId = "anjali_id_1";
        String templateSlug = "test_karthick";
        String notifCategory = "transactional";
        //String delay = "30";
        //String triggerAt = "2023-03-06T18:56:51.643Z";
        //String idempKey = "__idempotency_key__";
        //String brandId = "__brand_id__";
    
        // To send broadcast on a particular channel 
        //ArrayList<String> channels =  new ArrayList<>(Arrays.asList("androidpush","email"));
    JSONObject body = new JSONObject().put("list_id",listId)
      .put("template",templateSlug)
      .put("notification_category",notifCategory)
      .put("data", new JSONObject()
           .put("link_suffix", "https://s3.amazonaws.com/unroll-images-production/projects%2F22692%2F1630591176038-322170")
           .put("first_name", "Joe"))

        // 
        SubscriberListBroadcast broadcastIns = new SubscriberListBroadcast(body);
    
        // Broadcast with idempotency key and brand id
        // SubscriberListBroadcast broadcastIns = new SubscriberListBroadcast(body, idempKey, brandId);
        JSONObject res = suprClient.subscriberLists.broadcast(broadcastIns);
        System.out.println(res);
    }