Hi I'm trying to use the toggl API to get reports as csv files. However I cannot seem to figure out how to make the get request right using all the parameters. I found a great Python script for it (https://baxeico.wordpress.com/2014/03/13/build-excel-timesheet-toggl-api-python/) but am unfortunately not able to translate it into Java. Help would be greatly appreciated. I seem to have a problem with the api_token. Since I always receive error 401 saying that the api_token is missing. Here the beginning of my code with adapted user details ;)
public class HttpURLConnectionExample {
private final String USER_AGENT = "Mozilla/5.0";
String workspaceId = "123456";
String apiToken = "qrstuvwxyz123456789";
public static void main(String[] args) throws Exception {
HttpURLConnectionExample http = new HttpURLConnectionExample();
System.out.println("Testing 1 - Send Http GET request");
http.sendGet();
}
// HTTP GET request
private void sendGet() throws Exception {
String url = "https://www.toggl.com/reports/api/v2/summary?user_agent='username'";
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
// optional default is GET
con.setRequestMethod("GET");
//add request header
//con.setRequestProperty("User-Agent", userAgent);
// that's where I'd like to add the workspace ID and my API token
con.setRequestProperty("api_token", apiToken);
con.setRequestProperty("workspace_id", workspaceId);
int responseCode = con.getResponseCode();
System.out.println("\nSending 'GET' request to URL : " + url);
System.out.println("Response Code : " + responseCode);
[...]