Published on

Calibre API: Get a List of All Users in Your Team

Authors

Calibre app helps us to monitor website/web app performance by loading the website/web app like in the browser and helps us to visualize things using various reports, budgets, etc

Here is how we can get all the users/members in your Calibre Team using their API.

Dependency

In order to interact with the API we'll need AUTH_TOKEN, we can easily create one from Calibre dashboard.

We'll be using fetch for API calls (and using node-fetch to support older versions of Node.js).

npm install node-fetch

Snippet

import fetch from 'node-fetch';

// You can get this from the URL itself
// Eg: https://app.calibreapp.com/teams/<YOUR_CALIBRE_TEAM_ID>
const YOUR_CALIBRE_TEAM_ID = 'example-....'; 
const CALIBRE_API_TOKEN = '...';

const fetch = require('node-fetch');

let data = JSON.stringify({
  query: `query ListMembers($teamId: String!) {
  team(slug: $teamId) {
    __typename
    slug
    name
    organisation {
      __typename
      slug
      name
    }
    members {
      __typename
      role
      state
      invitationName
      invitationEmail
      role
      uuid
      lastSeenAt
      teams {
        slug
        __typename
      }
      user {
        uuid
        name
        email
        avatar
        __typename
      }
    }
  }
}`,
  variables: {"teamId":YOUR_CALIBRE_TEAM_ID}
});

let config = {
  method: 'POST',
  headers: { 
    'Authorization': `Token ${CALIBRE_API_TOKEN}`, 
    'Content-Type': 'application/json'
  },
  body: data
};

fetch('https://api.calibreapp.com/graphql', config)
  .then((response) => response.json())
  .then((data) => {
    console.log(JSON.stringify(data));
  })
  .catch((error) => {
    console.log(error);
  });

Note: This API endpoint is something that I've noticed in their web app. Not from official docs. So it might change anytime. Use it with caution.

Happy finding users!