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
const user = supr_client.user.get_instance("_distinct_id_"); // create user instance// user methods mentioned in this docs can be attached to user instance if neededconst response = user.save() // IMP: trigger requestresponse.then((res) => console.log("response", res));
To Edit user, you need to first fetch user instance, call all the update methods and save changes using user.save() method.
Copy
Ask AI
// Fetch user instanceconst user = supr_client.users.get_edit_instance("_distinct_id_");// Call user update methodsuser.set_timezone("America/Los_Angeles");user.set("name", "John Doe");// Save Changesconst response = user.save(); // IMP: trigger requestresponse.then((res) => console.log("response", res));
Here’s a list of all edit methods:
Add User Channels
Use user.add_* method to add user channels.
Copy
Ask AI
// add Emailuser.add_email("user@example.com")// add SMSuser.add_sms("+15555555555")// add Whatsappuser.add_whatsapp("+15555555555")// add fcm push tokenuser.add_androidpush("__android_push_fcm_token__")// add apns push tokenuser.add_iospush("__iospush_token__")// add Slack using emailuser.add_slack({ email: "user@example.com", access_token: "xoxb-XXXXXXXX"});// add Slack if slack member_id is knownuser.add_slack({ user_id: "U03XXXXXXXX", access_token: "xoxb-XXXXXXXX"});// add Slack channeluser.add_slack({ channel_id: "CXXXXXXXX", access_token: "xoxb-XXXXXXXX"});// add Slack incoming webhookuser.add_slack({ incoming_webhook: { url: "https://hooks.slack.com/services/TXXXX/BXXXX/XXXXXXX" }});// add MS teams user or channel using conversation_iduser.add_ms_teams({ tenant_id: "c19xxxx2-9aaf-xxxx-xxxx", service_url: "https://smba.trafficmanager.net/amer", conversation_id: "19:c1524d7c-a06f-456f-8abe-xxxx"});// add MS teams user using user_iduser.add_ms_teams({ tenant_id: "c19xxxx2-9aaf-xxxx-xxxx", service_url: "https://smba.trafficmanager.net/amer", user_id: "29:1nsLcmJ2RKtYH6Cxxxx-xxxx"});// 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 user channels. These methods will detach provided value from the user profile in specified channel.
Copy
Ask AI
// remove Emailuser.remove_email("user@example.com")// remove SMSuser.remove_sms("+15555555555")// remove Whatsappuser.remove_whatsapp("+15555555555")// remove fcm push tokenuser.remove_androidpush("__android_push_fcm_token__")// remove apns push tokenuser.remove_iospush("__iospush_token__")// remove Slack emailuser.remove_slack({ email: "user@example.com", access_token: "xoxb-XXXXXXXX"});// remove Slack if slack member_id is knownuser.remove_slack({ user_id: "U03XXXXXXXX", access_token: "xoxb-XXXXXXXX"});// remove Slack channeluser.remove_slack({ channel_id: "CXXXXXXXX", access_token: "xoxb-XXXXXXXX"});// remove Slack incoming webhookuser.remove_slack({ incoming_webhook: { url: "https://hooks.slack.com/services/TXXXX/BXXXX/XXXXXXX" }});// remove MS teams user or channel using conversation_iduser.remove_ms_teams({ tenant_id: "c19xxxx2-9aaf-xxxx-xxxx", service_url: "https://smba.trafficmanager.net/amer", conversation_id: "19:c1524d7c-a06f-456f-8abe-xxxx"});// remove MS teams user using user_iduser.remove_ms_teams({ tenant_id: "c19xxxx2-9aaf-xxxx-xxxx", service_url: "https://smba.trafficmanager.net/amer", user_id: "29:1nsLcmJ2RKtYH6Cxxxx-xxxx"});// remove MS teams using incoming webhookuser.remove_ms_teams({ incoming_webhook: { url: "https://wnk1z.webhook.office.com/webhookb2/XXXXXXXXX" }});
Remove User Channels in bulk
This method will delete/unset all values in specified channel for user (ex: remove all emails attached to user).
Copy
Ask AI
user.unset("$email")user.unset(["$email", "$sms", "$whatsapp"])// what value to pass to unset channels// for email: $email// for whatsapp: $whatsapp// for SMS: $sms// for androidpush tokens: $androidpush// for iospush tokens: $iospush// for webpush tokens: $webpush// for slack: $slack// for ms_teams: $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 set the custom user property or properties. The given key and value will be assigned to the user, overwriting an existing property with the same key if present.
Add the given number to an existing property on the user. If the user 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.
After calling add*/remove*/unset methods, don’t forget to call the user.save() request. the changes will be sent to SuprSend only after calling this method.
To update multiple user profiles use Bulk API. There isn’t any limit on number-of-records that can be added to bulk_users instance. Use append() on bulk_users instance to add however-many-records to call in bulk.