Objects in SuprSend represent non-user entities such as organizations, teams , roles, and projects. Understand more about objects from our objects documentation

Upsert (create/update) an object

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.

const {Suprsend} = require("@suprsend/node-sdk");

// Initialize SDK
const supr_client = new Suprsend("Workspace_Key", "Workspace_Secret")

res = supr_client.objects.upsert("object_type", "object_id");
res.then((res) => console.log(res)).catch((err) => console.log(err));

Edit an object

There are 2 ways in which you can edit an object data.

  • Build edit payload yourself
  • Use helper methods provided by SDK (Recommended)

1. Build edit payload yourself

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.

//for all supported operations, refer API documentation
const payload = {operations: [{$unset: ["name"]}, {$remove: {"$email": "abc@example.com"}}]}

const response = await supr_client.objects.edit(object_type, object_id, payload};

2. Edit using helper methods [Recommended]

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.

// create instance
const object_instance = supr_client.objects.get_instance(object_type, object_id);

// call any helper methods
object_instance.set(key, value);
object_instance.add_email("johndoe@gmail.com");

// save the changes
const response = await supr_client.objects.edit(object_instance);

Here’s a list of all edit helper methods:

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.

List Objects

List objects for an object_type. You can also pass listing options in the payload which includes limit,before,after

const response = await supr_client.objects.list(object_type,{"limit":10, "after:"cursor"});

Get Object Details

const response = await supr_client.objects.get(object_type, object_id);

Create Subscriptions

const payload = {
  "recipients": ["recipient1", "recipient2"],
  "properties": {"role":"manager"}
}

const response = await supr_client.objects.create_subscriptions(object_type, object_id, payload);

List Subscriptions

const response = await supr_client.objects.get_subscriptions(object_type, object_id,{"limit":10})

Remove Object Subscription

const payload = {"recipients": ["recipient1", "recipient2"]}

const response = await supr_client.objects.delete_subscriptions(object_type, object_id, payload)

Get list of objects subscribed by object

An object can subscribe to other objects. Use this method to get the list of all objects that the current object has subscribed to.

const response = await supr_client.objects.get_objects_subscribed_to(object_type, object_id);

Delete Object

const response = await supr_client.objects.delete(object_type, object_id);

Bulk Delete Object

const response = await supr_client.objects.bulk_delete(object_type, {object_ids: ["object_id1", "object_id2"]});