SuprSend identifies users with immutable distinct_id. It’s best to map the same identifier in your DB with distinct_id in SuprSend. Do not use identifiers that can be changed like email or phone number. You can view synced users by searching distinct_id on Users page.
To create a new user or to update an existing user, you’ll have to fetch user instance. Call supr_client.user.get_instance to instantiate user object.
Copy
Ask AI
import suprsendsupr_client = suprsend.Suprsend("workspace_key", "workspace_secret")distinct_id = "distinct_id" # Unique identifier of user in your application# Instantiate User profileuser = supr_client.users.get_edit_instance(distinct_id)
To Edit user, you need to first fetch user instance, call all the update methods and save changes using users.async_edit method.
Copy
Ask AI
#Fetch user instanceuser = supr_client.users.get_edit_instance("_distinct_id_")#Call user update methodsuser.set_timezone("America/Los_Angeles")user.set("name", "John Doe")#Save Changesres = supr_client.users.async_edit(user)print(res)
Here’s a list of all edit methods:
Add User Channels
Add communication channels on which you want to notify user. Push sand Inbox tokens are automatically tracked on user identification when the corresponding frontend SDK is integrated. Other channels (Email, SMS, Slack, MS teams, WhatsApp) need to be explicitly set in user profile.
Use user.add_* method(s) to add user channels.
Copy
Ask AI
# Add channel details to user-instance. Call relevant add_* methodsuser.add_email("user@example.com") # - To add Emailuser.add_sms("+15555555555") # - To add SMSuser.add_whatsapp("+15555555555") # - To add WhatsAppuser.add_androidpush("__android_push_fcm_token__")user.add_iospush("__iospush_token__")# - To add Slack using emailuser.add_slack( { "email": "user@example.com", "access_token": "xoxb-XXXXXXXX" })# - To add Slack if slack member_id is knownuser.add_slack( { "user_id": "U03XXXXXXXX", "access_token": "xoxb-XXXXXXXX" })# - To add Slack channeluser.add_slack( { "channel_id": "CXXXXXXXX", "access_token": "xoxb-XXXXXXXX" })# - To add Slack incoming webhookuser.add_slack( { "incoming_webhook": { "url": "https://hooks.slack.com/services/TXXXX/BXXXX/XXXXXXX" } })# - To add MS teams user or channel using conversation_iduser.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_iduser.add_ms_teams( { "tenant_id": "c1981ab2-9aaf-xxxx-xxxx", "service_url": "https://smba.trafficmanager.net/amer", "user_id": "29:1nsLcmJ2RKtYH6Cxxxx-xxxx" })# - To add MS teams using incoming webhookuser.add_ms_teams( { "incoming_webhook": { "url": "https://wnk1z.webhook.office.com/webhookb2/XXXXXXXXX" } })
Remove User Channels
Use user.remove_* method(s) to remove channels.
Copy
Ask AI
# Remove channel details from user-instance. Call relevant remove_* methodsuser.remove_email("user@example.com")user.remove_sms("+15555555555")user.remove_whatsapp("+15555555555")user.remove_androidpush("__android_push_fcm_token__")user.remove_iospush("__iospush_token__")# - To remove Slack emailuser.remove_slack( { "email": "user@example.com", "access_token": "xoxb-XXXXXXXX" })# - To remove Slack if slack member_id is knownuser.remove_slack( { "user_id": "U03XXXXXXXX", "access_token": "xoxb-XXXXXXXX" })# - To remove Slack channeluser.remove_slack( { "channel_id": "CXXXXXXXX", "access_token": "xoxb-XXXXXXXX" })# - To remove Slack incoming webhookuser.remove_slack( { "incoming_webhook": { "url": "https://hooks.slack.com/services/TXXXX/BXXXX/XXXXXXX" } })# - To remove MS teams user or channel using conversation_iduser.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 remove MS teams user using user_iduser.remove_ms_teams( { "tenant_id": "c1981ab2-9aaf-xxxx-xxxx", "service_url": "https://smba.trafficmanager.net/amer", "user_id": "29:1nsLcmJ2RKtYH6Cxxxx-xxxx" })# - To remove MS teams using incoming webhookuser.remove_ms_teams( { "incoming_webhook": { "url": "https://wnk1z.webhook.office.com/webhookb2/XXXXXXXXX" } })
Remove Channel types
This method will delete/unset all values in specified channel for user (ex: remove all emails attached to user).
Copy
Ask AI
# --- To delete all emails associated with useruser.unset("$email")user.unset(["$email", "$sms", "$whatsapp"])# Supported channel keys are:# $email, $whatsapp, $sms, $androidpush, $iospush, $webpush, $slack, $ms_teams
Set Preferred language
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.
Copy
Ask AI
user.set_preferred_language("en")
Set preferred timezone
You can set timezone of user using this method. Value for timezone must be from amongst the IANA timezones.
Copy
Ask AI
user.set_timezone("America/Los_Angeles")
Set
Set is used to add custom user properties. It is an upsert function, meaning any existing property value with the same key will be overwritten on subsequent updates.
After calling add*/remove*/unset methods, don’t forget to call users.async_edit() since user edit is async update and the changes will be sent to SuprSend only after calling this method.