Jagan Rao
Jagan Rao

Reputation: 1

I can't get “Find time entries for user on workspace” using clockify API

I will try to Gets a time entry by using start date and end date for the specified user on the workspace in clockify

and I'm trying to use the following API endpoint to get the user:

How to get time entry for the specified user using this endpoint?

    <script> 
   $.ajax({

 url:'https://api.clockify.me/api/workspaces/5ce55d0df15c986c490dbd31/user/5cecc6b 
  9d278ae5b59628763/time-entries',
  method: 'GET',
  contentType: "application/json",
  headers: {
        'X-Api-Key': 'XRyd+5AH7VhhP+I8'
    },

 data: JSON.stringify({ 
 start: "2019-07-16T13:00:37Z",
 end: "2019-07-16T14:01:41Z"
  }),
  success: function(data, textStatus, request){

       obj = JSON.parse(JSON.stringify(request))
       //obj = JSON.parse(request);    
       //console.log(request);
       console.log(obj.responseJSON);

    document.getElementById("demo").innerHTML = txt;
   },
   error: function (request, textStatus, errorThrown) {

         console.log("Error");
   },
  always: function(r) {
    console.log(r);
    alert(r);
  }
  });
  </script>

 {
    "timestamp": "2019-07-18T05:42:25.577+0000",
    "status": 404,
    "error": "Not Found",`enter code here`
    "message": "No message availabl",
    "path": "/workspaces/5ce55d0df15c986c490dbd31/user/5cecc6b9d278ae5b59628763/time-entries"
  }

Upvotes: 0

Views: 581

Answers (2)

Kerschbaumer Stefan
Kerschbaumer Stefan

Reputation: 392

It's because their API documentation is wrong. The right endpoint is: https://api.clockify.me/api//workspaces/workspaceId/timeEntries/user/userId/

Upvotes: 1

HalfBloodPrince
HalfBloodPrince

Reputation: 121

Can you point out how and where you are specifying the user name?

Also, refer following code snippet where you can set start and end time before request. And store them in an environment variable.

//Getting current TS
var timestampHeader = new Date().getTime();
console.log("Current Time for event is -> "+timestampHeader);
pm.environment.set("currentTime",timestampHeader);

//Getting old TS
var date = new Date();
date.setTime(date.getTime() - 7.884e+9);
console.log("Old Time for event Is : "+date.getTime());
pm.environment.set("oldTime", date.getTime());

Similarly, you can store a User name in Environment Variable.

To Store values in environement variable: pm.environement.set("variable_name", variable_value);

To get the value of a variable: pm.environement.get("variable_name");

So, you an do like follow:

  1. Set Start Time, End Time and User values in environment variable using Pre-request Script

Eg.

pm.environement.set("start_time","start time value");

pm.environement.set("end_time","endtime value");

pm.environement.set("user","user value");

  1. In request body pass above values

like,

{{start__time}}

{{end_time}}

{{user}}

Upvotes: 0

Related Questions