Customer IDs

Learn how customer IDs help you build scalable customer engagement applications on the Elarian Framework.

Default Customer Id

Whenever you engage a customer on Elarian a default customerId is generated that you can reference the customer by. You can get this identifier by checking the customers state.

const customer = new client.Customer({
  customerNumber: { ... }
});

const resp = await customer.getState();

console.log(resp.customerId);

Secondary Customer Id

You can also give a customer one or more secondaryIds. This is similar to the default Id generated by Elarian and is optimized for querying/finding the customer. This secondaryId can be anything you'd like and follows a key<>value pattern.

Update customer secondaryId

...

const resp = await customer.updateSecondaryIds([
  {
    key: 'userId',
    value: '808082',
    expiresAt: new Date(2025, 1, 1).getTime() / 1000, // optional
  },
  {
    key: 'email',
    value: 'jane@doe.com',
    expiresAt: new Date(2025, 1, 1).getTime() / 1000, // optional
  }
]);

console.log(resp);

Get customer secondaryIds

...

const customerState = await customer.getState();

console.log(customerState.identityState.secondaryIds);

Delete customer secondaryId

...

const resp = await customer.deleteSecondaryIds([{
  key: 'email',
  value: 'jane@doe.com',
}]);