Objects represent non-user entities such as organizations, teams, roles, and projects. Understand more about objects here.
Create / Update Object
This is an upsert
method, used to create or update an object.
import suprsend
supr_client = suprsend.Suprsend("Workspace_Key", "Workspace_Secret")
# Object details
object_id = "engineering"
object_type = "departments"
# Optional: for setting additional properties on object
properties = {
"key1": "val1",
"$email":"devs@abc.com"
}
res = supr_client.objects.upsert(object_type, object_id, properties)
print(res)
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)
Edit an object (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
res = supr_client.objects.edit
("object_type", "object_id", {"operations": [{"$set": {"company_name": "ABC company"}}]})
print(res)
Edit an object (using helper methods) [Recommended]
To edit object, you need to first fetch object instance, call all the update methods and save changes using objects.edit
method.
# Fetch object instance
obj_inst = supr_client.objects.get_edit_instance("object_type", "object_id")
# Call object update methods
obj_inst.set_timezone("America/Los_Angeles")
obj_inst.set("company_name", "ABC company")
# Save Changes
res = supr_client.objects.edit(obj_inst)
print(res)
List of available methods:
List Objects
List objects for an object_type
. You can also pass listing options in the payload which includes limit
,before
,after
res = supr_client.objects.list("object_type")
{"after": "01JJW6H55NXXXX59ARDW85G0KN", "limit": 1}
print(res)
Get Object Details
res = supr_client.objects.get("object_type", "object_id")
print(res)
Add Object Subscription
res = supr_client.objects.create_subscriptions(
"object_type",
"object_id",
{
"recipients": [
"distinct_id_1",
{"object_type": "teams", "object_id": "product"},
],
"properties": {"type": "members"},
},
)
print(res)
List Object Subscription
res = supr_client.objects.get_subscriptions("object_type", "object_id")
{"after": "01JJW6H55NXXXXXX5G0KN", "limit": 1}
print(res)
Remove Object Subscription
res = supr_client.objects.delete_subscriptions
(
"object_type",
"object_id",
{
"recipients": [
"distinct_id_1",
{"object_type": "departments", "object_id": "engineering"},
]
},
)
print(res)
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
res = supr_client.objects.get_objects_subscribed_to("object_type", "object_id", {"after": "01JJW6H55NXXXXX85G0KN", "limit": 1})
print(res)
Delete Object
res = supr_client.objects.delete("object_type", "object_id")
print(res)
Bulk Delete Objects
res = supr_client.objects.bulk_delete("object_type", {"object_ids": ["object_id1","object_id2"]})
print(res)