Branch.io, for each users in my database create a referral link for my app so that I can bulk emailing my users with their referral link

Refresh

April 2019

Views

309 time

1

I know I can create referral links in my react native app for a given user.

i.e.

branch.setIdentity(userId);
const branchUniversalObject = await 
branch.createBranchUniversalObject(..);
const { url } = await branchUniversalObject.generateShortUrl(linkProperties);

But what I want to do is for each user in my database create a unique referral link. Not in my mobile app but in an admin web app (which is written in node) so that I can email all my users with their unique referral links.

Would do something like this if there was a node package but there isn't

users.forEach(user => {
  branch.setIdentity(user.userId);
  const branchUniversalObject = await branch.createBranchUniversalObject(..);
  const { url } = await branchUniversalObject.generateShortUrl(linkProperties);
  saveUserReferalLink(user, url);
});

I've been looking at API

https://docs.branch.io/pages/apps/api/

but not quite sure what I need to do

create a link with https://api.branch.io/v1/url and set the user in the stage param?

Thanks for any help in advance

Update

As suggested by Evgeniy Haydamakha the documentation does say the following

Referrer links

  • Create a user with an $identity_id
  • Create a link with the $identity_id from step 1 in the link data dictionary

However I’ve been struggling to create a user. The documentation suggests creating a user as below

curl -XPOST https://api.branch.io/v1/profile \
  -d '{
    "branch_key":"MY_KEY",
    "identity":"steve",
    "identity_id":"444"
}'

The question is what should the identity_id be in reality? 444 for example does not work it will not create a user. The id 12345678 does work, but ends up creating a user in the identities tab in the liveview tab of the dashboard with a date of 2014-05-28, the id seems time dependant. Ideally I wouldn’t pass a identity_id at all, it would auto generate it, like setIdentity('steve') does.

I then found this article, that suggests I don’t need to create a user at all but pass my identity to the link i.e. “steve” in the above example as a Branch Developer Identity and that if there is no identity_id (Branch Identity ID) associated with the identity, a new one will be created.

https://stackoverflow.com/a/46358311/9636627

Which is great, I’ve tried it and it works, the only problem is now, that the newly created user does not appear in the “identites” tab of liveview. I know the user exists because if I do user a read identity passing in for instance “steve”, I get a response with the new “identity_id” (Branch Identity ID) in.

To summarise my questions are

What should the identity_id (Branch Identity ID) actually be when creating a new user?

Why do new users not appear in the “identities” tab of liveview, when I create a new link and pass a developer identity?

1 answers

0

In order to create a referral link via an API you will need to create a user identity_id, as per Branch documentation (or have an identity ID on hand), and then include $identity_id into the data dictionary, like so:

curl -XPOST https://api.branch.io/v1/url \
  -d '{
  "branch_key": "YOUR_BRANCH_KEY",
  "channel": "facebook",
  "feature": "onboarding",
  "campaign": "new product",
  "stage": "new user",
  "tags": ["one", "two", "three"],
  "data": {
    "$identity_id": "444",
    "$canonical_identifier": "content/123",
    "$og_title": "Title from Deep Link",
    "$og_description": "Description from Deep Link",
    "$og_image_url": "http://www.lorempixel.com/400/400/",
    "$desktop_url": "http://www.example.com",
    "custom_boolean": true,
    "custom_integer": 1243,
    "custom_string": "everything",
    "custom_array": [1,2,3,4,5,6],
    "custom_object": { "random": "dictionary" }
  }
}'