Create, update, & manage objects and their subscriptions using NodeJS 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.
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.
It is possible to use the SDK’s helper methods to perform edit operations on an object.For this, first create object instance then call any of the helper methods mentioned below and finally save the changes.
Copy
Ask AI
// create instanceconst object_instance = supr_client.objects.get_instance(object_type, object_id);// call any helper methodsobject_instance.set(key, value);object_instance.add_email("johndoe@gmail.com");// save the changesconst response = await supr_client.objects.edit(object_instance);
Here’s a list of all edit helper methods:
Add Channels
Use object_ins.add_* method(s) to add user channels in a profile
Copy
Ask AI
// add Emailobject_instance.add_email("object_ins@example.com");// add Emailobject_instance.add_sms("+15555555555");// add Whatsappobject_instance.add_whatsapp("+15555555555");// add fcm push tokenobject_instance.add_androidpush("__android_push_fcm_token__");// add apns push tokenobject_instance.add_iospush("__iospush_token__");// add Slack using emailobject_instance.add_slack( { "email": "user@example.com", "access_token": "xoxb-XXXXXXXX" });// add Slack if slack member_id is knownobject_instance.add_slack( { "user_id": "U03XXXXXXXX", "access_token": "xoxb-XXXXXXXX" });// add Slack channelobject_instance.add_slack( { "channel_id": "CXXXXXXXX", "access_token": "xoxb-XXXXXXXX" });// add Slack incoming webhookobject_instance.add_slack( { "incoming_webhook": { "url": "https://hooks.slack.com/services/TXXXX/BXXXX/XXXXXXX" } });// add MS teams user or channel using conversation_idobject_instance.add_ms_teams( { "tenant_id": "c1981ab2-9aaf-xxxx-xxxx", "service_url": "https://smba.trafficmanager.net/amer", "conversation_id": "19:c1524d7c-a06f-456f-8abe-xxxx" });// add MS teams user using user_idobject_instance.add_ms_teams( { "tenant_id": "c1981ab2-9aaf-xxxx-xxxx", "service_url": "https://smba.trafficmanager.net/amer", "object_ins_id": "29:1nsLcmJ2RKtYH6Cxxxx-xxxx" });// add MS teams using incoming webhookobject_instance.add_ms_teams( { "incoming_webhook": { "url": "https://wnk1z.webhook.office.com/webhookb2/XXXXXXXXX" } });
Remove Channels
Use object_ins.remove_* method(s) to remove channels from an object profile
Copy
Ask AI
// remove Emailobject_instance.remove_email("object_ins@example.com");// remove SMSobject_instance.remove_sms("+15555555555");// remove Whatsappobject_instance.remove_whatsapp("+15555555555");// remove fcm push tokenobject_instance.remove_androidpush("__android_push_fcm_token__"); // - by default, token is assumed to be fcm-token// remove apns push tokenobject_instance.remove_iospush("__iospush_token__");// remove Slack emailobject_instance.remove_slack( { "email": "object_ins@example.com", "access_token": "xoxb-XXXXXXXX" });// remove Slack if slack member_id is knownobject_instance.remove_slack( { "object_ins_id": "U03XXXXXXXX", "access_token": "xoxb-XXXXXXXX" });// remove Slack channelobject_instance.remove_slack( { "channel_id": "CXXXXXXXX", "access_token": "xoxb-XXXXXXXX" });// remove Slack incoming webhookobject_instance.remove_slack( { "incoming_webhook": { "url": "https://hooks.slack.com/services/TXXXX/BXXXX/XXXXXXX" } });// add MS teams user or channel using conversation_idobject_instance.remove_ms_teams( { "tenant_id": "c1981ab2-9aaf-xxxx-xxxx", "service_url": "https://smba.trafficmanager.net/amer", "conversation_id": "19:c1524d7c-a06f-456f-8abe-xxxx" });// add MS teams user using user_idobject_instance.remove_ms_teams( { "tenant_id": "c1981ab2-9aaf-xxxx-xxxx", "service_url": "https://smba.trafficmanager.net/amer", "object_ins_id": "29:1nsLcmJ2RKtYH6Cxxxx-xxxx" });// add MS teams using incoming webhookobject_instance.remove_ms_teams( { "incoming_webhook": { "url": "https://wnk1z.webhook.office.com/webhookb2/XXXXXXXXX" } });
Remove Channels in bulk
If you need to delete/unset all emails (or any other channel) of an object, you can call object_ins.unset() method on the object instance. The method accepts the channel key/s (a single key or list of keys)
Copy
Ask AI
object_instance.unset("$email");object_instance.unset(["$email", "$sms", "$whatsapp"]);// available channel keys -//["$email","$whatsapp","$sms","$androidpush","$iospush","$webpush","$slack","$ms_teams"]// --- multiple channels can also be deleted in one call by passing argument as a listobject_ins.unset(["$email", "$sms", "$whatsapp"]);res = object_ins.save();res.then((res) => console.log(res)).catch((err) => console.log(err));
Set Preferred language
Copy
Ask AI
object_instance.set_preferred_language("en");
Set Preferred Timezone
Copy
Ask AI
object_instance.set_timezone("America/Belize");
Set
Set is used to set the custom property or properties. The given name and value will be assigned to the object, overwriting an existing property with the same name if present. It can take key as first param, value as second param for setting single object property or object for setting multiple object properties.
Mandatory This param will be string in case where only single property needs to be created/updated. It will be a dictionary in cases where complex objects need to be set in object properties, like multiple properties, arrays, nested properties etc. Should not start with $ or ss_
arg2
any
Optional This will be value that will be attached to key property. Not required in cases where first param is a dictionary.
When you create a key, please ensure that the Key Name does not start with or , as we have reserved these symbols for our internal events and property names.
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
Copy
Ask AI
// For setting once a single property:object_instance.set_once(key, value);object_instance.set_once("first_login", "2021-11-02");// For setting once multiple propertiesobject_instance.set_once(properties);object_instance.set_once({"first_login" : "2021-11-02", "DOB" : "1991-10-02"});
Increment
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.
Copy
Ask AI
// For incrementing a single property:object_instance.increment(key, value);object_instance.increment("login_count", 1);// For incrementing multiple properties:object_instance.increment(property_obj);object_instance.increment({"login_count" : 1, "remaining_credits" : -1});
Append
This method will append a value to the list for a given property.
Copy
Ask AI
// For appending a single property:object_instance.append.append(key, value);object_instance.append.append("wishlist", "iphone12");// For appending multiple properties:object_instance.append.append(properties);object_instance.append.append({"wishlist" : "iphone12", "cart" : "Apple airpods"});
Remove
This method will remove a value from the list for a given property.
Copy
Ask AI
// For removing a single property:object_instance.remove(key, value);object_instance.remove("wishlist", "iphone12");// For removing multiple properties:object_instance.remove(properties);object_instance.remove({"wishlist" : "iphone12", "wishlist": "Apple airpods"});
Unset
This will remove a property permanently from properties.
Copy
Ask AI
// For unsetting a single property:object_instance.unset(key);object_instance.unset("wishlist");// For unsetting multiple properties:object_instance.unset(property_list);object_instance.unset(["wishlist", "cart"]);
Parameters
Type
Description
key
string
This property provided will be deleted from object properties
property_list
array[string]
If list is given all properties included in list will be removed.
After calling add_*/remove_*/unset methods, don’t forget to call object_ins.save(). On call of save(), SDK sends the request to SuprSend platform to update the Object Profile.