PHP code example of worksection / worksection-php-sdk
1. Go to this page and download the library: Download worksection/worksection-php-sdk library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
worksection / worksection-php-sdk example snippets
use Worksection\SDK\EntityBuilder;
use Worksection\SDK\Exception\SdkException;
$sdk = EntityBuilder::getInstance('https://myaccount.worksection.com/');
$sdk->setAdminToken('0da9fa4321ghm887530cfb8w3m57d3f4');
try {
$projectsEntity = $sdk->createProjectsEntity(); // Entity for using projects api methods
$tasksEntity = $sdk->createTasksEntity(); // Entity for using tasks api methods
$membersEntity = $sdk->createMembersEntity(); // Entity for using members api methods
$commentsEntity = $sdk->createCommentsEntity() // Entity for using comments api methods
$tagsEntity = $sdk->createTagsEntity(); // Entity for using tags api methods
$costsEntity = $sdk->createCostsEntity(); // Entity for using costs api methods
$filesEntity = $sdk->createFilesEntity(); // Entity for using files api methods
// Example of usage (returns data on all projects)
$result = $projectsEntity->get_projects();
// Example of usage (creates a project)
$result = $projectsEntity->post_project('New Test Project', [
'email_user_from' => '[email protected]',
'email_manager' => '[email protected]',
'text' => 'Description of project',
'datestart' => '29.12.2023',
'dateend' => '29.12.2024'
]);
// Example of usage (closes the specified task (100500 id task in 100 id project)
$result = $tasksEntity->complete_task(100, 100500);
} catch (SdkException $e) {
// work with errors
}
use Worksection\SDK\EntityBuilder;
use Worksection\SDK\Exception\SdkException;
$sdk = EntityBuilder::getInstance('https://myaccount.worksection.com/');
$sdk->setAccessToken('eyJ0eXAiOiJKV...3v3tKTcdp8zg');
try {
$projectsEntity = $sdk->createProjectsEntity(); // Entity for using projects api methods
$tasksEntity = $sdk->createTasksEntity(); // Entity for using tasks api methods
$membersEntity = $sdk->createMembersEntity(); // Entity for using members api methods
$commentsEntity = $sdk->createCommentsEntity() // Entity for using comments api methods
$tagsEntity = $sdk->createTagsEntity(); // Entity for using tags api methods
$costsEntity = $sdk->createCostsEntity(); // Entity for using costs api methods
$filesEntity = $sdk->createFilesEntity(); // Entity for using files api methods
// Example of usage (returns data on all open and closed account tasks/subtasks)
$result = $tasksEntity->get_all_tasks();
// Example of usage (create comments in task)
$result = $commentsEntity->post_comment(
'[email protected]', // Email user from
'Text of my comment, hello world!', // Text of comment
500, // Project ID
899 // Task ID
);
} catch (SdkException $e) {
// work with errors
}
use Worksection\SDK\EntityBuilder;
use Worksection\SDK\Exception\SdkException;
// Example usage
$tokensData = EntityBuilder::refreshToken(
'5ba135c31b89r688256h984722891861', // client id
'71aef25ea193128c9186dd89bf4537f0b0cb2d4f09a2a1b7ed05c98b25fbc1', // client secret
'def4720027cbe...89ce27148ad6' // refresh token
);
/**
* Response in tokensData example:
{
"token_type": "Bearer",
"expires_in": 86400,
"access_token": "eyJ0...cdp7zg",
"refresh_token": "def50200...8448rd2"
}
*/
use Worksection\SDK\EntityBuilder;
use Worksection\SDK\Exception\SdkException;
// Example usage
$sdk = EntityBuilder::getInstance('https://myaccount.worksection.com/');
$sdk->setAccessToken('eyJ0eXAiOiJKV...3v3tKTcdp8zg');
// If access token has expired while the request is being used
// SDK will use the specified refresh token to update access token
// then execute the request and return data with new tokens
$sdk->setAutoRefreshToken(
'5ba135c31b89r688256h984722891861', // client id
'71aef25ea193128c9186dd89bf4537f0b0cb2d4f09a2a1b7ed05c98b25fbc1', // client secret
'def4720027cbe...89ce27148ad6' // refresh token
);
$projectsEntity = $sdk->createProjectsEntity();
$result = $projectsEntity->get_projects();
/**
* Response example (autorefresh enable):
{
"status": "ok",
"data": [
{
"id": "262",
"name": "",
"page": "/project/262/",
"status": "archive",
"company": "Management",
"user_from": {
"id": "111",
"email": "[email protected]",
"name": "dev"
}
},
{
"id": "203",
"name": "",
"page": "/project/203/",
"status": "archive",
"company": "Design",
"user_from": {
"id": "222",
"email": "[email protected]",
"name": "Smith John"
}
}
],
"access_token": "eyJ0...cdp7zg",
"refresh_token": "def50200...8448rd2"
}
*/