Events

The SDK emits a number of different events when it loads, a user connects an account, sets up an integration, etc. You can leverage these events to plug in your own logic in the user journey.

Note: Events emitted by the SDK are scoped to the instance on which the eventEmitter object is configured. There is no possiblilty of naming collision with global events, or even with the same event subscribed on multiple SDK instances.

This article lists all the events that can be leveraged, and explains how to subscribe and unsubscribe to/from them.

Marketplace initialized

eventEmitter.on('ready')

Fired when the SDK finishes initialization by authorizing the client. This event is not fired if the credentials provided are incorrect.

mySDKInstance.eventEmitter.on('ready', (data) => {

});

Account connected

eventEmitter.on('did-add-authorization')

Fired when an authorization is added successfully in the flow setup form. You can use the alreadyExists key to check if a user is adding a previously connected account again.

CopymySDKInstance.eventEmitter.on('did-add-authorization', (data) => {
/**
* data:
* identity: string;
* authorizationId: number;
* flowId: number;
* alreadyExists: boolean;
*/
});

Account disconnected

eventEmitter.on('did-remove-authorization')

Fired when an authorization is deleted in the flow setup form.

CopymySDKInstance.eventEmitter.on('did-remove-authorization', (data) => {
  /**
   * data:
   *   authorizationId: number;
   */
});

Integration created

eventEmitter.on('did-save-integration')

Fired when an integration is saved successfully. If a user edits an existing integration and saves it, this will fire again.

CopymySDKInstance.eventEmitter.on('did-save-integration', (data) => {
  console.log(`Hey, we set up integration ${data.integrationId} successfully!`);
  /**
   * data:
   *   flowId: number;
   *   integrationId: number;
   *   name: string; **Name of the integration**
   *   status: 'ACTIVE' | 'INACTIVE';
   *   callbackUrl: string;
   *   event:  'EDIT' | 'CREATE';
   *   flowName: string;
   *   flowDescription: string;
   *   brandingApp: {
         name: string,
         description: string,
         icon_url: string
       };
   */
});

Integration enabled

eventEmitter.on('did-enable-integration')

Fired when an integration is enabled using the toggle on integrations listing screen.

CopymySDKInstance.eventEmitter.on('did-enable-integration', (data) => {
  console.log(`Hey, we enabled integration ${data.integrationId} successfully!`);
  /**
   * data:
   *   integrationId: number;
   *   name: string; **Name of the integration**
   *   status: 'ACTIVE' | 'INACTIVE';
   */
});

Integration disabled

eventEmitter.on('did-disable-integration')

Fired when an integration is disabled using the toggle on integrations listing screen.

CopymySDKInstance.eventEmitter.on('did-disable-integration', (data) => {
  console.log(`Hey, we disabled integration ${data.integrationId} successfully!`);
  /**
   * data:
   *   integrationId: number;
   *   name: string; **Name of the integration**
   *   status: 'ACTIVE' | 'INACTIVE';
   */
});

Integration renamed

eventEmitter.on('did-rename-integration')

Fired when an integration is renamed.

CopymySDKInstance.eventEmitter.on('did-rename-integration', (data) => {
  console.log(`Hey, we renamed integration ${data.integrationId} successfully!`);
  /**
   * data:
   *   integrationId: number;
   *   name: string; **Name of the integration**
   *   status: 'ACTIVE' | 'INACTIVE';
   */
});

Integration deleted

eventEmitter.on('did-delete-integration')

Fired when an integration is deleted successfully.

CopymySDKInstance.eventEmitter.on('did-delete-integration', (data) => {
  console.log(
    `Hey, we deleted integration ${data.integrationId} successfully!`,
  );
  /**
   * data:
   *   flowId: number;
   *   integrationId: number;
   */
});

Subscribe to an event

Call eventEmitter.on('<event_name>') method​ to subscribe to an event.

For example, here's how you would subscribe to the did-save-integration event to get the callback URL you need to run the integration.

CopymySDKInstance.eventEmitter.on('did-save-integration', (data) => {
  console.log(`Hey, we set up integration ${data.integrationId} successfully!`);
  /**
   * data:
   *   flowId: number;
   *   integrationId: number;
   *   name: string;
   *   status: string;
   *   callbackUrl: string;
   *   event:  'EDIT' | 'CREATE';
   */
});

Unsu​bscribe from an event

Call eventEmitter.unsub('<event_name>') method​ to unsubscribe from an event.

Here's an example:

Copyfunction integrationSavedCallback(data: CallbackData) {
  console.log(`Integration with name ${data.name} was created!`);
}
// subscribe
mySDKInstance.eventEmitter.on('did-save-integration', integrationSavedCallback);

// unsubscribe
mySDKInstance.eventEmitter.unsub('did-save-integration', integrationSavedCallback);

Last updated