### Go example Source: https://tsheetsteam.github.io/api_docs Go example using net/http to send a GET request with an Authorization header. ```go package main import ( "fmt" "net/http" "io/ioutil" ) func main() { url := "https://rest.tsheets.com/api/v1/customfielditems?customfield_id=195923" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("Authorization", "Bearer ") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := ioutil.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` -------------------------------- ### Go Example for Custom Field Items Source: https://tsheetsteam.github.io/api_docs Go example using net/http to send a GET request to the customfielditems endpoint. Standard library only. ```go package main import ( "fmt" "net/http" "io/ioutil" ) func main() { url := "https://rest.tsheets.com/api/v1/customfielditems?customfield_id=195923&ids=3875655,3875657" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("Authorization", "Bearer ") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := ioutil.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` -------------------------------- ### Java OkHttp example Source: https://tsheetsteam.github.io/api_docs Java example using OkHttp to send a GET request to the customfielditems endpoint. ```java OkHttpClient client = new OkHttpClient(); Request request = new Request.Builder() .url("https://rest.tsheets.com/api/v1/customfielditems?customfield_id=195923") .get() .addHeader("Authorization", "Bearer ") .build(); Response response = client.newCall(request).execute(); ``` -------------------------------- ### Python requests example Source: https://tsheetsteam.github.io/api_docs Python example using the requests library to send a GET request with query parameters and Authorization header. ```python import requests url = "https://rest.tsheets.com/api/v1/customfielditems" querystring = { "customfield_id":"195923", } payload = "" headers = { 'Authorization': "Bearer ", } response = requests.request("GET", url, data=payload, headers=headers, params=querystring) print(response.text) ``` -------------------------------- ### Go Example for Jobcode Assignments Source: https://tsheetsteam.github.io/api_docs Go example using net/http to make a GET request to the jobcode_assignments endpoint. Replace with your API token. ```go package main import ( "fmt" "net/http" "io/ioutil" ) func main() { url := "https://rest.tsheets.com/api/v1/jobcode_assignments?user_ids=1242515" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("Authorization", "Bearer ") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := ioutil.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` -------------------------------- ### Example: Retrieve deleted timesheets in Go Source: https://tsheetsteam.github.io/api_docs Go example using net/http to make a GET request to the timesheets_deleted endpoint with an Authorization header. ```go package main import ( "fmt" "net/http" "io/ioutil" ) func main() { url := "https://rest.tsheets.com/api/v1/timesheets_deleted?ids=136022048" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("Authorization", "Bearer ") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := ioutil.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` -------------------------------- ### Swift URLSession example Source: https://tsheetsteam.github.io/api_docs Swift example using URLSession to send a GET request with an Authorization header. ```swift import Foundation let headers = [ "Authorization": "Bearer ", ] let request = NSMutableURLRequest( url: NSURL(string: "https://rest.tsheets.com/api/v1/customfielditems?customfield_id=195923")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "GET" request.allHTTPHeaderFields = headers let session = URLSession.shared let dataTask = session.dataTask( with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } } ) dataTask.resume() ``` -------------------------------- ### Node.js request module example Source: https://tsheetsteam.github.io/api_docs Node.js example using the request module to send a GET request with query parameters and Authorization header. ```javascript var request = require("request"); var options = { method: 'GET', url: 'https://rest.tsheets.com/api/v1/customfielditems', qs: { customfield_id: '195923', }, headers: { 'Authorization': 'Bearer ', } }; request(options, function (error, response, body) { if (error) throw new Error(error); console.log(body); }); ``` -------------------------------- ### Java OkHttpClient Example for Custom Field Items Source: https://tsheetsteam.github.io/api_docs Java example using OkHttpClient to send a GET request to the customfielditems endpoint. Requires OkHttp library. ```java OkHttpClient client = new OkHttpClient(); Request request = new Request.Builder() .url("https://rest.tsheets.com/api/v1/customfielditems?customfield_id=195923&ids=3875655,3875657") .get() .addHeader("Authorization", "Bearer ") .build(); Response response = client.newCall(request).execute(); ``` -------------------------------- ### Java OkHttpClient Example for Jobcode Assignments Source: https://tsheetsteam.github.io/api_docs Java example using OkHttpClient to make a GET request to the jobcode_assignments endpoint. Replace with your API token. ```java OkHttpClient client = new OkHttpClient(); Request request = new Request.Builder() .url("https://rest.tsheets.com/api/v1/jobcode_assignments?user_ids=1242515") .get() .addHeader("Authorization", "Bearer ") .build(); Response response = client.newCall(request).execute(); ``` -------------------------------- ### Swift URLSession Example for Custom Field Items Source: https://tsheetsteam.github.io/api_docs Swift example using URLSession to send a GET request to the customfielditems endpoint. Requires Foundation framework. ```swift import Foundation let headers = [ "Authorization": "Bearer ", ] let request = NSMutableURLRequest( url: NSURL(string: "https://rest.tsheets.com/api/v1/customfielditems?customfield_id=195923&ids=3875655,3875657")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "GET" request.allHTTPHeaderFields = headers let session = URLSession.shared let dataTask = session.dataTask( with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } } ) dataTask.resume() ``` -------------------------------- ### Retrieve Notifications with Go Source: https://tsheetsteam.github.io/api_docs Go example using net/http to make a GET request to the notifications endpoint. ```go package main import ( "fmt" "net/http" "io/ioutil" ) func main() { url := "https://rest.tsheets.com/api/v1/notifications?user_id=1242515" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("Authorization", "Bearer ") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := ioutil.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` -------------------------------- ### Go Example for Updating Project Activity Read Time Source: https://tsheetsteam.github.io/api_docs Uses net/http to send a POST request with headers and body. ```go package main import ( "fmt" "strings" "net/http" "io/ioutil" ) func main() { url := "https://rest.tsheets.com/api/v1/project_activity_read_times" payload := strings.NewReader("") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("Authorization", "Bearer ") req.Header.Add("Content-Type", "application/json") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := ioutil.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` -------------------------------- ### Go example for project notes Source: https://tsheetsteam.github.io/api_docs Uses Go's net/http to send a GET request to the project_notes endpoint with the required query parameters and Authorization header. ```go package main import ( "fmt" "net/http" "io/ioutil" ) func main() { url := "https://rest.tsheets.com/api/v1/project_notes?ids=12,367,3489&project_id=1234" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("Authorization", "Bearer ") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := ioutil.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` -------------------------------- ### Go POST Request to Create Project Notes Source: https://tsheetsteam.github.io/api_docs Go example using net/http to POST to the project_notes endpoint. Replace and as needed. ```go package main import ( "fmt" "strings" "net/http" "io/ioutil" ) func main() { url := "https://rest.tsheets.com/api/v1/project_notes" payload := strings.NewReader("") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("Authorization", "Bearer ") req.Header.Add("Content-Type", "application/json") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := ioutil.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` -------------------------------- ### VB.NET RestClient example Source: https://tsheetsteam.github.io/api_docs VB.NET example using RestSharp to send a GET request to the customfielditems endpoint. ```vbnet Dim client = New RestClient("https://rest.tsheets.com/api/v1/customfielditems?customfield_id=195923") Dim request = New RestRequest(Method.[GET]) request.AddHeader("Authorization", "Bearer ") Dim response As IRestResponse = client.Execute(request) ``` -------------------------------- ### Perl REST::Client example Source: https://tsheetsteam.github.io/api_docs Perl example using REST::Client to send a GET request with an Authorization header. ```perl use REST::Client; my $client = REST::Client->new(); $client->addHeader('Authorization', 'Bearer '); $url="https://rest.tsheets.com/api/v1/customfielditems?customfield_id=195923"; $client->GET($url); print $client->responseContent(); print $client->responseHeader('ResponseHeader'); ``` -------------------------------- ### Create Estimates with Go (net/http) Source: https://tsheetsteam.github.io/api_docs Go example using net/http to POST to the projects endpoint. ```go package main import ( "fmt" "strings" "net/http" "io/ioutil" ) func main() { url := "https://rest.tsheets.com/api/v1/projects" payload := strings.NewReader("") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("Authorization", "Bearer ") req.Header.Add("Content-Type", "application/json") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := ioutil.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` -------------------------------- ### Create Groups - Go Source: https://tsheetsteam.github.io/api_docs Go example using net/http to POST to the groups endpoint. ```go package main import ( "fmt" "strings" "net/http" "io/ioutil" ) func main() { url := "https://rest.tsheets.com/api/v1/groups" payload := strings.NewReader("") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("Authorization", "Bearer ") req.Header.Add("Content-Type", "application/json") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := ioutil.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` -------------------------------- ### Go HTTP POST Example Source: https://tsheetsteam.github.io/api_docs Go example using net/http to POST to the jobcode_assignments endpoint. Uses ioutil to read the response body. ```go package main import ( "fmt" "strings" "net/http" "io/ioutil" ) func main() { url := "https://rest.tsheets.com/api/v1/jobcode_assignments" payload := strings.NewReader("") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("Authorization", "Bearer ") req.Header.Add("Content-Type", "application/json") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := ioutil.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` -------------------------------- ### PHP HttpRequest example Source: https://tsheetsteam.github.io/api_docs PHP example using the HttpRequest class to send a GET request with query data and Authorization header. ```php setUrl('https://rest.tsheets.com/api/v1/customfielditems'); $request->setMethod(HTTP_METH_GET); $request->setQueryData(array( 'customfield_id' => '195923', )); $request->setHeaders(array( 'Authorization' => 'Bearer ', )); try { $response = $request->send(); echo $response->getBody(); } catch (HttpException $ex) { echo $ex; } ``` -------------------------------- ### C# RestClient example Source: https://tsheetsteam.github.io/api_docs C# example using RestSharp to send a GET request to the customfielditems endpoint. Requires RestSharp library. ```csharp var client = new RestClient("https://rest.tsheets.com/api/v1/customfielditems?customfield_id=195923"); var request = new RestRequest(Method.GET); request.AddHeader("Authorization", "Bearer "); IRestResponse response = client.Execute(request); ``` -------------------------------- ### Go Request to Create Project Activity Replies Source: https://tsheetsteam.github.io/api_docs Uses net/http to send a POST request. Sets headers and body, and prints the response. ```go package main import ( "fmt" "strings" "net/http" "io/ioutil" ) func main() { url := "https://rest.tsheets.com/api/v1/project_activity_replies" payload := strings.NewReader("") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("Authorization", "Bearer ") req.Header.Add("Content-Type", "application/json") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := ioutil.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` -------------------------------- ### Java OkHttp example for project notes Source: https://tsheetsteam.github.io/api_docs Uses OkHttpClient to send a GET request to the project_notes endpoint with the required query parameters and Authorization header. ```java OkHttpClient client = new OkHttpClient(); Request request = new Request.Builder() .url("https://rest.tsheets.com/api/v1/project_notes?ids=12,367,3489&project_id=1234") .get() .addHeader("Authorization", "Bearer ") .build(); Response response = client.newCall(request).execute(); ``` -------------------------------- ### Create Estimates with Java (OkHttp) Source: https://tsheetsteam.github.io/api_docs Java example using OkHttp to POST to the projects endpoint. Requires OkHttp library. ```java OkHttpClient client = new OkHttpClient(); MediaType mediaType = MediaType.parse("application/json"); RequestBody body = RequestBody.create(mediaType, ""); Request request = new Request.Builder() .url("https://rest.tsheets.com/api/v1/projects") .post(body) .addHeader("Authorization", "Bearer ") .addHeader("Content-Type", "application/json") .build(); Response response = client.newCall(request).execute(); ``` -------------------------------- ### GET /api/v1/timesheets Source: https://tsheetsteam.github.io/api_docs Retrieves timesheets from the TSheets REST API. The example shows how to get page 3 of timesheets for a specific user within a date range, using the GET method and query parameters. ```APIDOC ## [GET] /api/v1/timesheets ### Description Retrieves a list of timesheets. The example demonstrates retrieving page 3 of timesheets linked to a specific user within a given time range. ### Method GET ### Endpoint https://rest.tsheets.com/api/v1/timesheets ### Parameters #### Query Parameters - **page** (integer) - Optional - The page number of results to retrieve. Example: 3. - **user_ids** (integer) - Optional - The ID of the user whose timesheets to retrieve. Example: 1123. - **start_date** (string) - Optional - The start date of the time range in YYYY-MM-DD format. Example: 2018-01-01. - **end_date** (string) - Optional - The end date of the time range in YYYY-MM-DD format. Example: 2018-02-01. ### Request Example ``` curl "https://rest.tsheets.com/api/v1/timesheets?page=3&user_ids=1123&start_date=2018-01-01&end_date=2018-02-01" \ -H "Authorization: Bearer " ``` ### Authentication Requires an authorization token. Include the header `Authorization: Bearer `. ### Response Returns a list of timesheets matching the specified filters. The response content is not shown in the source, but the request returns the timesheet data for the given user and date range. ``` -------------------------------- ### Example: Retrieve deleted timesheets in Swift (URLSession) Source: https://tsheetsteam.github.io/api_docs Swift example using URLSession to make a GET request to the timesheets_deleted endpoint with an Authorization header. ```swift import Foundation let headers = [ "Authorization": "Bearer ", ] let request = NSMutableURLRequest( url: NSURL(string: "https://rest.tsheets.com/api/v1/timesheets_deleted?ids=136022048")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "GET" request.allHTTPHeaderFields = headers let session = URLSession.shared let dataTask = session.dataTask( with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } } ) dataTask.resume() ``` -------------------------------- ### Go net/http request to retrieve project activities Source: https://tsheetsteam.github.io/api_docs Use this Go example with net/http to make a GET request to the project_activities endpoint. Replace with your authorization token. ```go package main import ( "fmt" "net/http" "io/ioutil" ) func main() { url := "https://rest.tsheets.com/api/v1/project_activities?project_id=1234&activity_types=clock_in,clock_out" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("Authorization", "Bearer ") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := ioutil.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` -------------------------------- ### Create Project Request Body Example Source: https://tsheetsteam.github.io/api_docs Example request body for creating a new project with an existing jobcode, specifying jobcode_id, description, start_date, and due_date. ```json { "data": [{ "jobcode_id": 6386831, "description": "This is the project to track all party prep.", "start_date": "2019-11-05T00:00:00+00:00", "due_date": "2019-12-15T00:00:00+00:00" }] } ``` -------------------------------- ### Example: Retrieve deleted timesheets in Java (OkHttp) Source: https://tsheetsteam.github.io/api_docs Java example using OkHttpClient to make a GET request to the timesheets_deleted endpoint with an Authorization header. ```java OkHttpClient client = new OkHttpClient(); Request request = new Request.Builder() .url("https://rest.tsheets.com/api/v1/timesheets_deleted?ids=136022048") .get() .addHeader("Authorization", "Bearer ") .build(); Response response = client.newCall(request).execute(); ``` -------------------------------- ### Create Invitations - Go (net/http) Source: https://tsheetsteam.github.io/api_docs Uses the standard net/http package to POST to the invitations endpoint. Replace and as needed. ```go package main import ( "fmt" "strings" "net/http" "io/ioutil" ) func main() { url := "https://rest.tsheets.com/api/v1/invitations" payload := strings.NewReader("") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("Authorization", "Bearer ") req.Header.Add("Content-Type", "application/json") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := ioutil.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` -------------------------------- ### Example: Retrieve deleted timesheets in VB.NET (RestClient) Source: https://tsheetsteam.github.io/api_docs VB.NET example using RestClient to make a GET request to the timesheets_deleted endpoint with an Authorization header. ```vbnet Dim client = New RestClient("https://rest.tsheets.com/api/v1/timesheets_deleted?ids=136022048") Dim request = New RestRequest(Method.[GET]) request.AddHeader("Authorization", "Bearer ") Dim response As IRestResponse = client.Execute(request) ``` -------------------------------- ### Create Groups - Java (OkHttp) Source: https://tsheetsteam.github.io/api_docs Java example using OkHttp to POST to the groups endpoint. Requires OkHttp library. ```java OkHttpClient client = new OkHttpClient(); MediaType mediaType = MediaType.parse("application/json"); RequestBody body = RequestBody.create(mediaType, ""); Request request = new Request.Builder() .url("https://rest.tsheets.com/api/v1/groups") .post(body) .addHeader("Authorization", "Bearer ") .addHeader("Content-Type", "application/json") .build(); Response response = client.newCall(request).execute(); ``` -------------------------------- ### Example: Retrieve deleted timesheets in C# (RestClient) Source: https://tsheetsteam.github.io/api_docs C# example using RestClient to make a GET request to the timesheets_deleted endpoint with an Authorization header. ```csharp var client = new RestClient("https://rest.tsheets.com/api/v1/timesheets_deleted?ids=136022048"); var request = new RestRequest(Method.GET); request.AddHeader("Authorization", "Bearer "); IRestResponse response = client.Execute(request); ``` -------------------------------- ### Create Estimates with Swift (URLSession) Source: https://tsheetsteam.github.io/api_docs Swift example using URLSession to POST to the projects endpoint. Requires Foundation framework. ```swift import Foundation let headers = [ "Authorization": "Bearer ", "Content-Type": "application/json", ] let parameters = as [String : Any] let postData = JSONSerialization.data(withJSONObject: parameters, options: []) let request = NSMutableURLRequest( url: NSURL(string: "https://rest.tsheets.com/api/v1/projects")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "POST" request.allHTTPHeaderFields = headers request.httpBody = postData as Data let session = URLSession.shared let dataTask = session.dataTask( with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } } ) dataTask.resume() ``` -------------------------------- ### Response Format: 200 OK for Create Project Activity Reply Source: https://tsheetsteam.github.io/api_docs Example JSON response for a successful create operation. Shows the created reply objects and supplemental data including user and project activity details. ```json { "results": { "project_activity_replies": { "1": { "_status_code": 200, "_status_message": "Created", "id": 10001, "project_activity_id": 40001, "user_id": 20001, "note": "note 1", "active": true, "created": "2019-12-12T22:34:04+00:00", "last_modified": "2019-12-12T22:34:04+00:00", "mentions": [], "linked_objects": { "project_activities": [ 40001 ] } }, "2": { "_status_code": 200, "_status_message": "Created", "id": 10002, "project_activity_id": 4001, "user_id": 20001, "note": "note 2", "active": true, "created": "2019-12-12T22:34:04+00:00", "last_modified": "2019-12-12T22:34:04+00:00", "mentions": [], "linked_objects": { "project_activities": [ 40002 ] } }, } }, "supplemental_data": { "users": { "20001": { "id": 20001, "first_name": "Test", "last_name": "User", "display_name": "", "group_id": 0, "active": true, "employee_number": 0, "salaried": false, "exempt": false, "username": "test@user.com", "email": "test@user.com", "email_verified": false, "payroll_id": "", "hire_date": "0000-00-00", "term_date": "0000-00-00", "last_modified": "2022-02-23T22:59:17+00:00", "last_active": "2022-05-09T21:36:43+00:00", "created": "2021-11-01T19:27:25+00:00", "client_url": "your-company-url", "company_name": "Your Company", "profile_image_url": "https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61", "pronouns": "", "mobile_number": "", "pto_balances": { "701818256": 0, "701818258": 0, "701818260": 0 }, "submitted_to": "2000-01-01", "approved_to": "2000-01-01", "manager_of_group_ids": [], "require_password_change": false, "pay_rate": 1, "pay_interval": "year", "permissions": { "admin": true, "mobile": true, "status_box": true, "reports": true, "manage_timesheets": true, "manage_authorization": true, "manage_users": true, "manage_my_timesheets": true, "manage_jobcodes": true, "pin_login": true, "approve_timesheets": true, "manage_schedules": false, "external_access": false, "manage_my_schedule": false, "manage_company_schedules": false, "view_company_schedules": false, "view_group_schedules": false, "manage_no_schedules": false, "view_my_schedules": false, "view_projects": false, "manage_projects": true, "time_tracking": true }, "customfields": "" } }, "project_activities": { "40001": { "id": 40001, "user_id": 20001, "project_id": 30001, "activity_type": "note", "active": true, "created": "2019-12-06T22:57:34+00:00", "last_modified": "2019-12-06T22:57:34+00:00", "unread_replies_count": 0, "following": false, "project_activity_metadata": [ ], "linked_objects": { "project_activity_replies": [ 10001 ] } } } } } ``` -------------------------------- ### Swift URLSession Example for Jobcode Assignments Source: https://tsheetsteam.github.io/api_docs Swift example using URLSession to make a GET request to the jobcode_assignments endpoint. Replace with your API token. ```swift import Foundation let headers = [ "Authorization": "Bearer ", ] let request = NSMutableURLRequest( url: NSURL(string: "https://rest.tsheets.com/api/v1/jobcode_assignments?user_ids=1242515")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "GET" request.allHTTPHeaderFields = headers let session = URLSession.shared let dataTask = session.dataTask( with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } } ) dataTask.resume() ``` -------------------------------- ### Retrieve Project Notes with Go Source: https://tsheetsteam.github.io/api_docs Go example using net/http to send a GET request to the project_notes endpoint with the project_id query parameter and Bearer token. ```go package main import ( "fmt" "net/http" "io/ioutil" ) func main() { url := "https://rest.tsheets.com/api/v1/project_notes?project_id=1234" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("Authorization", "Bearer ") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := ioutil.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` -------------------------------- ### PHP HttpRequest Example for Jobcode Assignments Source: https://tsheetsteam.github.io/api_docs PHP example using HttpRequest to make a GET request to the jobcode_assignments endpoint. Replace with your API token. ```php setUrl('https://rest.tsheets.com/api/v1/jobcode_assignments'); $request->setMethod(HTTP_METH_GET); $request->setQueryData(array( 'user_ids' => '1242515', )); $request->setHeaders(array( 'Authorization' => 'Bearer ', )); try { $response = $request->send(); echo $response->getBody(); } catch (HttpException $ex) { echo $ex; } ``` -------------------------------- ### Java OkHttp POST Request to Create Project Notes Source: https://tsheetsteam.github.io/api_docs Java example using OkHttpClient to POST to the project_notes endpoint. Replace and as needed. ```java OkHttpClient client = new OkHttpClient(); MediaType mediaType = MediaType.parse("application/json"); RequestBody body = RequestBody.create(mediaType, ""); Request request = new Request.Builder() .url("https://rest.tsheets.com/api/v1/project_notes") .post(body) .addHeader("Authorization", "Bearer ") .addHeader("Content-Type", "application/json") .build(); Response response = client.newCall(request).execute(); ``` -------------------------------- ### Sample 200 OK response for updating project activity read times Source: https://tsheetsteam.github.io/api_docs Example response showing successfully created project_activity_read_times with status codes and supplemental user and project data. ```json { "results": { "project_activity_read_times": { "1": { "_status_code": 200, "_status_message": "Created", "id": 10001, "user_id": 20001, "project_id": 30001, "latest_read_time": "2020-01-01T00:00:00+00:00" }, "2": { "_status_code": 200, "_status_message": "Created", "id": 10002, "user_id": 20001, "project_id": 30002, "latest_read_time": "2020-01-05T00:00:00+00:00" }, } }, "supplemental_data": { "users": { "20001": { "id": 20001, "first_name": "Test", "last_name": "User", "active": true, "username": "test@user.com", "email": "test@user.com", "client_url": "your-company-url", "company_name": "Your Company" } }, "projects": { "30001": { "id": 30001, "jobcode_id": 50001, "parent_jobcode_id": 0, "name": "Test Project", "status": "in_progress", "description": "Test Project for Docs", "start_date": "", "due_date": "", "completed_date": "", "active": true, "last_modified": "2019-11-21T18:42:06+00:00", "created": "2019-11-21T18:42:06+00:00", "linked_objects": { "notes_read_times": [ 159834 ] } }, { "id": 30002, "jobcode_id": 50002, "parent_jobcode_id": 1023134674, "name": "Test Project 2", "status": "in_progress", "description": "Test Project 2 for Docs", "start_date": "", "due_date": "", "completed_date": "", "active": true, "last_modified": "2019-11-21T18:42:06+00:00", "created": "2019-11-21T18:42:06+00:00", "linked_objects": { "notes_read_times": [ 160538 ] } } } } } ``` -------------------------------- ### VB.NET RestClient Example for Custom Field Items Source: https://tsheetsteam.github.io/api_docs VB.NET example using RestClient to send a GET request to the customfielditems endpoint. Requires RestSharp library. ```vbnet Dim client = New RestClient("https://rest.tsheets.com/api/v1/customfielditems?customfield_id=195923&ids=3875655,3875657") Dim request = New RestRequest(Method.[GET]) request.AddHeader("Authorization", "Bearer ") Dim response As IRestResponse = client.Execute(request) ``` -------------------------------- ### C# RestClient Example for Custom Field Items Source: https://tsheetsteam.github.io/api_docs C# example using RestClient to send a GET request to the customfielditems endpoint. Requires RestSharp library. ```csharp var client = new RestClient("https://rest.tsheets.com/api/v1/customfielditems?customfield_id=195923&ids=3875655,3875657"); var request = new RestRequest(Method.GET); request.AddHeader("Authorization", "Bearer "); IRestResponse response = client.Execute(request); ``` -------------------------------- ### Go POST Request Source: https://tsheetsteam.github.io/api_docs Go example using net/http to POST to the customfields endpoint. ```go package main import ( "fmt" "strings" "net/http" "io/ioutil" ) func main() { url := "https://rest.tsheets.com/api/v1/customfields" payload := strings.NewReader("") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("Authorization", "Bearer ") req.Header.Add("Content-Type", "application/json") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := ioutil.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` -------------------------------- ### Example: Retrieve deleted timesheets in Perl (REST::Client) Source: https://tsheetsteam.github.io/api_docs Perl example using REST::Client to make a GET request to the timesheets_deleted endpoint with an Authorization header. ```perl use REST::Client; my $client = REST::Client->new(); $client->addHeader('Authorization', 'Bearer '); $url="https://rest.tsheets.com/api/v1/timesheets_deleted?ids=136022048"; $client->GET($url); print $client->responseContent(); print $client->responseHeader('ResponseHeader'); ``` -------------------------------- ### Retrieve Project Activity Read Times - Go Source: https://tsheetsteam.github.io/api_docs Go example using net/http to send a GET request. Requires a valid Bearer token. ```go package main import ( "fmt" "net/http" "io/ioutil" ) func main() { url := "https://rest.tsheets.com/api/v1/project_activity_read_times" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("Authorization", "Bearer ") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := ioutil.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` -------------------------------- ### Example: Retrieve deleted timesheets in Ruby (Net::HTTP) Source: https://tsheetsteam.github.io/api_docs Ruby example using Net::HTTP to make a GET request to the timesheets_deleted endpoint with an Authorization header. ```ruby require 'uri' require 'net/http' url = URI("https://rest.tsheets.com/api/v1/timesheets_deleted?ids=136022048") http = Net::HTTP.new(url.host, url.port) request = Net::HTTP::Get.new(url) request["Authorization"] = 'Bearer ', response = http.request(request) puts response.read_body ``` -------------------------------- ### Go net/http POST to Create Jobcodes Source: https://tsheetsteam.github.io/api_docs Go example using net/http to POST to the jobcodes endpoint. Replace and as needed. ```go package main import ( "fmt" "strings" "net/http" "io/ioutil" ) func main() { url := "https://rest.tsheets.com/api/v1/jobcodes" payload := strings.NewReader("") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("Authorization", "Bearer ") req.Header.Add("Content-Type", "application/json") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := ioutil.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` -------------------------------- ### Create Project Notes Response Format Source: https://tsheetsteam.github.io/api_docs Example JSON response for a successful project note creation, showing the results object with created notes and supplemental data including users, projects, and project activities. ```json { "results": { "project_notes": { "1": { "_status_code": 200, "_status_message": "Created", "id": 10001, "project_id": 30001, "user_id": 20001, "note": "note 1", "active": true, "created": "2019-12-12T22:34:04+00:00", "last_modified": "2019-12-12T22:34:04+00:00", "mentions": [], "files": [60001, 60002, 60003], "linked_objects": { "project_activities": [ 40001 ] } }, "2": { "_status_code": 200, "_status_message": "Created", "id": 10002, "project_id": 2992757, "user_id": 20001, "note": "note 2", "active": true, "created": "2019-12-12T22:34:04+00:00", "last_modified": "2019-12-12T22:34:04+00:00", "mentions": [], "files": [60011, 60012, 60013], "linked_objects": { "project_activities": [ 40002 ] } }, } }, "supplemental_data": { "users": { "20001": { "id": 20001, "first_name": "Test", "last_name": "User", "display_name": "", "group_id": 0, "active": true, "employee_number": 0, "salaried": false, "exempt": false, "username": "test@user.com", "email": "test@user.com", "email_verified": false, "payroll_id": "", "hire_date": "0000-00-00", "term_date": "0000-00-00", "last_modified": "2022-02-23T22:59:17+00:00", "last_active": "2022-05-09T21:36:43+00:00", "created": "2021-11-01T19:27:25+00:00", "client_url": "your-company-url", "company_name": "Your Company", "profile_image_url": "https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61", "pronouns": "", "mobile_number": "", "pto_balances": { "701818256": 0, "701818258": 0, "701818260": 0 }, "submitted_to": "2000-01-01", "approved_to": "2000-01-01", "manager_of_group_ids": [], "require_password_change": false, "pay_rate": 1, "pay_interval": "year", "permissions": { "admin": true, "mobile": true, "status_box": true, "reports": true, "manage_timesheets": true, "manage_authorization": true, "manage_users": true, "manage_my_timesheets": true, "manage_jobcodes": true, "pin_login": true, "approve_timesheets": true, "manage_schedules": false, "external_access": false, "manage_my_schedule": false, "manage_company_schedules": false, "view_company_schedules": false, "view_group_schedules": false, "manage_no_schedules": false, "view_my_schedules": false, "view_projects": false, "manage_projects": true, "time_tracking": true }, "customfields": "" } }, "projects": { "30001": { "id": 30001, "jobcode_id": 50001, "parent_jobcode_id": 0, "name": "Test Project", "status": "in_progress", "description": "Test Project for Docs", "start_date": "", "due_date": "", "completed_date": "", "active": true, "last_modified": "2019-11-21T18:42:06+00:00", "created": "2019-11-21T18:42:06+00:00", "linked_objects": { "notes_read_times": [ 159834 ] } } }, "project_activities": { "40001": { "id": 40001, "user_id": 20001, "project_id": 30001, "activity_type": "note", "active": true, "created": "2019-12-06T22:57:34+00:00", "last_modified": "2019-12-06T22:57:34+00:00", "unread_replies_count": 0, "following": false, "project_activity_metadata": [ ], "linked_objects": { "project_notes": [ 10001 ] } }, "40002": { "id": 40002, "user_id": 20001, "project_id": 30001, "activity_type": "note", "active": true, "created": "2019-12-09T17:14:22+00:00", "last_modified": "2019-12-09T17:14:22+00:00", "project_activity_metadata": [ ], "linked_objects": { "project_notes": [ 10002 ] } } } } } ```