API Report data

Discussion for TimeTrex open source community developers.
Post Reply
fcoucello
Posts: 4
Joined: Tue Mar 06, 2018 10:03 am

API Report data

Post by fcoucello » Fri Mar 16, 2018 9:53 am

Hello all,

Before I say anything, I want to congratulate the TimeTrex team for a great job on creating this amazing software!

I recently installed TimeTrex Community Edition to test it on the company where I'm a colaborator.
Im trying to create a simple routine aplication in C# to get weekly reports. Im following the workfore-management-api from https://www.timetrex.com/workforce-management-api.
I can get the config but im getting trouble on the report data, this is the response I get:
{"-1010-time_period":{"time_period":"last_pay_period"},"-1000-template":"by_employee regular overtime premium absence"}
{"api_retval":false,"api_details":{"code":"VALIDATION","description":"INVALID DATA","record_details":{"total":1,"valid":0,"invalid":1},"user_generic_status_batch_id":false,"details":[{"time_period":["No time period defined for this report"],"columns":["No columns specified to display on report"]}]}}
it says I didnt choose any time period nor columns.
$result = postToURL( buildURL( 'APITimesheetSummaryReport', 'getTimesheetSummaryReport' ), array( $config, 'raw' ) );
with raw or wihout it i get the same response.
Im sure Im missing something some parameters I guess.

mikeb
Posts: 534
Joined: Thu Jul 27, 2006 11:58 am

Re: API Report data

Post by mikeb » Fri Mar 16, 2018 10:03 am

Can you post the raw HTTP request that you are sending to the API?
TimeTrex Community Edition is developed and supported by volunteers.
Help motivate us to continue by showing your appreciation!

fcoucello
Posts: 4
Joined: Tue Mar 06, 2018 10:03 am

Re: API Report data

Post by fcoucello » Fri Mar 16, 2018 10:28 am

http://<timetrexserver>/api/json/api.php?Class=APITimesheetSummaryReport&Method=getTimesheetSummaryReport&SessionID=\"7a4dcbdce25b480ace9b3f7c06d497fd6675eb2e\"&json={\"-1010-time_period\":{\"time_period\":\"last_pay_period\"},\"-1000-template\":\"by_employee regular overtime premium absence\"}
if I do it on the browser it shows a blank page

mikeb
Posts: 534
Joined: Thu Jul 27, 2006 11:58 am

Re: API Report data

Post by mikeb » Fri Mar 16, 2018 4:19 pm

The JSON data cannot be included on the URL, it must be included in the body of the POST request instead.
TimeTrex Community Edition is developed and supported by volunteers.
Help motivate us to continue by showing your appreciation!

fcoucello
Posts: 4
Joined: Tue Mar 06, 2018 10:03 am

Re: API Report data

Post by fcoucello » Mon Mar 19, 2018 8:05 am

Here is some PrintScreens...
Attachments
restapi3.png
With json on body2
restapi3.png (25.2 KiB) Viewed 1176 times
restapi2.png
With json on url
restapi2.png (20.82 KiB) Viewed 1176 times
restapi.png
With json on body
restapi.png (24.22 KiB) Viewed 1176 times

mikeb
Posts: 534
Joined: Thu Jul 27, 2006 11:58 am

Re: API Report data

Post by mikeb » Mon Mar 19, 2018 8:46 am

The body must be formatted with the "json" POST variable containing the raw JSON data, similar to this:

Code: Select all

json={"user_name": "myuser", "password": "mypassword"}
TimeTrex Community Edition is developed and supported by volunteers.
Help motivate us to continue by showing your appreciation!

fcoucello
Posts: 4
Joined: Tue Mar 06, 2018 10:03 am

Re: API Report data

Post by fcoucello » Mon Mar 19, 2018 10:40 am

Then Your saying that it must be in the url not in body....

mikeb
Posts: 534
Joined: Thu Jul 27, 2006 11:58 am

Re: API Report data

Post by mikeb » Mon Mar 19, 2018 3:25 pm

fcoucello wrote:
Mon Mar 19, 2018 10:40 am
Then Your saying that it must be in the url not in body....
That is incorrect, it must be in the body of the POST request.


You can simply make a call like this:

URL: https://demo.timetrex.com/next-release/ ... thod=Login
Body:

Code: Select all

json={ "user_name": "demoadmin1", "password": "demo" }
You can use this site (https://resttesttest.com/) to test the above example as well, by simply clicking on the "Add Parameter" button, giving it a name of "json" and value of "{ "user_name": "demoadmin1", "password": "demo" }"
TimeTrex Community Edition is developed and supported by volunteers.
Help motivate us to continue by showing your appreciation!

Post Reply