infeeeee / kimai2-cmd

Command line client for Kimai2, the open source, self-hosted time tracker
MIT License
26 stars 6 forks source link

Starting a project only works with ui #24

Closed GordianDziwis closed 3 years ago

GordianDziwis commented 3 years ago
kimai2-cmd start "Foo" "Bar" -v -i

Results in

Found in KIMAI_CONFIG envvar: /home/beavis/.config/kimai2/settings.ini
settings.ini found at: /home/beavis/.config/kimai2/settings.ini
---
calling kimai:  GET projects [object Object]
request options: [object Object]
Response body: [object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
---
calling kimai:  GET activities [object Object]
request options: [object Object]
Response body: [object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
---
calling kimai:  GET config/i18n [object Object]
request options: [object Object]
kimaistart calling api: [object Object]
---
calling kimai:  POST timesheets [object Object]
request options: [object Object]
Response body: [object Object]
Server error message:
400
Validation Failed
(node:488024) UnhandledPromiseRejectionWarning: Validation Failed
(Use `node --trace-warnings ...` to show where the warning was created)
(node:488024) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:488024) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Response body: [object Object]
servertime: 2021-11-22T15:36:47+0100
localtime: 2021-11-22T15:36:47+01:00
infeeeee commented 3 years ago

I can't reproduce this. Error 400 means, something is malformed in the request to kimai.

How did you installed kimai2-cmd?

If you installed it with npm you can change t manually. In this line: https://github.com/infeeeee/kimai2-cmd/blob/ca8c54da0004f5b367712b64b1472696d69fca36/kimai2-cmd.js#L77 add .body behind options, so it should look like this:

debug("request options: " + options.body)

If you installed a prebuilt, I just created a new build with this extra debugging: https://github.com/infeeeee/kimai2-cmd/releases/tag/1.3.1

Post the output of the same command with this new version

GordianDziwis commented 3 years ago

This helped, the issue is that all my activities have the same name Work. Kimai2-cmd queries by name for the activity id and if there exists multiple activities with the same name, it just uses the first one. Which could belong to another project.

infeeeee commented 3 years ago

You can use global activities instead: https://www.kimai.org/documentation/activity.html#global-activities They are working perfectly in kimai2-cmd.

I don't know how I could solve this client side.

GordianDziwis commented 3 years ago

This helps, thanks!