Skip to content

Instantly share code, notes, and snippets.

@afeld
Created January 27, 2024 17:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save afeld/33de09ee9816ae2f7285ac14cb87d0b9 to your computer and use it in GitHub Desktop.
Save afeld/33de09ee9816ae2f7285ac14cb87d0b9 to your computer and use it in GitHub Desktop.
setting Toggl entries to billable
# didn't seem to work, but saving here in case it's useful to others
import requests
from base64 import b64encode
workspace_id = 67337
project_id = 190841872
headers = {
"content-type": "application/json",
"Authorization": "Basic %s"
% b64encode(
b"EMAIL:PASSWORD"
).decode("ascii"),
}
# https://developers.track.toggl.com/docs/reports/detailed_reports
data = requests.post(
f"https://api.track.toggl.com/reports/api/v3/workspace/{workspace_id}/search/time_entries",
json={
"project_ids": [project_id],
"start_date": "2023-07-01",
"billable": False,
# "page_size": 1000,
},
headers=headers,
)
data.raise_for_status()
report = data.json()
for report_entry in report:
for time_entry in report_entry["time_entries"]:
print(".", end="", flush=True)
time_entry_id = time_entry["id"]
# https://developers.track.toggl.com/docs/api/time_entries/index.html#put-timeentries
response = requests.put(
f"https://api.track.toggl.com/api/v9/workspaces/{workspace_id}/time_entries/{time_entry_id}",
json={"billable": True},
headers=headers,
)
response.raise_for_status()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment