/lovable-integrations

Lovable and Toggl integration: Step-by-Step Guide 2025

Easily integrate Lovable with Toggl using our step-by-step guide. Discover tips and best practices to boost productivity and streamline your workflow today.

Matt Graham, CEO of Rapid Developers

Book a call with an Expert

Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.

Book a free No-Code consultation

How to integrate Lovable with Toggl?

 

Setting Up Toggl Dependencies

 
  • Create a new file in your Lovable project named package.json in the root directory if it does not already exist.
  • Add the following code snippet to the package.json file. Since Lovable doesn’t support a terminal, these dependencies will be installed automatically when the project loads.

{
  "dependencies": {
    "node-fetch": "2.6.1"
  }
}
  • This configuration tells Lovable to use the module node-fetch so that HTTP requests can be sent to Toggl’s API.

 

Creating the Toggl Service File

 
  • Create a new TypeScript file named togglService.ts in your project’s source directory (for example, in a folder called services if you are organizing your code that way).
  • Paste the following code snippet into togglService.ts. It contains a class that handles communication with the Toggl API (such as fetching projects and starting time entries).

import fetch from 'node-fetch';

export class TogglService {
  private apiToken: string;
  private workspaceId: string;

  constructor(apiToken: string, workspaceId: string) {
    this.apiToken = apiToken;
    this.workspaceId = workspaceId;
  }

  async getProjects(): Promise<any> {
    const url = https://api.track.toggl.com/api/v8/workspaces/${this.workspaceId}/projects;
    const response = await fetch(url, {
      headers: {
        'Authorization': 'Basic ' + Buffer.from(${this.apiToken}:api_token).toString('base64')
      }
    });
    if (!response.ok) {
      throw new Error(Toggl API error: ${response.statusText});
    }
    return response.json();
  }

  async startTimeEntry(description: string): Promise<any> {
    const url = 'https://api.track.toggl.com/api/v8/time_entries/start';
    const body = {
      time_entry: {
        description: description,
        created_with: 'Lovable'
      }
    };
    const response = await fetch(url, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        'Authorization': 'Basic ' + Buffer.from(${this.apiToken}:api_token).toString('base64')
      },
      body: JSON.stringify(body)
    });
    if (!response.ok) {
      throw new Error(Toggl API error: ${response.statusText});
    }
    return response.json();
  }
}
  • This file defines the TogglService class with two methods: getProjects (to retrieve project details) and startTimeEntry (to begin a new time entry).
  • Modify or extend this file with any additional API calls as needed.

 

Integrating Toggl Service into Your Main Application

 
  • Open your main application file (for example, app.ts) where you want to integrate Toggl’s functionality.
  • Add the following code snippet into app.ts to import and use the TogglService class. Insert it at the top of the file (for the import statement) and within a relevant function or initialization section for the Toggl API calls.

import { TogglService } from './togglService';

// Replace these with your actual Toggl API token and workspace ID
const TOGGLAPITOKEN = 'yourtogglapi_token';
const WORKSPACEID = 'yourworkspace_id';

const toggl = new TogglService(TOGGLAPITOKEN, WORKSPACE_ID);

// Example: Fetching projects from Toggl
toggl.getProjects()
  .then(projects => {
    console.log('Projects from Toggl:', projects);
    // Insert logic to handle the projects data within your Lovable project here
  })
  .catch(error => {
    console.error('Error fetching projects:', error);
  });

// Example: Starting a new time entry
toggl.startTimeEntry('Working on Lovable Project')
  .then(timeEntry => {
    console.log('Started time entry:', timeEntry);
    // Insert logic to handle the time entry response here
  })
  .catch(error => {
    console.error('Error starting time entry:', error);
  });
  • This code creates an instance of TogglService using your API credentials.
  • It then demonstrates two examples: fetching a list of projects and starting a new time entry.
  • You can replace the console.log statements with code that better integrates with your Lovable project’s UI or functionality.

 

Configuring Environment Variables in Code

 
  • Since Lovable does not have a terminal to set environment variables, you can hard-code your Toggl credentials as shown above for simplicity.
  • For better security, if your project supports a configuration file or secret storage mechanism, add your API token and workspace ID there and import them into your code.
  • For example, create a file named config.ts:

export const CONFIG = {
  TOGGLAPITOKEN: 'yourtogglapi_token',
  WORKSPACEID: 'yourworkspace_id'
};
  • Then modify your app.ts accordingly:

import { CONFIG } from './config';
import { TogglService } from './togglService';

const toggl = new TogglService(CONFIG.TOGGLAPITOKEN, CONFIG.WORKSPACE_ID);

// Further integration code remains the same...
  • This approach allows you to centralize your configuration, making it easier to update if needed.

 

Finalizing the Integration

 
  • Save all changes. The toggl integration should now be active in your Lovable project.
  • Test by ensuring that the appropriate network requests are made when the integrated code executes.
  • If you encounter any issues, review the console logs for errors from the Toggl API.

Still stuck?
Copy this prompt into ChatGPT and get a clear, personalized explanation.

This prompt helps an AI assistant understand your setup and guide you through the fix step by step, without assuming technical knowledge.

AI AI Prompt

Want to explore opportunities to work with us?

Connect with our team to unlock the full potential of no-code solutions with a no-commitment consultation!

Book a Free Consultation

Client trust and success are our top priorities

When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.

Rapid Dev was an exceptional project management organization and the best development collaborators I've had the pleasure of working with. They do complex work on extremely fast timelines and effectively manage the testing and pre-launch process to deliver the best possible product. I'm extremely impressed with their execution ability.

CPO, Praction - Arkady Sokolov

May 2, 2023

Working with Matt was comparable to having another co-founder on the team, but without the commitment or cost. He has a strategic mindset and willing to change the scope of the project in real time based on the needs of the client. A true strategic thought partner!

Co-Founder, Arc - Donald Muir

Dec 27, 2022

Rapid Dev are 10/10, excellent communicators - the best I've ever encountered in the tech dev space. They always go the extra mile, they genuinely care, they respond quickly, they're flexible, adaptable and their enthusiasm is amazing.

Co-CEO, Grantify - Mat Westergreen-Thorne

Oct 15, 2022

Rapid Dev is an excellent developer for no-code and low-code solutions.
We’ve had great success since launching the platform in November 2023. In a few months, we’ve gained over 1,000 new active users. We’ve also secured several dozen bookings on the platform and seen about 70% new user month-over-month growth since the launch.

Co-Founder, Church Real Estate Marketplace - Emmanuel Brown

May 1, 2024 

Matt’s dedication to executing our vision and his commitment to the project deadline were impressive. 
This was such a specific project, and Matt really delivered. We worked with a really fast turnaround, and he always delivered. The site was a perfect prop for us!

Production Manager, Media Production Company - Samantha Fekete

Sep 23, 2022