### GET Setup calendar integration Source: https://engineering.toggl.com/docs/focus/api/calendar/index.html Connect a new calendar integration by making a GET request to the setup endpoint. This endpoint requires path parameters for organization and workspace IDs, and accepts query parameters to specify the calendar provider and a return URL. ```APIDOC ## GET /api/organizations/{organization_id}/workspaces/{workspace_id}/integrations/calendar/setup ### Description Connect a new calendar integration. ### Method GET ### Endpoint /api/organizations/{organization_id}/workspaces/{workspace_id}/integrations/calendar/setup ### Parameters #### Path Parameters - **organization_id** (integer) - Required - organization ID - **workspace_id** (integer) - Required - workspace ID #### Query Parameters - **provider** (string) - Required - Calendar service provider which the calendars will be retrieved - **return_to** (string) - Optional - Page to which the user will be redirected after authenticating ### Response #### Success Response (302) Redirect to oAuth URL #### Error Response (400) Invalid request #### Error Response (402) status payment required: integration already exists #### Error Response (500) Internal Server Error ``` -------------------------------- ### Get Project Rates (Rust) Source: https://engineering.toggl.com/docs/focus/api/rates/index.html An asynchronous example in Rust using 'reqwest' and 'tokio' to retrieve project rates. It demonstrates setting up a client with basic authentication and making the GET request. ```rust extern crate tokio; extern crate serde_json; use reqwest::{Client}; use reqwest::header::{CONTENT_TYPE}; #[tokio::main] async fn main() -> Result<(), reqwest::Error> { let client = Client::new().basic_auth("", ""); let json = client.request(Method::GET, "https://focus.toggl.com/api/organizations/{organization_id}/workspaces/{workspace_id}/projects/{project_id}/rates".to_string()) .header(CONTENT_TYPE, "application/json") .send() .await? .json() .await?; println!(_{("#?"}, json); Ok(()) } ``` -------------------------------- ### Get Milestone with Go Source: https://engineering.toggl.com/docs/focus/api/milestones/index.html Implement a GET request in Go to fetch milestone details. This example shows how to set headers, basic authentication, and handle the response. ```go req, err := http.NewRequest(http.MethodGet, "https://focus.toggl.com/api/workspaces/{workspace_id}/milestones/{milestone_id}") if err != nil { print(err) } req.Header.Set("Content-Type", "application/json; charset=utf-8") req.SetBasicAuth("", "") client := &http.Client{} resp, err := client.Do(req) if err != nil { print(err) } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { print(err) } fmt.Print(string(body)) ``` -------------------------------- ### List Project Attachments with Python Source: https://engineering.toggl.com/docs/focus/api/project-attachments/index.html A Python example using the requests library to fetch project attachments. Assumes the 'requests' library is installed. ```Python import requests from base64 import b64encode data = requests.get('https://focus.toggl.com/api/organizations/{organization_id}/workspaces/{workspace_id}/projects/{project_id}/attachments', headers={'content-type': 'application/json'}) print(data.json()) ``` -------------------------------- ### Get User Workspace Settings (Ruby) Source: https://engineering.toggl.com/docs/focus/api/user-workspace-settings/index.html Ruby example for retrieving user workspace settings using Net::HTTP. Parses the JSON response. ```ruby require 'net/http' require 'uri' require 'json' uri = URI('https://focus.toggl.com/api/workspaces/{workspace_id}/users/me/settings') http = Net::HTTP.new(uri.host, uri.port) req = Net::HTTP::Get.new(uri.path) req['Content-Type'] = "application/json" request.basic_auth '', '' res = http.request(req) puts JSON.parse(res.body) ``` -------------------------------- ### List Projects using Go Source: https://engineering.toggl.com/docs/focus/api/projects/index.html Demonstrates fetching projects using Go's standard http library. Includes setting headers and basic authentication. ```go req, err := http.NewRequest(http.MethodGet, \ "https://focus.toggl.com/api/organizations/{organization_id}/workspaces/{workspace_id}/projects") if err != nil { print(err) } req.Header.Set("Content-Type", "application/json; charset=utf-8") req.SetBasicAuth("", "") client := &http.Client{} resp, err := client.Do(req) if err != nil { print(err) } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { print(err) } fmt.Print(string(body)) ``` -------------------------------- ### Get a Single Ghost (Rust) Source: https://engineering.toggl.com/docs/focus/api/ghosts Rust example using the reqwest and tokio crates to make a GET request for a ghost. Demonstrates client setup, basic authentication, and header configuration. ```Rust extern crate tokio extern crate serde_json use reqwest::{Client}; use reqwest::header::{CONTENT_TYPE}; #[tokio::main] async fn main() -> Result<(), reqwest::Error> { let client = Client::new().basic_auth("", ""); let json = client.request(Method::GET, "https://focus.toggl.com/api/organizations/{organization_id}/workspaces/{workspace_id}/ghosts/{ghost_id}".to_string()) .header(CONTENT_TYPE, "application/json") .send() .await? .json() .await?; println!("{:#?}", json); Ok(()) } ``` -------------------------------- ### Create New Task using Go Source: https://engineering.toggl.com/docs/focus/api/tasks Demonstrates creating a new task in Go. This example shows how to marshal the JSON payload, create an HTTP POST request, set headers, and authenticate using basic auth. Error handling for each step is included. ```go bytes, err := json.Marshal('{"assignee_user_ids":[{}],"auto_log_time":"boolean","billable":"boolean","color":"string","custom_fields":{},"description":"string","end_date":"string","estimated_mins":"integer","ghost_assignee_ids":[{}],"integration_ext_id":"integer","integration_source":"string","name":"string","notes":"string","parent_task_id":"integer","pinned":"boolean","position":"integer","priority":"string","priority_at":"string","private":"boolean","project_id":"integer","rrule":"string","start_date":"string","status_id":"integer","tag_ids":[{}],"team_assignee_ids":[{}]}') if err != nil { print(err) } req, err := http.NewRequest(http.MethodPost, "https://focus.toggl.com/api/organizations/{organization_id}/workspaces/{workspace_id}/tasks", bytes.NewBuffer(bytes)) if err != nil { print(err) } req.Header.Set("Content-Type", "application/json; charset=utf-8") req.SetBasicAuth("", "") client := &http.Client{} resp, err := client.Do(req) if err != nil { print(err) } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { print(err) } fmt.Print(string(body)) ``` -------------------------------- ### Get Project by ID (JavaScript) Source: https://engineering.toggl.com/docs/focus/api/projects This JavaScript example uses the `fetch` API to get project data. It demonstrates setting the GET method, content type, and authorization header. ```javascript fetch("https://focus.toggl.com/api/organizations/{organization_id}/workspaces/{workspace_id}/projects/{project_id}", { method: "GET", headers: { "Content-Type": "application/json", "Authorization": `Basic ${base64.encode(:)}` }, }) .then((resp) => resp.json()) .then((json) => { console.log(json); }) .catch(err => console.error(err)); ``` -------------------------------- ### Create Project (JavaScript) Source: https://engineering.toggl.com/docs/focus/api/projects This JavaScript example uses the `fetch` API to create a new project. It demonstrates setting the request method to POST, providing the JSON payload in the body, and including the necessary Authorization header with base64 encoded credentials. ```javascript fetch("https://focus.toggl.com/api/organizations/{organization_id}/workspaces/{workspace_id}/projects", { method: "POST", body: {"auto_compute_estimates":"boolean","billable":"boolean","client_id":"integer","color":"string","completion_mode":"string","custom_fields":{},"description":"string","draft":"boolean","end_date":"string","estimated_mins":"integer","fixed_fee":{"amount":"number","currency":"string"},"is_template":"boolean","name":"string","parent_project_id":"integer","pinned":"boolean","private":"boolean","rollover_mode":"string","rrule":"string","start_date":"string","tag_ids":[{}]}", headers: { "Content-Type": "application/json", "Authorization": `Basic ${base64.encode(:)}` }, }) .then((resp) => resp.json()) .then((json) => { console.log(json); }) .catch(err => console.error(err)); ``` -------------------------------- ### Get Saved Views with Python Source: https://engineering.toggl.com/docs/focus/api/SavedViews Uses the requests library in Python to get saved views. Assumes the 'requests' library is installed. ```python import requests from base64 import b64encode data = requests.get('https://focus.toggl.com/api/workspaces/{workspace_id}/saved-views', headers={'content-type': 'application/json'}) print(data.json()) ``` -------------------------------- ### List Tags using Go Source: https://engineering.toggl.com/docs/focus/api/tags Example of how to fetch a list of tags using Go's http package. This snippet demonstrates setting headers and basic authentication. ```go req, err := http.NewRequest(http.MethodGet, "https://focus.toggl.com/api/workspaces/{workspace_id}/tags") if err != nil { print(err) } req.Header.Set("Content-Type", "application/json; charset=utf-8") req.SetBasicAuth("", "") client := &http.Client{} resp, err := client.Do(req) if err != nil { print(err) } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { print(err) } fmt.Print(string(body)) ``` -------------------------------- ### Get Organization Roles with Go Source: https://engineering.toggl.com/docs/focus/api/organization/index.html Implement a GET request in Go to fetch organization roles. This example shows how to set headers and basic authentication. ```go req, err := http.NewRequest(http.MethodGet, "https://focus.toggl.com/api/organizations/{organization_id}/roles") if err != nil { print(err) } req.Header.Set("Content-Type", "application/json; charset=utf-8") req.SetBasicAuth("", "") client := &http.Client{} resp, err := client.Do(req) if err != nil { print(err) } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { print(err) } fmt.Print(string(body)) ``` -------------------------------- ### Get Time Off for a Ghost (JavaScript) Source: https://engineering.toggl.com/docs/focus/api/Time JavaScript example using the Fetch API to get time off data. Includes basic authentication and error handling. ```JavaScript fetch("https://focus.toggl.com/api/organizations/{organization_id}/{workspace_id}/timeoff/ghosts/{ghost_id}", { method: "GET", headers: { "Content-Type": "application/json", "Authorization": `Basic ${base64.encode(:)}` }, }) .then((resp) => resp.json()) .then((json) => { console.log(json); }) .catch(err => console.error(err)); ``` -------------------------------- ### List Clients using Go Source: https://engineering.toggl.com/docs/focus/api/clients/index.html This Go code snippet demonstrates how to fetch a list of clients using the `net/http` package. It includes setting the necessary headers and basic authentication. ```go req, err := http.NewRequest(http.MethodGet, "https://focus.toggl.com/api/workspaces/{workspace_id}/clients") if err != nil { print(err) } req.Header.Set("Content-Type", "application/json; charset=utf-8") req.SetBasicAuth("", "") client := &http.Client{} resp, err := client.Do(req) if err != nil { print(err) } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { print(err) } fmt.Print(string(body)) ``` -------------------------------- ### Create New Client with Go Source: https://engineering.toggl.com/docs/focus/api/clients/index.html This Go code snippet demonstrates how to create a new client using the `net/http` package. It includes JSON marshaling for the request body and basic authentication. ```go bytes, err := json.Marshal('{"name":"string"}') if err != nil { print(err) } req, err := http.NewRequest(http.MethodPost, "https://focus.toggl.com/api/workspaces/{workspace_id}/clients", bytes.NewBuffer(bytes)) if err != nil { print(err) } req.Header.Set("Content-Type", "application/json; charset=utf-8") req.SetBasicAuth("", "") client := &http.Client{} resp, err := client.Do(req) if err != nil { print(err) } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { print(err) } fmt.Print(string(body)) ``` -------------------------------- ### Get a Single Ghost (JavaScript) Source: https://engineering.toggl.com/docs/focus/api/ghosts JavaScript fetch API example for getting a ghost. It shows how to set the method, headers, and handle the JSON response. ```JavaScript fetch("https://focus.toggl.com/api/organizations/{organization_id}/workspaces/{workspace_id}/ghosts/{ghost_id}", { method: "GET", headers: { "Content-Type": "application/json", "Authorization": `Basic ${base64.encode(:)}` }, }) .then((resp) => resp.json()) .then((json) => { console.log(json); }) .catch(err => console.error(err)); ``` -------------------------------- ### Create Project (Go) Source: https://engineering.toggl.com/docs/focus/api/projects This Go code snippet demonstrates how to create a new project using the Toggl Focus API. It involves marshaling JSON data, setting up an HTTP POST request with appropriate headers and basic authentication, and handling the response. ```go bytes, err := json.Marshal('{"auto_compute_estimates":"boolean","billable":"boolean","client_id":"integer","color":"string","completion_mode":"string","custom_fields":{},"description":"string","draft":"boolean","end_date":"string","estimated_mins":"integer","fixed_fee":{"amount":"number","currency":"string"},"is_template":"boolean","name":"string","parent_project_id":"integer","pinned":"boolean","private":"boolean","rollover_mode":"string","rrule":"string","start_date":"string","tag_ids":[{}]}') if err != nil { print(err) } req, err := http.NewRequest(http.MethodPost, "https://focus.toggl.com/api/organizations/{organization_id}/workspaces/{workspace_id}/projects", bytes.NewBuffer(bytes)) if err != nil { print(err) } req.Header.Set("Content-Type", "application/json; charset=utf-8") req.SetBasicAuth("", "") client := &http.Client{} resp, err := client.Do(req) if err != nil { print(err) } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { print(err) } fmt.Print(string(body)) ``` -------------------------------- ### Get a Single Ghost (Ruby) Source: https://engineering.toggl.com/docs/focus/api/ghosts Ruby example for retrieving a ghost. It uses the Net::HTTP library to make the GET request and parse the JSON response. ```Ruby require 'net/http' require 'uri' require 'json' uri = URI('https://focus.toggl.com/api/organizations/{organization_id}/workspaces/{workspace_id}/ghosts/{ghost_id}') http = Net::HTTP.new(uri.host, uri.port) req = Net::HTTP::Get.new(uri.path) req['Content-Type'] = "application/json" request.basic_auth '', '' res = http.request(req) puts JSON.parse(res.body) ``` -------------------------------- ### GET List Project Rates (Go) Source: https://engineering.toggl.com/docs/focus/api/rates This Go code snippet demonstrates how to fetch project rates using the `net/http` package. It constructs a GET request, sets necessary headers, and handles the response. Basic authentication is applied using email and password. ```go req, err := http.NewRequest(http.MethodGet, "https://focus.toggl.com/api/organizations/{organization_id}/workspaces/{workspace_id}/projects/{project_id}/rates") if err != nil { print(err) } req.Header.Set("Content-Type", "application/json; charset=utf-8") req.SetBasicAuth("", "") client := &http.Client{} resp, err := client.Do(req) if err != nil { print(err) } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { print(err) } fmt.Print(string(body)) ``` -------------------------------- ### Get Time Block by ID using Go Source: https://engineering.toggl.com/docs/focus/api/time-blocks/index.html Implement a GET request in Go to fetch a time block. This example demonstrates setting headers and basic authentication. ```go req, err := http.NewRequest(http.MethodGet, "https://focus.toggl.com/api/organizations/{organization_id}/workspaces/{workspace_id}/tasks/{task_id}/time-blocks/{time_block_id}") if err != nil { print(err) } req.Header.Set("Content-Type", "application/json; charset=utf-8") req.SetBasicAuth("", "") client := &http.Client{} resp, err := client.Do(req) if err != nil { print(err) } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { print(err) } fmt.Print(string(body)) ``` -------------------------------- ### Setup Calendar Integration Source: https://engineering.toggl.com/docs/focus/api/calendar Connect a new calendar integration by initiating the setup process. This endpoint redirects the user to an OAuth URL for authentication. ```APIDOC ## GET /api/workspaces/{workspace_id}/integrations/calendar/setup ### Description Connect a new calendar integration. ### Method GET ### Endpoint https://focus.toggl.com/api/workspaces/{workspace_id}/integrations/calendar/setup ### Parameters #### Path Parameters - **workspace_id** (integer) - Required - workspace ID #### Query Parameters - **provider** (string) - Required - Calendar service provider which the calendars will be retrieved - **return_to** (string) - Optional - Page to which the user will be redirected after authenticating ### Response #### Success Response (302) Redirect to oAuth URL #### Error Response (400) Invalid request #### Error Response (402) status payment required: integration already exists #### Error Response (500) Internal Server Error ``` -------------------------------- ### Get Organization Users (JavaScript) Source: https://engineering.toggl.com/docs/focus/api/organization This JavaScript example uses the fetch API to get organization users. It includes setting the 'Content-Type' and 'Authorization' headers with basic authentication. ```javascript fetch("https://focus.toggl.com/api/organizations/{organization_id}/users", { method: "GET", headers: { "Content-Type": "application/json", "Authorization": `Basic ${base64.encode(:)}` }, }) .then((resp) => resp.json()) .then((json) => { console.log(json); }) .catch(err => console.error(err)); ``` -------------------------------- ### List Tags using Go Source: https://engineering.toggl.com/docs/focus/api/tags/index.html Example of how to fetch tags from a workspace using Go's http package. Ensure proper error handling and response body reading. ```Go req, err := http.NewRequest(http.MethodGet, "https://focus.toggl.com/api/workspaces/{workspace_id}/tags") if err != nil { print(err) } req.Header.Set("Content-Type", "application/json; charset=utf-8") req.SetBasicAuth("", "") client := &http.Client{} resp, err := client.Do(req) if err != nil { print(err) } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { print(err) } fmt.Print(string(body)) ``` -------------------------------- ### Get Project Rates (JavaScript) Source: https://engineering.toggl.com/docs/focus/api/rates/index.html An example using the Fetch API in JavaScript to get project rates. It includes setting the 'Content-Type' and 'Authorization' headers with basic authentication. ```javascript fetch("https://focus.toggl.com/api/organizations/{organization_id}/workspaces/{workspace_id}/projects/{project_id}/rates", { method: "GET", headers: { "Content-Type": "application/json", "Authorization": `Basic ${base64.encode(:)}` }, }) .then((resp) => resp.json()) .then((json) => { console.log(json); }) .catch(err => console.error(err)); ``` -------------------------------- ### Setup Calendar Integration Source: https://engineering.toggl.com/docs/focus/api/calendar Connect a new calendar integration to your workspace. This endpoint initiates the setup process, which may involve OAuth redirection. ```APIDOC ## GET Setup calendar integration ### Description Connect a new calendar integration. ### Method GET ### Endpoint `https://focus.toggl.com/api/organizations/{organization_id}/workspaces/{workspace_id}/integrations/calendar/setup` ### Parameters #### Path Parameters - **organization_id** (integer) - Required - organization ID - **workspace_id** (integer) - Required - workspace ID #### Query Parameters - **provider** (string) - Required - Calendar service provider which the calendars will be retrieved - **return_to** (string) - Optional - Page to which the user will be redirected after authenticating ### Response #### Success Response (302) Redirect to oAuth URL #### Error Responses - **400** - Invalid request - **402** - status payment required: integration already exists - **500** - Internal Server Error ``` -------------------------------- ### Get Capacities Data (JavaScript) Source: https://engineering.toggl.com/docs/focus/api/capacities/index.html This JavaScript example uses the fetch API to make a GET request to the Capacities endpoint. It includes setting the Content-Type and Authorization headers. ```javascript fetch("https://focus.toggl.com/api/organizations/{organization_id}/workspaces/{workspace_id}/capacities/{group}", { method: "GET", headers: { "Content-Type": "application/json", "Authorization": `Basic ${base64.encode(:)}` }, }) .then((resp) => resp.json()) .then((json) => { console.log(json); }) .catch(err => console.error(err)); ``` -------------------------------- ### Create Tasks, Subtasks, Time Blocks, and Time Entries in Bulk (Go) Source: https://engineering.toggl.com/docs/focus/api/composite This Go example demonstrates how to marshal a JSON payload and make a POST request to the composite API endpoint. It includes setting headers and basic authentication. ```go bytes, err := json.Marshal('{"subtasks":[{"assignee_user_ids":[{}],"auto_log_time":"boolean","billable":"boolean","color":"string","custom_fields":{},"description":"string","end_date":"string","estimated_mins":"integer","ghost_assignee_ids":[{}],"integration_ext_id":"integer","integration_source":"string","name":"string","notes":"string","pinned":"boolean","position":"integer","priority":"string","priority_at":"string","private":"boolean","project_id":"integer","rrule":"string","start_date":"string","status_id":"integer","tag_ids":[{}],"team_assignee_ids":[{}]}],"task":{"assignee_user_ids":[{}],"auto_log_time":"boolean","billable":"boolean","color":"string","custom_fields":{},"description":"string","end_date":"string","estimated_mins":"integer","ghost_assignee_ids":[{}],"integration_ext_id":"integer","integration_source":"string","name":"string","notes":"string","parent_task_id":"integer","pinned":"boolean","position":"integer","priority":"string","priority_at":"string","private":"boolean","project_id":"integer","recurring_task_id":"integer","rrule":"string","start_date":"string","status_id":"integer","tag_ids":[{}],"team_assignee_ids":[{}]}},"time_blocks":[{"completed":"boolean","duration":"integer","outbound_sync":"boolean","start":"string"}],"time_entry":{"calendar_event_id":"integer","description":"string","duration":"integer","planned_at":"string","planned_duration":"integer","planned_start":"string","start":"string","time_block":{"completed":"boolean","duration":"integer","outbound_sync":"boolean","start":"string"},"time_block_id":"integer","tracked_at":"string","type":{}}}') if err != nil { print(err) } req, err := http.NewRequest(http.MethodPost, "https://focus.toggl.com/api/workspaces/{workspace_id}/composite/tasks", bytes.NewBuffer(bytes)) if err != nil { print(err) } req.Header.Set("Content-Type", "application/json; charset=utf-8") req.SetBasicAuth("", "") client := &http.Client{} resp, err := client.Do(req) if err != nil { print(err) } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { print(err) } fmt.Print(string(body)) ``` -------------------------------- ### Get Time Offs with JavaScript Source: https://engineering.toggl.com/docs/focus/api/Time/index.html Fetch time off data using the JavaScript fetch API. This example demonstrates setting the GET method, content type, and authorization header. ```JavaScript fetch("https://focus.toggl.com/api/organizations/{organization_id}/{workspace_id}/timeoff", { method: "GET", headers: { "Content-Type": "application/json", "Authorization": `Basic ${base64.encode(:)}` }, }) .then((resp) => resp.json()) .then((json) => { console.log(json); }) .catch(err => console.error(err)); ``` -------------------------------- ### Get Project with Children (Go) Source: https://engineering.toggl.com/docs/focus/api/projects This Go code demonstrates how to fetch a project and its children using the http package. It sets the necessary headers and basic authentication. Remember to handle potential errors during the request and response processing. ```go req, err := http.NewRequest(http.MethodGet, "https://focus.toggl.com/api/organizations/{organization_id}/workspaces/{workspace_id}/projects/{project_id}/children") if err != nil { print(err) } req.Header.Set("Content-Type", "application/json; charset=utf-8") req.SetBasicAuth("", "") client := &http.Client{} resp, err := client.Do(req) if err != nil { print(err) } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { print(err) } fmt.Print(string(body)) ``` -------------------------------- ### Go HTTP Request for Project Children Source: https://engineering.toggl.com/docs/focus/api/projects/index.html Example of making a GET request in Go to fetch a project and its sub-projects. It demonstrates setting headers, basic authentication, and handling the response. ```go req, err := http.NewRequest(http.MethodGet, "https://focus.toggl.com/api/organizations/{organization_id}/workspaces/{workspace_id}/projects/{project_id}/children") if err != nil { print(err) } req.Header.Set("Content-Type", "application/json; charset=utf-8") req.SetBasicAuth("", "") client := &http.Client{} resp, err := client.Do(req) if err != nil { print(err) } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { print(err) } fmt.Print(string(body)) ``` -------------------------------- ### Get All Saved Views (JavaScript) Source: https://engineering.toggl.com/docs/focus/api/SavedViews/index.html This JavaScript example uses the Fetch API to make a GET request for saved views. It handles the response and logs the JSON data or any errors. ```javascript fetch("https://focus.toggl.com/api/workspaces/{workspace_id}/saved-views", { method: "GET", headers: { "Content-Type": "application/json" }, }) .then((resp) => resp.json()) .then((json) => { console.log(json); }) .catch(err => console.error(err)); ``` -------------------------------- ### Create Project Attachment (Go) Source: https://engineering.toggl.com/docs/focus/api/project-attachments Example of creating a project attachment using Go's http package. Handles request creation, header setting, and response reading. ```go req, err := http.NewRequest(http.MethodPost, "https://focus.toggl.com/api/organizations/{organization_id}/workspaces/{workspace_id}/projects/{project_id}/attachments") if err != nil { print(err) } req.Header.Set("Content-Type", "application/json; charset=utf-8") client := &http.Client{} resp, err := client.Do(req) if err != nil { print(err) } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { print(err) } fmt.Print(string(body)) ``` -------------------------------- ### Get Time Block by ID using Python Source: https://engineering.toggl.com/docs/focus/api/time-blocks/index.html Use the Python requests library to get a time block. This example shows how to set the content type and basic authentication header. ```python import requests from base64 import b64encode data = requests.get('https://focus.toggl.com/api/organizations/{organization_id}/workspaces/{workspace_id}/tasks/{task_id}/time-blocks/{time_block_id}', headers={'content-type': 'application/json', 'Authorization' : 'Basic %s' % b64encode(b":").decode("ascii")}) print(data.json()) ``` -------------------------------- ### Setup Calendar Integration Source: https://engineering.toggl.com/docs/focus/api/calendar/index.html Connect a new calendar integration by initiating the setup process. This endpoint redirects the user to an OAuth URL for authentication and authorization. ```APIDOC ## GET /api/workspaces/{workspace_id}/integrations/calendar/setup ### Description Connect a new calendar integration. ### Method GET ### Endpoint https://focus.toggl.com/api/workspaces/{workspace_id}/integrations/calendar/setup ### Parameters #### Path Parameters - **workspace_id** (integer) - Required - workspace ID #### Query Parameters - **provider** (string) - Required - Calendar service provider which the calendars will be retrieved - **return_to** (string) - Optional - Page to which the user will be redirected after authenticating ### Response #### Success Response (302) Redirect to oAuth URL #### Error Responses - **400**: Invalid request - **402**: status payment required: integration already exists - **500**: Internal Server Error ``` -------------------------------- ### Get Current Tracked Time Entry (JavaScript) Source: https://engineering.toggl.com/docs/focus/api/tracking This JavaScript example uses the Fetch API to get the current time entry. It includes setting the Authorization header with a base64 encoded string. ```javascript fetch("https://focus.toggl.com/api/organizations/{organization_id}/workspaces/{workspace_id}/tracking/current", { method: "GET", headers: { "Content-Type": "application/json", "Authorization": `Basic ${base64.encode(:)}` }, }) .then((resp) => resp.json()) .then((json) => { console.log(json); }) .catch(err => console.error(err)); ``` -------------------------------- ### List Project Rates Summary (JavaScript) Source: https://engineering.toggl.com/docs/focus/api/rates This JavaScript example uses the Fetch API to get project rates. It demonstrates setting the method, headers including basic authentication, and handling the JSON response. ```javascript fetch("https://focus.toggl.com/api/organizations/{organization_id}/workspaces/{workspace_id}/projects/rates", { method: "GET", headers: { "Content-Type": "application/json", "Authorization": `Basic ${base64.encode(:)}` }, }) .then((resp) => resp.json()) .then((json) => { console.log(json); }) .catch(err => console.error(err)); ``` -------------------------------- ### Get Milestone with Rust Source: https://engineering.toggl.com/docs/focus/api/milestones/index.html Fetch milestone details in Rust using the reqwest client. This example demonstrates setting up the client, making a GET request with basic authentication, and handling the JSON response. ```rust extern crate tokio extern crate serde_json; use reqwest::{Client}; use reqwest::header::{CONTENT_TYPE}; #[tokio::main] async fn main() -> Result<(), reqwest::Error> { let client = Client::new().basic_auth("", ""); let json = client.request(Method::GET, "https://focus.toggl.com/api/workspaces/{workspace_id}/milestones/{milestone_id}".to_string()) .header(CONTENT_TYPE, "application/json") .send() .await? .json() .await?; println("{:#?}", json); Ok(()) } ``` -------------------------------- ### Get User Workspace Settings (Go) Source: https://engineering.toggl.com/docs/focus/api/user-workspace-settings/index.html Example of fetching user workspace settings using Go's http package. Ensure to handle potential errors and close the response body. ```go req, err := http.NewRequest(http.MethodGet, "https://focus.toggl.com/api/workspaces/{workspace_id}/users/me/settings") if err != nil { print(err) } req.Header.Set("Content-Type", "application/json; charset=utf-8") req.SetBasicAuth("", "") client := &http.Client{} resp, err := client.Do(req) if err != nil { print(err) } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { print(err) } fmt.Print(string(body)) ``` -------------------------------- ### Get Project with Parent Projects (Go) Source: https://engineering.toggl.com/docs/focus/api/projects This Go code demonstrates how to construct an HTTP GET request to fetch project data. It includes setting headers and basic authentication. Error handling for the request and response body reading is also shown. ```go req, err := http.NewRequest(http.MethodGet, "https://focus.toggl.com/api/organizations/{organization_id}/workspaces/{workspace_id}/projects/{project_id}/parents") if err != nil { print(err) } req.Header.Set("Content-Type", "application/json; charset=utf-8") req.SetBasicAuth("", "") client := &http.Client{} resp, err := client.Do(req) if err != nil { print(err) } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { print(err) } fmt.Print(string(body)) ``` -------------------------------- ### GET Get time offs of organization users Source: https://engineering.toggl.com/docs/focus/api/Time Retrieves time-off information for users within a specified organization. Requires organization ID and can be filtered by user IDs, start date, and end date. ```APIDOC ## GET /organizations/{organization_id}/timeoff ### Description Returns time offs of organization users. ### Method GET ### Endpoint https://focus.toggl.com/api/organizations/{organization_id}/timeoff ### Parameters #### Path Parameters - **organization_id** (integer) - Required - Organization ID #### Query Parameters - **user_id** ([]integer) - Required - User IDs - **start_date** (string) - Required - From date (YYYY-MM-DD) - **end_date** (string) - Required - To date (YYYY-MM-DD) ### Response #### Success Response (200) - **items** (Array of object) - List of time-off entries. - **end_time** (string) - **ghost_id** (integer) - **start_time** (string) - **timeoff_id** (integer) - **user_id** (integer) #### Error Response (400) Invalid parameters #### Error Response (403) Forbidden #### Error Response (500) Internal Server Error ``` -------------------------------- ### Get Time Block by ID (Rust) Source: https://engineering.toggl.com/docs/focus/api/time-blocks Provides a Rust example using reqwest and tokio to fetch a time block by ID. Includes setting up the client with basic authentication and sending the GET request. ```Rust extern crate tokio; extern crate serde_json; use reqwest::{Client}; use reqwest::header::{CONTENT_TYPE}; #[tokio::main] async fn main() -> Result<(), reqwest::Error> { let client = Client::new().basic_auth("", ""); let json = client.request(Method::GET, "https://focus.toggl.com/api/organizations/{organization_id}/workspaces/{workspace_id}/tasks/{task_id}/time-blocks/{time_block_id}".to_string()) .header(CONTENT_TYPE, "application/json") .send() .await? .json() .await?; println!("{:#?}", json); Ok(()) } ``` -------------------------------- ### List Tasks (Go) Source: https://engineering.toggl.com/docs/focus/api/tasks Example of fetching tasks using Go's http package. Ensure to handle errors and close the response body. ```go req, err := http.NewRequest(http.MethodGet, "https://focus.toggl.com/api/organizations/{organization_id}/workspaces/{workspace_id}/tasks") if err != nil { print(err) } req.Header.Set("Content-Type", "application/json; charset=utf-8") req.SetBasicAuth("", "") client := &http.Client{} resp, err := client.Do(req) if err != nil { print(err) } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { print(err) } fmt.Print(string(body)) ``` -------------------------------- ### Create Project (Ruby) Source: https://engineering.toggl.com/docs/focus/api/projects This Ruby script shows how to create a new project via the Toggl Focus API. It utilizes the Net::HTTP library for making the POST request and includes setting the Content-Type header and basic authentication. ```ruby require 'net/http' require 'uri' require 'json' uri = URI('https://focus.toggl.com/api/organizations/{organization_id}/workspaces/{workspace_id}/projects') http = Net::HTTP.new(uri.host, uri.port) req = Net::HTTP::Post.new(uri.path) req['Content-Type'] = "application/json" req.body = {"auto_compute_estimates":"boolean","billable":"boolean","client_id":"integer","color":"string","completion_mode":"string","custom_fields":{},"description":"string","draft":"boolean","end_date":"string","estimated_mins":"integer","fixed_fee":{"amount":"number","currency":"string"},"is_template":"boolean","name":"string","parent_project_id":"integer","pinned":"boolean","private":"boolean","rollover_mode":"string","rrule":"string","start_date":"string","tag_ids":[{}]}.to_json request.basic_auth '', '' res = http.request(req) puts JSON.parse(res.body) ``` -------------------------------- ### Get Current Trial (Python) Source: https://engineering.toggl.com/docs/focus/api/subscriptions/index.html This Python example uses the requests library to retrieve the current trial information. It sends a GET request with the appropriate content type header and prints the JSON response. ```python import requests from base64 import b64encode data = requests.get('https://focus.toggl.com/api/organizations/{organization_id}/subscriptions/trials/current', headers={'content-type': 'application/json'}) print(data.json()) ``` -------------------------------- ### Create Project Attachment (Rust) Source: https://engineering.toggl.com/docs/focus/api/project-attachments Rust example using reqwest and tokio to create a project attachment. Demonstrates setting headers and handling async requests. ```rust extern crate tokio; extern crate serde_json; use reqwest::{Client}; use reqwest::header::{CONTENT_TYPE}; #[tokio::main] async fn main() -> Result<(), reqwest::Error> { let client = Client::new(); let json = client.request(Method::POST, "https://focus.toggl.com/api/organizations/{organization_id}/workspaces/{workspace_id}/projects/{project_id}/attachments".to_string()) .header(CONTENT_TYPE, "application/json") .send() .await? .json() .await?; println!(!{{:#?}}, json); Ok(()) } ``` -------------------------------- ### Get Public Holidays (JavaScript) Source: https://engineering.toggl.com/docs/focus/api/public-holidays/index.html This JavaScript example uses the `fetch` API to retrieve public holidays. It demonstrates setting the GET method, content type, and authorization header using base64 encoding. ```javascript fetch("https://focus.toggl.com/api/organizations/{organization_id}/public-holidays", { method: "GET", headers: { "Content-Type": "application/json", "Authorization": `Basic ${base64.encode(:)}` }, }) .then((resp) => resp.json()) .then((json) => { console.log(json); }) .catch(err => console.error(err)); ``` -------------------------------- ### Go Request for User Workspace Settings Source: https://engineering.toggl.com/docs/focus/api/user-workspace-settings Demonstrates how to fetch user workspace settings using Go's http package. Includes setting headers and basic authentication. ```go req, err := http.NewRequest(http.MethodGet, "https://focus.toggl.com/api/workspaces/{workspace_id}/users/me/settings") if err != nil { print(err) } req.Header.Set("Content-Type", "application/json; charset=utf-8") req.SetBasicAuth("", "") client := &http.Client{} resp, err := client.Do(req) if err != nil { print(err) } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { print(err) } fmt.Print(string(body)) ``` -------------------------------- ### Get Client by ID using JavaScript (Fetch API) Source: https://engineering.toggl.com/docs/focus/api/clients/index.html This JavaScript example uses the Fetch API to make a GET request for client data. It includes setting headers for content type and authorization. ```javascript fetch("https://focus.toggl.com/api/workspaces/{workspace_id}/clients/{client_id}", { method: "GET", headers: { "Content-Type": "application/json", "Authorization": `Basic ${base64.encode(:)}` }, }) .then((resp) => resp.json()) .then((json) => { console.log(json); }) .catch(err => console.error(err)); ``` -------------------------------- ### List Milestones with Go Source: https://engineering.toggl.com/docs/focus/api/milestones/index.html Example of how to fetch milestones using Go's http package. Handles request creation, authentication, and response reading. ```Go req, err := http.NewRequest(http.MethodGet, "https://focus.toggl.com/api/workspaces/{workspace_id}/milestones") if err != nil { print(err) } req.Header.Set("Content-Type", "application/json; charset=utf-8") req.SetBasicAuth("", "") client := &http.Client{} resp, err := client.Do(req) if err != nil { print(err) } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { print(err) } fmt.Print(string(body)) ``` -------------------------------- ### Get Task with Children Sub-tasks by ID (JavaScript) Source: https://engineering.toggl.com/docs/focus/api/tasks This JavaScript example uses the Fetch API to get a task and its children sub-tasks. It includes setting the 'Content-Type' header and 'Authorization' header with base64 encoded credentials. ```javascript fetch("https://focus.toggl.com/api/organizations/{organization_id}/workspaces/{workspace_id}/tasks/{task_id}/children", { method: "GET", headers: { "Content-Type": "application/json", "Authorization": `Basic ${base64.encode(:)}` }, }) .then((resp) => resp.json()) .then((json) => { console.log(json); }) .catch(err => console.error(err)); ``` -------------------------------- ### POST Composite Tasks - Go Example Source: https://engineering.toggl.com/docs/focus/api/composite/index.html This Go code demonstrates how to construct and send a POST request to the Composite API endpoint. It includes JSON marshaling, setting headers, basic authentication, and handling the response. Ensure you have the necessary imports for `encoding/json`, `fmt`, `io/ioutil`, and `net/http`. ```go bytes, err := json.Marshal('{"subtasks":[{"assignee_user_ids":[{}],"auto_log_time":"boolean","billable":"boolean","color":"string","custom_fields":{},"description":"string","end_date":"string","estimated_mins":"integer","ghost_assignee_ids":[{}],"integration_ext_id":"integer","integration_source":"string","name":"string","notes":"string","pinned":"boolean","position":"integer","priority":"string","priority_at":"string","private":"boolean","project_id":"integer","rrule":"string","start_date":"string","status_id":"integer","tag_ids":[{}],"team_assignee_ids":[{}]}],"task":{"assignee_user_ids":[{}],"auto_log_time":"boolean","billable":"boolean","color":"string","custom_fields":{},"description":"string","end_date":"string","estimated_mins":"integer","ghost_assignee_ids":[{}],"integration_ext_id":"integer","integration_source":"string","name":"string","notes":"string","parent_task_id":"integer","pinned":"boolean","position":"integer","priority":"string","priority_at":"string","private":"boolean","project_id":"integer","recurring_task_id":"integer","rrule":"string","start_date":"string","status_id":"integer","tag_ids":[{}],"team_assignee_ids":[{}]}},"time_blocks":[{"completed":"boolean","duration":"integer","outbound_sync":"boolean","start":"string"}],"time_entry":{"calendar_event_id":"integer","description":"string","duration":"integer","planned_at":"string","planned_duration":"integer","planned_start":"string","start":"string","time_block":{"completed":"boolean","duration":"integer","outbound_sync":"boolean","start":"string"},"time_block_id":"integer","tracked_at":"string","type":{}}}') if err != nil { print(err) } req, err := http.NewRequest(http.MethodPost, "https://focus.toggl.com/api/workspaces/{workspace_id}/composite/tasks", bytes.NewBuffer(bytes)) if err != nil { print(err) } req.Header.Set("Content-Type", "application/json; charset=utf-8") req.SetBasicAuth("", "") client := &http.Client{} resp, err := client.Do(req) if err != nil { print(err) } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { print(err) } fmt.Print(string(body)) ``` -------------------------------- ### Start Tracking Time Entry with JavaScript (Fetch API) Source: https://engineering.toggl.com/docs/focus/api/tracking This JavaScript example uses the Fetch API to start a time entry. It demonstrates setting the request method, body, headers, and handling the JSON response. ```javascript fetch("https://focus.toggl.com/api/organizations/{organization_id}/workspaces/{workspace_id}/tracking/start", { method: "POST", body: {"billable":"boolean","calendar_event_id":"integer","description":"string","project_id":"integer","start":"string","task_id":"integer","time_block_id":"integer","type":"string"}, headers: { "Content-Type": "application/json", "Authorization": `Basic ${base64.encode(:)}` }, }) .then((resp) => resp.json()) .then((json) => { console.log(json); }) .catch(err => console.error(err)); ``` -------------------------------- ### Get List Task Time Blocks (JavaScript) Source: https://engineering.toggl.com/docs/focus/api/time-blocks JavaScript example using the Fetch API to get time blocks. Demonstrates setting headers, including Authorization with base64 encoded credentials, and handling JSON responses. ```javascript fetch("https://focus.toggl.com/api/organizations/{organization_id}/workspaces/{workspace_id}/time-blocks", { method: "GET", headers: { "Content-Type": "application/json", "Authorization": `Basic ${base64.encode(:)}` }, }) .then((resp) => resp.json()) .then((json) => { console.log(json); }) .catch(err => console.error(err)); ```