I have written a JS API script that I run from my IOS device to start the timer as per the script below.
It starts the timer across my iPhone, iPad and Mac when I open the Toggl app, however it does not start the lock screen widget timer on the IOS devices. The Mac menu bar timer does show up though which is nice.
I am currently using the Scriptables app and IOS shortcuts to start the timer.
If I start the timer inside the Toggl app itself then the lockscreen widget timer will be displayed on the one device I started the timer on.
But I cannot figure out how to get the lockscreen widget to also show up using the API call - and ideally itβd be great if it could show up on both IOS devices.
Is this possible at all?
// icon-color: red; icon-glyph: clock;
// ===== CONFIG =====
const TOGGL_API_TOKEN = "SuperSecretToken";
const DEFAULT_SESSION_NAME = "Work Session";
// ===== GET WORKSPACE ID =====
async function getWorkspaceId() {
const tokenString = `${TOGGL_API_TOKEN}:api_token`;
const authHeader = Data.fromString(tokenString).toBase64String();
const req = new Request("https://api.track.toggl.com/api/v9/me");
req.headers = { "Authorization": `Basic ${authHeader}` };
const response = await req.loadJSON();
return response.default_workspace_id || response.workspaces?.[0]?.id;
}
// ===== START TOGGL TIMER =====
async function startTogglTimer(description) {
const tokenString = `${TOGGL_API_TOKEN}:api_token`;
const authHeader = Data.fromString(tokenString).toBase64String();
const workspaceId = await getWorkspaceId();
const req = new Request("https://api.track.toggl.com/api/v9/time_entries");
req.method = "POST";
req.headers = {
"Content-Type": "application/json",
"Authorization": `Basic ${authHeader}`
};
req.body = JSON.stringify({
description: description,
workspace_id: workspaceId,
duration: -1,
start: new Date().toISOString(),
created_with: "Scriptable Pomodoro"
});
try {
const response = await req.loadJSON();
console.log("Timer started β
", response);
return response.id;
} catch (e) {
console.error("Failed to start Toggl timer β", e);
return null;
}
}
// ===== RUN =====
(async () => {
const timerId = await startTogglTimer(DEFAULT_SESSION_NAME);
if (timerId) console.log(`Started timer ID: ${timerId}`);
})();