Create, update, & manage objects and their subscriptions with Java SDK.
Objects in SuprSend represent non-user entities such as organizations, teams , roles, and projects. Understand more about objects from our objects documentation
Object updating is an upsert function, meaning it would always override existing key values on further updates. Object id and type is mandatory to create object. You can optionally pass object properties (to use in template or workflow condition) or channel information (send notification on object channels) in the payload.
Copy
Ask AI
import org.json.JSONObject;import suprsend.Suprsend;public class ObjectEdit { public static void main(String[] args) throws Exception { objectEditInstance(); } public static void getSuprClient() throws Exception { Suprsend suprsendClient = new Suprsend("_workspace_key_", "_workspace_secret_"); return suprsendClient; } public static void objectEditInstance() throws Exception { Suprsend suprsendClient = getSuprClient(); // Instiantiate object String objectType = "departments"; String objectId = "engineering"; // Object Payload to upsert properties and communication channels JSONObject payload = new JSONObject() .put("k1", "value1"); .put("$email", "devs@abc.com"); JSONObject object = suprClient.objects.upsert(objectType, objectId, payload); System.out.println(object); }}
Use this to modify an object, typically for removing channels or unsetting properties. The payload will follow the same structure as the Object Edit API.
Copy
Ask AI
import org.json.JSONObject;import suprsend.Suprsend;public class ObjectEdit { public static void objectEditInstance() throws Exception { Suprsend suprsendClient = getSuprClient(); // Instiantiate object String objectType = "departments"; String objectId = "engineering"; // Object Payload JSONObject payload = new JSONObject().put("operations", new JSONObject[] { new JSONObject().put("$set", new JSONObject().put("k2", "value2")) }); JSONObject object = suprClient.objects.edit(objectType, objectId, payload); System.out.println(object); }}
Use object_ins.add* method(s) to add user channels in a profile
Copy
Ask AI
// Add Emailobject_ins.addEmail("example@example.com");//Add SMSobject_ins.addSms("+919999999999");//Add Whatsappobject_ins.addWhatsapp("+919999999999");// Add Androidpush token.Pass the vendor as 2nd param.object_ins.addAndroidpush("androidpush_fcm_token__","fcm");// Add iospush tokenobject_ins.addIospush("__iospush_apns_token__");// Add Slack using user email idJSONObject slackIdent = new JSONObject() .put("access_token", "xoxb-XXXXXXXX") .put("email", "user@example.com");object_ins.addSlack(slackIdent);// Add Slack using member_id of the user if knownJSONObject slackIdent = new JSONObject() .put("access_token", "xoxb-XXXXXXXX") .put("user_id", "U03XXXXXXXX");object_ins.addSlack(slackIdent);// Add Slack channel_idJSONObject slackIdent = new JSONObject() .put("access_token", "xoxb-XXXXXXXX") .put("channel_id", "C04XXXXXXXX");object_ins.addSlack(slackIdent);// Add Slack incoming webhookJSONObject slackIdent = new JSONObject() .put("incoming_webhook", new JSONObject().put("url", "https://hooks.slack.com/services/TXXXX/BXXXX/XXXXXXX"))object_ins.addSlack(slackIdent);// Add Webpush token json (VAPID)JSONObject webpush = new JSONObject() .put("endpoint", "__end_point__") .put("expirationTime", "") .put("keys", new JSONObject() .put("p256dh", "__p256dh__") .put("auth", "__auth_key__"));object_ins.addWebpush(webpush, "vapid");
Remove Channels
Use object_ins.remove* method(s) to remove channels from an object profile
Copy
Ask AI
// Remove Emailobject_ins.removeEmail("example@example.com");//Remove SMSobject_ins.removeSms("+919999999999");//Remove Whatsappobject_ins.removeWhatsapp("+919999999999");// Remove Androidpush token.Pass the vendor as 2nd param.object_ins.removeAndroidpush("androidpush_fcm_token__","fcm");// Remove iospush tokenobject_ins.removeIospush("__iospush_apns_token__");// Remove Slack using user email idJSONObject slackIdent = new JSONObject() .put("access_token", "xoxb-XXXXXXXX") .put("email", "user@example.com");object_ins.removeSlack(slackIdent);// Remove Slack using member_id of the user if knownJSONObject slackIdent = new JSONObject() .put("access_token", "xoxb-XXXXXXXX") .put("user_id", "U03XXXXXXXX");object_ins.removeSlack(slackIdent);// Remove Slack channel_idJSONObject slackIdent = new JSONObject() .put("access_token", "xoxb-XXXXXXXX") .put("channel_id", "C04XXXXXXXX");object_ins.removeSlack(slackIdent);// Remove Slack incoming webhookJSONObject slackIdent = new JSONObject() .put("incoming_webhook", new JSONObject().put("url", "https://hooks.slack.com/services/TXXXX/BXXXX/XXXXXXX")) object_ins.removeSlack(slackIdent);// Remove Webpush token json (VAPID)JSONObject webpush = new JSONObject() .put("endpoint", "__end_point__") .put("expirationTime", "") .put("keys", new JSONObject() .put("p256dh", "__p256dh__") .put("auth", "__auth_key__"));object_ins.removeWebpush(webpush, "vapid");
Remove Channels in bulk
This method will delete/unset all values in specified channel for object (ex: remove all emails attached to object).
Copy
Ask AI
object_ins.unset("$email");object_ins.unset(Arrays.asList(new String[] { "$sms", "$email" }));// available channel keys -//{"$email","$whatsapp","$sms","$androidpush","$iospush","$webpush","$slack","$ms_teams"}
Set Preferred language
If you want to send notification in user’s preferred language, you can set it by passing language code in this method. This is useful especially for the applications which offer vernacular or multi-lingual support.
Copy
Ask AI
object_ins.setPreferredLanguage("es")
Set Preferred Timezone
You can set timezone of user using this method. Value for timezone must be from amongst the IANA timezones.
Copy
Ask AI
object_ins.setTimezone("America/Los_Angeles");
Set
Set any custom property using this method. It will shallow merge existing properties with new values. Key shouldn’t start with $ or ss.
Copy
Ask AI
//set single propertyobject_ins.set(key, value);object_ins.set("company_name", "ABC company");//set multiple propertiesJSONObject objectsProperties = new JSONObject() .put("company_name", "ABC company") .put("city", "San Francisco")object_ins.set(objectsProperties);
Unset
Remove any custom property key using this method.
Copy
Ask AI
//unset single propertyobject_ins.unset(key);object_ins.unset("company_name");//unset multiple propertiesobject_ins.unset(Arrays.asList(new String[] { "$sms", "wishlist" }));
Append
This method will append a value to the list for a given property.
Copy
Ask AI
//append single propertyobject_ins.append("array", "k1");//append multiple propertiesJSONObject objectsProperties = new JSONObject() .put("wishlist", "iphone12") .put("products", "tenancy");object_ins.append(objectsProperties);
Remove
This method will remove a value from the list for a given property.
Copy
Ask AI
//append single propertyobject_ins.remove("array", "k1");//append multiple propertiesJSONObject objectsProperties = new JSONObject() .put("wishlist", "iphone12") .put("products", "tenancy");object_ins.remove(objectsProperties);
Set Once
Works just like object_ins.set, except it will not overwrite existing property values. This is useful for properties like First login date
Add the given amount to an existing property on the object. If the object does not already have the associated property, the amount will be added to zero. To reduce a property, provide a negative number for the value.
List objects for an object_type. You can also pass listing options in the payload which includes limit,before,after
Copy
Ask AI
String objectType = "__objecttype__";// optional params to pass limit (default=10) and cursor pointer for fetching the next set of resultsHashMap<String, Object> opts = new HashMap<String, Object>() { { put("limit", 10); put("after", "01HFS04E4J29KHPYRK7HT3YQQ5"); }};JSONObject res = suprClient.objects.list(objectType, opts);System.out.println(res);
String objectType = "__objecttype__";String objectId = "__objectid__";// optional params to pass limit (default=10) and cursor pointer for fetching the next set of resultsHashMap<String, Object> opts = new HashMap<String, Object>() { { put("limit", 10); put("after", "01HFS04E4J29KHPYRK7HT3YQQ5"); }};JSONObject res = suprClient.objects.getSubscriptions(objectType, objectId, opts);System.out.println(res);
An object can subscribe to other objects. Use this method to get the list of all objects that the current object has subscribed to.
Copy
Ask AI
String objectType = "__objecttype__";String objectId = "__objectid__";// optional params to pass limit (default=10) and cursor pointer for fetching the next set of resultsHashMap<String, Object> opts = new HashMap<String, Object>() { { put("limit", 10); put("after", "01HFS04E4J29KHPYRK7HT3YQQ5"); }};JSONObject res = suprClient.objects.getObjectsSubscribedTo(objectType, objectId, opts);System.out.println(res);