View your availability
availability
GET https://cronorg.com/api/v1/availability?login=&password=
login | Your identification code. |
---|---|
password | Your password. |
startdate | Start date. |
enddate | End date. |
startdate
- YYYY-MM-DD, e.g. 2023-01-01
.
enddate
- YYYY-MM-DD, e.g. 2023-12-31
.
NOTE: The parameters startdate
and enddate
are mandatory.
$ curl -D - -X GET "https://cronorg.com/api/v1/availability?login=abcdef&password=ABCDEF&startdate=2023-01-01&enddate=2023-12-31"
{"status":"success","data":{"total_hours":56,"total_days":8,"weeks":{"3":12,"4":28,"5":16},"timeline":[8,4,0,0,8,8,0,8,4,0,0,8,8]}}
Returns your availability from Thursday, January 19, 2023 until Tuesday, January 31, 2023 with 8 hours available Monday till Thursday and 4 hours Friday and one day of absence on Wednesday January 25, 2023.
Click on the clock in the menu bar of your personal home page to edit your availabilities.
Download the code of the sendget
function defined in the file sendhttp.php.
Copy the file in the space of your application.
NOTE: See the page Call the service API for a description of the sendget
function.
Add the file availability.php with the following content:
- require_once 'sendhttp.php';
- function availability($login, $password, $startdate, $enddate) {
Defines the function availability
.
$login
is your identification code. $password
is your password.
$startdate
specifies the start of the period, $enddate
the end of the period.
$startdate
and $enddate
are integers of the type timestamp (Unix timestamp).
- $curl = 'https://cronorg.com/api/v1/availability';
Sets $curl
to the URL of the availability action.
- $args = array(
- 'login' => $login,
- 'password' => $password,
- 'startdate' => date('Y-m-d', $startdate),
- 'enddate' => date('Y-m-d', $enddate),
- );
Prepares the list of arguments of the GET: the identification code and the password of the user's account, the start date and the end date of the period.
- $response=sendget($curl, $args);
Sends the HTTP request with sendget
.
- if (!$response or $response[0] != 200) {
- return false;
- }
If $response
is false
, the server is unreachable.
If $response[0]
doesn't contain the HTTP return code 200 Ok, an execution error has occurred.
In case of error, availability
returns false.
- $r=json_decode($response[2], true);
Decodes the data returned in JSON.
- if ($r['status'] == 'success') {
- return ($r['data']);
- }
Returns the data array if the action has succeeded.
- return false;
- }
Returns false
in case of error.
EXAMPLE
Assuming you have saved the files sendhttp.php and availability.php in the current directory, run PHP in interactive mode, load the availability
function and call it with your identification code and password, the start date and the end date of a period in argument:
$ php -a
php > require_once 'availability.php';
php > print_r(availability('abcdef', 'ABCDEF', strtotime('2023-01-19'), strtotime('2023-01-31')));
Array
(
[total_hours] => 56
[total_days] => 8
[weeks] => Array
(
[3] => 12
[4] => 28
[5] => 16
)
[timeline] => Array
(
[0] => 8
[1] => 4
[2] => 0
[3] => 0
[4] => 8
[5] => 8
[6] => 0
[7] => 8
[8] => 4
[9] => 0
[10] => 0
[11] => 8
[12] => 8
)
)
php > quit
Comments
To add a comment, click here.