Objective
I want to make button presses start/stop Toggl timers (time-tracking).
Bash equivalent
This is the curl I want to use in groovy:
curl -v -u <toggl api token>:api_token \
-H "Content-Type: application/json" \
-d '{"time_entry":{"description":"This is a test time entry","created_with":"curl"}}' \
-X POST https://api.track.toggl.com/api/v8/time_entries/start
Code
Using httpPostJson() documentation, I’ve implemented it like so inside an event handler that reliably gets called:
def params = [
"uri": "https://api.track.toggl.com/api/v8/time_entries/start",
"body": [
"data": [
"{\"time_entry\":{\"description\":\"Test timer event\",\"created_with\":\"curl\"}}": ""
],
"auth": [
"user": "<toggl API token>",
"password": "api_token"
]
]
]
def content = ""
try {
httpPostJson(params) { resp ->
resp.headers.each {
log.debug "${it.name} : ${it.value}"
}
log.debug "response contentType: ${resp.contentType}"
log.debug "response data: ${resp.data}"
content = "${resp.data}"
}
} catch (e) {
content = "something went wrong: $e"
}
sendPush("EVENT:${evt.value}\n${content}")
Error
The error I get is javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
.
Question
Is this a problem with the code I have? Is it possible to POST with API token authentication from the groovy IDE or should I use the Java/Javascript SDK instead?