tempo-client

Wrapper for the Tempo REST API

Usage no npm install needed!

<script type="module">
  import tempoClient from 'https://cdn.skypack.dev/tempo-client';
</script>

README

JavaScript Tempo API Client for node.js

Documentation Tempo Rest API Build Status npm Install Size Code Coverage

An unofficial node.js wrapper for the Tempo REST API.

The repo aims to be similar in usage to the node-jira-client.

Installation

Install using NPM:

$ npm install tempo-client

Examples

Instantiating the client

The bearerToken can be retrieved in two ways; Either as an individual user (useful for running personal reports and basic tests), or as an application developer (Useful for developing apps that seamlessly integrate with Tempo). Please see the sections "Using the REST API as an individual user" or "Using the REST API as an application developer" in Tempo's documentation.

Note that the bearer token for Tempo IS NOT the same as the token generated in Jira.

// ES5
const TempoApi = require('tempo-client').default;

// ES6
import TempoApi from 'tempo-client';

const tempo = new TempoApi({
  protocol: 'https',
  host: 'api.tempo.io',
  bearerToken: 'token',
  apiVersion: '3'
})

Getting worklogs for a JIRA user

const user = {
  accountId: '1111aaaa2222bbbb3333cccc'
};
const dateRange = {
  from: '2019-10-07',
  to: '2019-10-11'
};

// ES6
const worklogs = tempo.worklogs.getForUser(user.accountId, dateRange)
  .then(worklogs => {
    console.log(worklogs.results);
  })
  .catch(err => {
    console.log(err);
  });

// ES7
async function getWorklogsForUser(user, from, to) {
  try {
    const worklogs = await tempo.worklogs.getForUser(user.accountId, { from, to });
    console.log(worklogs.results);
  } catch (err) {
    console.log(err);
  }
}

Create, modify, delete an "Account"

// Create a new account using `.post(...)`
let account = {
  key: 'CLOUDBAY_DEVELOPMENT',
  name: 'Cloudbay: Development',
  status: 'OPEN',
  leadAccountId: "123456:01234567-89ab-cdef-0123-456789abcdef"
};

let accountId = (await tempo.accounts.post(account)).id;
console.log(`Account "${account.key}" has an id of: ${accountId}`);

// Modify the account using `.putAccount(...)`
account.status = 'CLOSED'
const accountOnTempo = await tempo.accounts.putAccount(account.key, account);
console.log(`Account "${account.key}" is now: ${accountOnTempo.status}`);

// Delete the account using `.deleteAccount(...)`
await tempo.accounts.deleteAccount(account.key);

// `.getAccount(...)` will throw an error now that the account is deleted
try {
  await tempo.accounts.getAccount(account.key);
} catch (err) {
  console.log(`Account "${account.key}" no longer exists!`);
}

Documentation

REST API

All endpoints listed in the Tempo REST API (https://apidocs.tempo.io/) for the Version 3 REST API are implemented as of November 2019. The REST API documentation will answer most questions about the expected structure of data.

The Tempo Client itself

Auto-generated documentation for the Tempo Client can be found at: https://tempo-client.leifgehrmann.com/

For example, if one wants to modify the accounts collection, one can find the API methods at Globals/ "collections/accounts" / Accounts.

It's strongly recommended to use TypeScript as code completion will help quite a bit with navigating the client.

Contributing

See CONTRIBUTING.md for more information.