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"
  }
 */

- get_projects(string $filter = '', string $extra = '')
- close_project(int $projectId)
- post_project(string $title, array $optional = [])
- update_project(int $projectId, array $optional = [])
- get_project_groups()
- add_project_group(string $title)
- get_project(int $projectId, string $extra = '')
- add_project_members(int $projectId, string $members)
- delete_project_members(int $projectId, string $members)
- activate_project(int $projectId)
- get_events(string $period, int $projectId = 0)

- get_all_tasks(string $filter = '', string $extra = '')
- get_task(int $taskId, string $filter = '', string $extra = '')
- get_tasks(int $projectId, string $filter = '', string $extra = '')
- post_task(int $projectId, string $title, array $optional = [])
- complete_task(int $taskId)
- reopen_task(int $taskId)
- update_task(int $taskId, array $optional = [])
- search_tasks(int $projectId, int $taskId = 0, string $emailUserFrom = '', string $emailUserTo = '', string $filter = '', string $status = '')

- me()                          - User method (only for access token)
- get_users()
- get_contacts()
- add_user(string $email, array $optional = [])
- add_contact(string $email, string $name, array $optional = [])
- subscribe(int $taskId, string $emailUser)
- unsubscribe(int $taskId, string $emailUser)
- add_user_group(string $title, int $client = null)
- add_contact_group(string $title)
- get_user_groups()
- get_contact_groups()

- get_comments(int $taskId, string $extra = '')
- post_comment(int $taskId, string $text, array $optional = [])

- get_task_tag_groups(string $type = '', string $access = '')
- get_project_tag_groups(string $type = '', string $access = '')
- get_task_tags(string $group = '', string $type = '', string $access = '')
- get_project_tags(string $group = '', string $type = '', string $access = '')
- add_task_tag_groups(string $type, string $access, string $title)
- add_project_tag_groups(string $type, string $access, string $title)
- add_task_tags(string $group, string $title)
- update_task_tags(int $taskId, array $optional = [])
- add_project_tags(string $group, string $title)
- update_project_tags(int $projectId, array $optional = [])

- get_costs(int $projectId = 0, int $taskId = 0, array $optional = [])
- get_costs_total(int $projectId = 0, int $taskId = 0, array $optional = [])
- add_costs(int $taskId, array $optional = [])
- update_costs(int $costsId, array $optional = [])
- delete_costs(int $costsId)

- get_my_timer()                      - User method (only for access token)
- start_my_timer(int $taskId)         - User method (only for access token)
- stop_my_timer(string $comment = '') - User method (only for access token)
- delete_my_timer()                   - User method (only for access token)
- get_timers()                        - Admin method (only for admin token)
- stop_timer(int $timer)              - Admin method (only for admin token)

- download(int $fileId)
- get_files(int $projectId, int $taskId = 0)

- get_webhooks()
- add_webhook(string $url, string $events, string $projectIds = '', string $httpUser = '', string $httpPassword = '')
- delete_webhook(int $webhookId)

composer