As an exercise for for importing data with using the Elimity Insights API, you can try to complete the JavaScript example below.
For more information about the JavaScript client, see https://github.com/elimity-com/insights-client-js/tree/main/example.
import { performImport, logInfo } from "@elimity/insights-client";
// Step 1: Create a custom source in Elimity Insights with the following domain model:
//
// Entity types:
// 1. User:
// * Attribute types: email address (string), when created (date time), active (boolean)
// 2. Group:
// * Attribute types: description (string)
//
// Relationship types:
// 1. User -> Group
// Step 2: Generate an API token to your application and fill out this connection info:
const config = {
baseUrl: "https://todo.elimity.com/api",
sourceId: 1,
sourceToken: "TODO",
};
// Example input data
const users = [
{
fullName: "Tony Stark",
email: "tony.stark@example.com",
whenCreated: new Date("2015-12-17T03:24:00"),
active: false,
groups: ["admin"]
},
{
fullName: "Peter Parker",
email: "peter.parker@example.com",
whenCreated: new Date("2017-01-14T05:23:00"),
active: true,
groups: ["member", "editor"]
},
{
fullName: "Steve Rogers",
email: "steve.rogers@example.com",
whenCreated: new Date("2024-10-07T01:32:00"),
active: true,
groups: ["member", "team admin"]
},
];
// Step 3: Turn the input data into a list of entities and relationships
const entities = [];
const relationships = [];
await logInfo(config, "Processing input data")
// TODO homework ;)
// Step 4: Send the data to Elimity Insights
await logInfo(config, "Sending new data")
await performImport(config, entities, relationships);
// Step 5: Verify in Elimity Insights that the logs and the new data have been received successfully
Comments
0 comments
Please sign in to leave a comment.