PHP code example of brightleaf-digital / asana-client

1. Go to this page and download the library: Download brightleaf-digital/asana-client 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/ */

    

brightleaf-digital / asana-client example snippets




use BrightleafDigital\AsanaClient;

$personalAccessToken = 'your-personal-access-token';
$asanaClient = AsanaClient::withPersonalAccessToken($personalAccessToken);

// Get user information
$me = $asanaClient->users()->me();

// Create a task
$taskData = [
    'name' => 'My new task',
    'notes' => 'Task description',
    'projects' => ['12345678901234'] // Project GID
];
$task = $asanaClient->tasks()->createTask($taskData);

use BrightleafDigital\AsanaClient;
use BrightleafDigital\Auth\Scopes;

$clientId = 'your-client-id';
$clientSecret = 'your-client-secret';
$redirectUri = 'https://your-app.com/callback';

// Create a client and get the authorization URL
$asanaClient = new AsanaClient($clientId, $clientSecret, $redirectUri);

// Option 1: Request specific scopes
$authUrl = $asanaClient->getAuthorizationUrl([
    Scopes::TASKS_READ,
    Scopes::PROJECTS_READ,
    Scopes::USERS_READ
]);

// Option 2: Use default/full access (pass an empty array). May not be supported after July 2025.
// $authUrl = $asanaClient->getAuthorizationUrl([]);

// Redirect the user to $authUrl
// After authorization, Asana will redirect back to your callback URL

// In your callback handler:
$code = $_GET['code'];
$tokenData = $asanaClient->handleCallback($code);

// Save $tokenData for future use
// Then use the client
$workspaces = $asanaClient->users()->getCurrentUser();