Learn how to integrate Bolt.new AI with Clockify using our easy, step-by-step guide. Boost productivity by automating time tracking for your team.
Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
clockifyConfig.ts
. This file will store your Clockify API key and workspace ID. Since Bolt.new AI does not have a terminal, manually add this file using the file explorer in your project.clockifyConfig.ts
, add the following code snippet. Replace the placeholders with your actual Clockify API key and workspace ID.
export const CLOCKIFYAPIKEY = "YOURCLOCKIFYAPI_KEY";
export const CLOCKIFYWORKSPACEID = "YOURWORKSPACEID";
clockifyService.ts
in your project. This file will handle the API interactions with Clockify.fetch
available in modern environments.
import { CLOCKIFYAPIKEY, CLOCKIFYWORKSPACEID } from "./clockifyConfig";
const BASE_URL = "https://api.clockify.me/api/v1";
const headers = {
"Content-Type": "application/json",
"X-Api-Key": CLOCKIFYAPIKEY
};
/**
- Fetch all time entries for a given user.
- Replace 'userId' with the actual Clockify user ID.
*/
export async function getTimeEntries(userId: string) {
const url = ${BASE_URL}/workspaces/${CLOCKIFY_WORKSPACE_ID}/user/${userId}/time-entries;
const response = await fetch(url, { headers });
if (!response.ok) {
throw new Error("Failed to fetch time entries: " + response.statusText);
}
return await response.json();
}
/**
- Create a new time entry.
- Adjust the payload as needed.
*/
export async function createTimeEntry(userId: string, data: any) {
const url = ${BASE_URL}/workspaces/${CLOCKIFY_WORKSPACE_ID}/user/${userId}/time-entries;
const response = await fetch(url, {
method: "POST",
headers,
body: JSON.stringify(data)
});
if (!response.ok) {
throw new Error("Failed to create time entry: " + response.statusText);
}
return await response.json();
}
index.ts
or a specific module handling business logic, open that file.clockifyService.ts
and call them when needed. Below is an example snippet that demonstrates calling getTimeEntries
and logging the result. Insert this code block into the appropriate module in your project.
import { getTimeEntries, createTimeEntry } from "./clockifyService";
// Replace with the actual Clockify user ID.
const clockifyUserId = "YOURCLOCKIFYUSER_ID";
// Example: Fetch and log time entries for a user.
async function fetchAndLogTimeEntries() {
try {
const entries = await getTimeEntries(clockifyUserId);
console.log("Time Entries:", entries);
} catch (error) {
console.error("Error fetching time entries:", error);
}
}
fetchAndLogTimeEntries();
// Example: Create a new time entry.
// Prepare your payload according to Clockify API documentation.
// Adjust fields such as description, start, and end as required.
async function addTimeEntry() {
const entryData = {
description: "Meeting with client",
start: new Date().toISOString(),
// You may add an 'end' field if required.
billable: true
};
try {
const newEntry = await createTimeEntry(clockifyUserId, entryData);
console.log("Created Time Entry:", newEntry);
} catch (error) {
console.error("Error creating time entry:", error);
}
}
// Uncomment below to test creating a time entry.
// addTimeEntry();
fetch
API and TypeScript. Modern browsers and Node environments (if using a bundler) usually include a global fetch
implementation.fetch
in a Node.js environment, consider adding a polyfill by creating a file named polyfills.ts
and inserting the following code. Then import it at the very top of your main file (for example, index.ts
).
/ polyfills.ts /
import "whatwg-fetch";
whatwg-fetch
library as an external dependency using your project’s dependency management interface (if available). If such interface isn’t available, verify that the environment already supports fetch
.
clockifyConfig.ts
, clockifyService.ts
, and optionally polyfills.ts
) are correctly placed.When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.