Case 3 - How to get the total hours clocked for a given project


const httpClient = require('../config');

const getTotalHoursForProject = async (projectId, fromDate, toDate) => {
    return await httpClient
                    .get(`timelister?$filter=prosjektId eq '${projectId}' and Dato ge ${fromDate} and Dato le ${toDate}`);
}


const fromDate = '2016-01-01T08:00Z';
const toDate = '2017-08-01T08:00Z';

const response = await getTotalHoursForProject(3, fromDate, toDate);
const timesheets = response.data;

//Loop through all timesheets and sum the amount of clocked hours
//Replace ma_Timer with fAntall if you only want hours that are marked //"fakturerbar" (to be invoiced)
const totalHours = timesheets.reduce((total, timesheet) => {
      return total + timesheet.ma_Timer; 
}, 0)

console.log("Total hours: " + totalHours);


Case 1 - Add a project to Tidsbanken


//Your http-client. See "getting started" section for help on setting up 
//the client.
const httpClient = require('../httpClient');

(async () => {

    const project = {
        prosjektId: "PRO1234",
        oppgavenavn: "My project name",
        startet: true
    };


    const response = await httpClient.post('prosjekter', project);
    const project = response.data;

    console.log(`Project name: ${project.oppgavenavn}, Project number: ${project.prosjektId}`);

})();


Examples

All of the examples assume that you have obtained an API key and have followed the instructions in the "Getting started" section. If not, do that first.

The code examples are written in JavaScript (ES6+), but you can of course use any language of your choosing.


Case 2 - Get a list of clocked in employees

const getClockedInEmployees = async () => {
    return await httpClient.get('ansatte/innstemplede');
}

//Get a list of employees from the API
const response = await getClockedInEmployees();
const employees = response.data;

//Loop through the list and print the full name
employees.map((employee) => console.log(emp.fornavn + ' ' + emp.etternavn));