# API for Product 2008

### 1. Query Time Cards data:

#### Sample Code for passing parameters in URL：

```javascript
https://api1.opentimeclock.com/Jun-Inside-VPC?cmd=api/v2008QueryTimeCards&companyId=xxxx&developerToken=xxxx&nextRecord=0&dateTimeFrom=2022-05-01 00:00:00&dateTimeTo=2022-05-15 23:59:59&userFullName=xxxx&departmentName=xxxx
```

#### Sample Code in JavaScript with jQuery POST：

```javascript
function post(data, handler) {
  var url = "https://api1.opentimeclock.com/Jun-Inside-VPC"; //api url
  $.post(url, JSON.stringify(data), handler, 'json');
}

function getTimeCards() {

    //pass in JSON parameters:

  post({
    "cmd": "api/v2008QueryTimeCards", //This passed in commmand means query time cards records. We may have add or modify command later.
    "companyId": "xxxx", //Find your "Company ID" in company setting page.
    "developerToken": "xxxx", //Find "Developer Token" in reports page with admin account
    "nextRecord": "0", //Default to "0". If >"0" means query the left data when there are more than 5k records available.
    "dateTimeFrom": "2022-05-01 00:00:00", //From Date Time format: 0000-00-00 00:00:00
    "dateTimeTo": "2022-05-15 23:59:59", //To Date Time format: 0000-00-00 00:00:00
    "userFullName": "xxxx", //sample: Elon Musk; For all users, use "ALL USERS" or ""
    "departmentName": "xxxx" //sample: HR Department; For all departments, use "ALL DEPARTMENTS",or ""
  }, function (result) {

    //sample code to use returned data:

    var statusCode = result.statusCode;
    var message = result.message;
    var nextRecord = result.nextRecord;
    var dataSet = result.data;

    if(statusCode == 'SUCCESS')
        console.log('query data successfully.');

    if(statusCode == 'ERROR')
        console.log('query data failed. check returned message.');

    if(nextRecord == '-1')
        console.log('no more data left');

    if(nextRecord != '-1')
        console.log('there are more data left. pass in nextRecord to query more.');

    //use data set like this:
    var firstFullName=dataSet[0].userFullName;
  });
}
		
```

#### Sample Code in PHP：

```php
header("Content-type:application/json;charset=utf-8");

$url="https://api1.opentimeclock.com/Jun-Inside-VPC";

$param=array(
"cmd" => "api/v2008QueryTimeCards", //This passed in commmand means query time cards records. We may have add or modify command later.
"companyId" => "xxxx", //Find your "Company ID" in company setting page.
"developerToken" => "xxxx", //Find "Developer Token" in reports page with admin account
"nextRecord" => "0", //Default to "0". If >"0" means query the left data when there are more than 5k records available.
"dateTimeFrom" => "2022-05-01 00:00:00", //From Date Time format: 0000-00-00 00:00:00
"dateTimeTo" => "2022-05-15 23:59:59", //To Date Time format: 0000-00-00 00:00:00
"userFullName" => "xxxx", //sample: Elon Musk; For all users, use "ALL USERS" or ""
"departmentName" => "xxxx" //sample: HR Department; For all departments, use "ALL DEPARTMENTS",or ""
);

$data = json_encode($param);

$postdata=str_replace("\\/", "/", $data);
list($return_code, $return_content) = http_post_data($url, $postdata);

print_r($return_content);exit;

function http_post_data($url, $data_string) {

$ch = curl_init();

curl_setopt($ch, CURLOPT_POST, 1);

curl_setopt($ch, CURLOPT_URL, $url);

curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);

curl_setopt($ch, CURLOPT_HTTPHEADER, array(

"Content-Type: application/json; charset=utf-8",

"Content-Length: " . strlen($data_string))

);

ob_start();

curl_exec($ch);

$return_content = ob_get_contents();

ob_end_clean();

$return_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);

return array($return_code, $return_content);

}
		
```

#### Sample returned data in JSON：

```json
{
  "statusCode": "SUCCESS", //ERROR
  "message": "", //Company ID not found. Developer token is not correct. User Full Name not found. Department Name not found.
  "nextRecord": "-1", //if ="-1", means no more data left, otherwise please query left data from this number.
  "data":
  [
    {
      "userFullName": "Elon Musk",
      "employeeNumber": "12345",
      "userName": "elonmusk",
      "digitId": "123456",
      "inDateTime": "2021-05-27 08:49:00", //clock in date time or start date time
      "outDateTime": "2021-05-27 18:35:00", //clock out time //not applicable = 0000-00-00 00:00:00
      "hours": "0.000", //not applicable if entryType=0 (job)
      "entryType":0, //0=job; 1=pto, 2=addition adjustment, 3=deduction adjustment
      "jobName": "job 1",
      "ptoName": "vacation",
      "shiftName": "day shift",
      "employeeNote": "",
      "employeeNoteIsRead": "",
      "managerComment": "",
      "managerCommentIsRead": "",
      "inIp": "",
      "outIp": "",
      "inDeviceId": "",
      "outDeviceId": "",
      "inWifiId": "",
      "outWifiId": "",
      "inLatitude": "",
      "inLongitude": "",
      "outLatitude": "",
      "outLongitude": "",
      "entranceIn": "",
      "entranceOut: "",
      "approvedByEmployee": 0; //0=NO, 1=YES
      "approvedManagerFullName": "", //empty means not approved yet
      "createdDateTime": "2021-05-27 08:49:00" //our server time, record first created. Amazon.com aws North Virginia.
    },
    {
      //other records the same format.
    }
  ]
}
```

#### Where to find Developer Token:

<figure><img src="/files/ZeHMwBBTEthLH2ggPyxT" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.opentimeclock.com/docs/developer-api/api-for-product-2008.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
