This document will cover all the nodejs methods related to objects
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.
Copy
//for all supported operations, refer API documentationconst payload ={operations:[{$unset:["name"]},{$remove:{"$email":"abc@example.com"}}]}const response =await supr_client.objects.edit(object_type, object_id, payload};
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
// 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:
Use object_ins.add_* method(s) to add user channels in a profile
Copy
object_instance.add_email("object_ins@example.com");object_instance.add_sms("+15555555555");object_instance.add_whatsapp("+15555555555");object_instance.add_androidpush("__android_push_fcm_token__");object_instance.add_iospush("__iospush_token__");// - To add Slack using emailobject_instance.add_slack({"email":"user@example.com","access_token":"xoxb-XXXXXXXX"});// - To add Slack if slack member_id is knownobject_instance.add_slack({"user_id":"U03XXXXXXXX","access_token":"xoxb-XXXXXXXX"});// - To add Slack channelobject_instance.add_slack({"channel_id":"CXXXXXXXX","access_token":"xoxb-XXXXXXXX"});// - To add Slack incoming webhookobject_instance.add_slack({"incoming_webhook":{"url":"https://hooks.slack.com/services/TXXXXXXXXX/BXXXXXXXX/XXXXXXXXXXXXXXXXXXX"}});// - To 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"});// - To 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"});// - To add MS teams using incoming webhookobject_instance.add_ms_teams({"incoming_webhook":{"url":"https://wnk1z.webhook.office.com/webhookb2/XXXXXXXXX"}});
Use object_ins.remove_* method(s) to remove channels from an object profile
Copy
object_instance.remove_email("object_ins@example.com");object_instance.remove_sms("+15555555555");object_instance.remove_whatsapp("+15555555555");object_instance.remove_androidpush("__android_push_fcm_token__");// - by default, token is assumed to be fcm-tokenobject_instance.remove_iospush("__iospush_token__");// - To remove Slack emailobject_instance.remove_slack({"email":"object_ins@example.com","access_token":"xoxb-XXXXXXXX"});// - To remove Slack if slack member_id is knownobject_instance.remove_slack({"object_ins_id":"U03XXXXXXXX","access_token":"xoxb-XXXXXXXX"});// - To remove Slack channelobject_instance.remove_slack({"channel_id":"CXXXXXXXX","access_token":"xoxb-XXXXXXXX"});// - To remove Slack incoming webhookobject_instance.remove_slack({"incoming_webhook":{"url":"https://hooks.slack.com/services/TXXXXXXXXX/BXXXXXXXX/XXXXXXXXXXXXXXXXXXX"}});// - To 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"});// - To 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"});// - To add MS teams using incoming webhookobject_instance.remove_ms_teams({"incoming_webhook":{"url":"https://wnk1z.webhook.office.com/webhookb2/XXXXXXXXX"}});
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
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));
Copy
object_instance.set_preferred_language("en");
Copy
object_instance.set_timezone("America/Belize");
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.
Copy
//For setting single propertyobject_instance.set("key","value");//For multiple Propertiesobject_instance.set({"prop1":"val1","prop2":["one","two","three"],"number":20});
Parameters
Type
Description
arg1
string/dictionary
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.
Works just like object_ins.set, except it will not overwrite existing property values. This is useful for properties like First login date
Copy
// 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"});
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
// 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});
This method will append a value to the list for a given property.
Copy
// 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"});
This method will remove a value from the list for a given property.
Copy
// 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"});
This will remove a property permanently from properties.
Copy
// 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.