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 instanceobj_inst = supr_client.objects.get_edit_instance("object_type","object_id")# Call object update methodsobj_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:
Use object_ins.add* method(s) to add channels
obj_inst = supr_client.objects.get_edit_instance("object_type","object_id")# Add Emailobj_inst.add_email("user@example.com")# Add SMSobj_inst.add_sms("+15555555555")# Add Whatsappobj_inst.add_whatsapp("+15555555555")# Add Androidpush token with vendorobj_inst.add_androidpush("androidpush_fcm_token__","fcm")# Add iOS push tokenobj_inst.add_iospush("__iospush_apns_token__")# Add Slack using user email idslack_ident_email ={"access_token":"xoxb-XXXXXXXX","email":"user@example.com"}obj_inst.add_slack(slack_ident_email)# Add Slack using member_id of the userslack_ident_user_id ={"access_token":"xoxb-XXXXXXXX","user_id":"U03XXXXXXXX"}obj_inst.add_slack(slack_ident_user_id)# Add Slack channel_idslack_ident_channel_id ={"access_token":"xoxb-XXXXXXXX","channel_id":"C04XXXXXXXX"}obj_inst.add_slack(slack_ident_channel_id)# Add Slack incoming webhookslack_ident_webhook ={"incoming_webhook":{"url":"https://hooks.slack.com/services/TXXXXXXXXX/BXXXXXXXX/XXXXXXXXXXXXXXXXXXX"}}obj_inst.add_slack(slack_ident_webhook)# Add Webpush token json (VAPID)webpush_ident ={"endpoint":"__end_point__","expirationTime":"","keys":{"p256dh":"__p256dh__","auth":"__auth_key__"}}obj_inst.add_webpush(webpush_ident,"vapid")# Save changesres = supr_client.objects.edit(obj_inst)print(res)
Use object_ins.remove_* method(s) to remove channels from an object
obj_inst = supr_client.objects.get_edit_instance("object_type","object_id")# Remove Emailobj_inst.remove_email("user@example.com")# Remove SMSobj_inst.remove_sms("+15555555555")# Remove Whatsappobj_inst.remove_whatsapp("+15555555555")# Remove Androidpush token with vendorobj_inst.remove_androidpush("androidpush_fcm_token__","fcm")# Remove iOS push tokenobj_inst.remove_iospush("__iospush_apns_token__")# Remove Slack using user email idslack_ident_email ={"access_token":"xoxb-XXXXXXXX","email":"user@example.com"}obj_inst.remove_slack(slack_ident_email)# Remove Slack using member_id of the userslack_ident_user_id ={"access_token":"xoxb-XXXXXXXX","user_id":"U03XXXXXXXX"}obj_inst.remove_slack(slack_ident_user_id)# Remove Slack channel_idslack_ident_channel_id ={"access_token":"xoxb-XXXXXXXX","channel_id":"C04XXXXXXXX"}obj_inst.remove_slack(slack_ident_channel_id)# Remove Slack incoming webhookslack_ident_webhook ={"incoming_webhook":{"url":"https://hooks.slack.com/services/TXXXXXXXXX/BXXXXXXXX/XXXXXXXXXXXXXXXXXXX"}}obj_inst.remove_slack(slack_ident_webhook)# Remove Webpush token json (VAPID)webpush_ident ={"endpoint":"__end_point__","expirationTime":"","keys":{"p256dh":"__p256dh__","auth":"__auth_key__"}}obj_inst.remove_webpush(webpush_ident,"vapid")# Save changesres = supr_client.objects.edit(obj_inst)print(res)
This method will delete/unset all values in specified channel for object (ex: remove all emails attached to object).
# Remove multiple channels in bulkchannels_to_remove =["$email","$whatsapp","$sms","$androidpush","$iospush","$webpush","$slack","$ms_teams"]obj_inst.unset(channels_to_remove)
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.
obj_inst.set_preferred_language("en")
You can set timezone of user using this method. Value for timezone must be from amongst the IANA timezones.
obj_inst.set_timezone("America/Los_Angeles")
Set any custom property using this method. It will shallow merge existing properties with new values. Key shouldn’t start with $ or ss.
# Set a single propertyobj_inst.set(key, value)obj_inst.set("company_name","ABC company")# Set multiple propertiesobj_inst.set({ key1: value1, key2: value2 })obj_inst.set({"company_name":"ABC company","city":"San Francisco"})
Use this to unset existing channels or properties.
#unset single channel or propertyobj_inst.unset("$email")#unset multiple channels or propertiesobj_inst.unset(["$email","company_name"])
Use this to append item to an array based property.
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)
res = supr_client.objects.delete_subscriptions("object_type","object_id",{"recipients":["distinct_id_1",{"object_type":"departments","object_id":"engineering"},]},)print(res)