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.
Please note: you cannot change a user’s id once it has been set, so we recommend you use a non-transient id like a primary key rather than a phone number or email address.
To Edit user, you need to first fetch user instance, call all the update methods and save changes using user.save method.
importorg.json.JSONObject;importsuprsend.Suprsend;importsuprsend.Subscriber;publicclassUserEdit{publicstaticvoidupdateProfile()throwsException{Suprsend suprsendClient =getSuprClient();// User Edit InstanceString distinctID ="__distinct_id__";Subscriber user = suprsendClient.user.getInstance(distinctID);// Edit Helper methods user.addEmail("example@example.com"); user.setTimezone("America/New_York");// SaveJSONObject response = user.save();System.out.println(response);}}
Here’s a list of all edit methods:
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.
// User Edit InstanceString distinctID ="__distinct_id__";Subscriber user = suprsendClient.user.getInstance(distinctID);// Add Emailuser.addEmail("example@example.com");//Add SMSuser.addSms("+919999999999");//Add Whatsappuser.addWhatsapp("+919999999999");// Add Androidpush token.Pass the vendor as 2nd param.user.addAndroidpush("androidpush_fcm_token__","fcm");// Add iospush token user.addIospush("__iospush_apns_token__");// Add Slack using user email idJSONObject slackIdent =newJSONObject().put("access_token","xoxb-XXXXXXXX").put("email","user@example.com");user.addSlack(slackIdent);// Add Slack using member_id of the user if knownJSONObject slackIdent =newJSONObject().put("access_token","xoxb-XXXXXXXX").put("user_id","U03XXXXXXXX");user.addSlack(slackIdent);// Add Slack channel_idJSONObject slackIdent =newJSONObject().put("access_token","xoxb-XXXXXXXX").put("channel_id","C04XXXXXXXX");user.addSlack(slackIdent);// Add Slack incoming webhookJSONObject slackIdent =newJSONObject().put("incoming_webhook",newJSONObject().put("url","https://hooks.slack.com/services/TXXXXXXXXX/BXXXXXXXX/XXXXXXXXXXXXXXXXXXX"))user.addSlack(slackIdent);// Add Webpush token json (VAPID)JSONObject webpush =newJSONObject().put("endpoint","__end_point__").put("expirationTime","").put("keys",newJSONObject().put("p256dh","__p256dh__").put("auth","__auth_key__"));user.addWebpush(webpush,"vapid");
Use user.remove_* method(s) to remove channels.
// Remove Emailuser.removeEmail("example@example.com");//Remove SMSuser.removeSms("+919999999999");//Remove Whatsappuser.removeWhatsapp("+919999999999");// Remove Androidpush token.Pass the vendor as 2nd param.user.removeAndroidpush("androidpush_fcm_token__","fcm");// Remove iospush token user.removeIospush("__iospush_apns_token__");// Remove Slack using user email idJSONObject slackIdent =newJSONObject().put("access_token","xoxb-XXXXXXXX").put("email","user@example.com");user.removeSlack(slackIdent);// Remove Slack using member_id of the user if knownJSONObject slackIdent =newJSONObject().put("access_token","xoxb-XXXXXXXX").put("user_id","U03XXXXXXXX");user.removeSlack(slackIdent);// Remove Slack channel_idJSONObject slackIdent =newJSONObject().put("access_token","xoxb-XXXXXXXX").put("channel_id","C04XXXXXXXX");user.removeSlack(slackIdent);// Remove Slack incoming webhookJSONObject slackIdent =newJSONObject().put("incoming_webhook",newJSONObject().put("url","https://hooks.slack.com/services/TXXXXXXXXX/BXXXXXXXX/XXXXXXXXXXXXXXXXXXX"))user.removeSlack(slackIdent);// Remove Webpush token json (VAPID)JSONObject webpush =newJSONObject().put("endpoint","__end_point__").put("expirationTime","").put("keys",newJSONObject().put("p256dh","__p256dh__").put("auth","__auth_key__"));user.removeWebpush(webpush,"vapid");
This method will delete/unset all values in specified channel for user (ex: remove all emails attached to user).
// --- To unset one channel, for example to delete all emails associated with user// -- Channel keys - ("$email","$whatsapp","$sms," $androidpush","$iospush","$webpush","$slack")user.unset("$email");// --- multiple channels can also be deleted in one call by passing argument as a listArrayList<String> channels =newArrayList<>(Arrays.asList("$email","$slack","$androidpush","$iospush","$webpush","$whatsapp"));user.unset(channels);
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.
// User Edit InstanceString distinctID ="__distinct_id__";Subscriber user = suprsendClient.user.getInstance(distinctID);// Pass language in ISO 639-1 codeuser.setPreferredLanguage("es");
You can set timezone of user using this method. Value for timezone must be from amongst the IANA timezones.
// User Edit InstanceString distinctID ="__distinct_id__";Subscriber user = suprsendClient.user.getInstance(distinctID);// Pass IANA timezoneuser.setTimezone("America/New_York");
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.save() since user edit is async update and the changes will be sent to SuprSend only after calling this method.
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.
//Creating bulk instanceBulkSubscribers bulkIns = suprClient.bulkUsers.newInstance();// Prepare multiple usersString distinctID1 ="__distinct_id1__";// User 1User u1 = suprsendClient.user.getInstance(distinctID1);u1.addEmail("u1@example.com");String distinctID2 ="__distinct_id2__";// User 2User u2 = suprsendClient.user.getInstance(distinctID2);u2.addEmail("u2@example.com");// --- use .append on bulk instance to add one or more recordsbulkIns.append(u1);bulkIns.append(u2);// ORbulkIns.append(u1, u2);// SaveJSONObject response = bulkIns.save();System.out.println(response);
Bulk API supported in SDK version 0.2.0 and above:
Bulk API is supported in SuprSend python-sdk version 0.2.0 and above. If you are using an older version, please upgrade to the latest SDK version.
You can pass optional query parameters -limit,before,after
String distinctId ="__distinct_id__";// optional params to pass limit (default=10) and cursor pointer for fetching the next set of resultsHashMap<String,Object> opts =newHashMap<String,Object>(){{put("limit",10);put("after","01HFS04E4J29KHPYRK7HT3YQQ5");}};JSONObject res = suprClient.users.getObjectsSubscribedTo(distinctId, opts);System.out.println(response);
You can pass optional query parameters -limit, before, after
String distinctId ="__distinct_id__";// optional params to pass limit (default=10) and cursor pointer for fetching the next set of resultsHashMap<String,Object> opts =newHashMap<String,Object>(){{put("limit",10);put("after","01HFS04E4J29KHPYRK7HT3YQQ5");}};JSONObject res = suprClient.users.getListsSubscribedTo(distinctId, opts);System.out.println(response);