Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including @ampsec/platform-client with all npm packages installed. Try it out:

const {AmpApi, REPORTS} = require('@ampsec/platform-client'); const axios = require('axios'); const BASE_URL = process.env.AMPSEC_API_BASE_URL || '...'; const TOKEN = process.env.AMPSEC_API_TOKEN || '...'; const api = AmpApi.instance({ baseUrl: BASE_URL, token: TOKEN, client: axios, }); async function datagridExample() { const userListPage = await api.users.list({limit: 5, offset: 0}); console.log(`Fetched ${userListPage.data.length} of ${userListPage.hints.count} users`); const uid = userListPage.data[0].id; const userDetailsPage = await api.users.getById(uid); const user = userDetailsPage.data[0]; console.log(`Fetched details about user ${user.emails[0]} with id \`${user.id}\``); const userFindingsPage = await api.findings.list({uid: uid}); const count = userFindingsPage.hints.count; console.log(`${user.firstName} ${user.lastName} has ${count} findings.`); if (count > 0) { console.log('For example:'); console.log(userFindingsPage.data[0]); } } async function reportsExample() { const orgHealthScorePage = await api.reports.getMetrics(REPORTS.HEALTH_SCORE); console.log('Health Score:', orgHealthScorePage.data[0].results); const salesHealthScorePage = await api.reports.getMetrics(REPORTS.HEALTH_SCORE, {department: 'Sales'}); console.log('Sales Health Score:', salesHealthScorePage.data[0].results); const toolingCoveragePage = await api.reports.getMetrics(REPORTS.EMPLOYEE_TOOLING_COVERAGE); console.log('Tooling Coverage:', toolingCoveragePage.data[0].results); const healthTrendPage = await api.reports.getMetricsTrend(REPORTS.HEALTH_SCORE_TREND); console.log('Health Score Trend:'); for (const metric of healthTrendPage.data) { console.log(' - ', metric); } } async function run() { await datagridExample(); await reportsExample(); console.log('Done!'); } run();

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

@ampsec/platform-client v55.3.0

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free