PHP code example of motion-php / client
1. Go to this page and download the library: Download motion-php/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/ */
motion-php / client example snippets
$apiKey = getenv('YOUR_API_KEY');
$client = Motion::client($apiKey);
$result = $client->task()->create([
'name' => 'My Task',
'description' => 'My Task Description',
'status' => 'Completed',
]);
echo $result['task']['name']; // My Task
echo $result['task']['description']; // My Task Description
echo $result['task']['status']; // Completed
$apiKey = getenv('YOUR_API_KEY');
// PSR-18 HTTP Client
$httpClient = new GuzzleHttp\Client([]);
$client = Motion::factory()
->withApiKey($apiKey)
->withBaseUri('api.usemotion.com')
->withHttpClient($httpClient)
->withHttpHeader('X-My-Header', 'foo')
->withQueryParam('foo', 'bar')
->withStreamHandler(fn (RequestInterface $request): ResponseInterface => $client->send($request, [
'stream' => true
]))
->make();
$response = $client->tasks()->update('IF0lK9JcsdaxeLkDZ0nMG', [
'name' => 'My Task',
'description' => 'My Task Description',
'status' => 'Completed',
]);
$task = $response->task; // Task object
$task->id; // IF0lK9JcsdaxeLkDZ0nMG
$task->name; // My Task
$task->description; // My Task Description
$task->project; // Project object
$task->toArray(); // ['id' => 'IF0lK9JcsdaxeLkDZ0nMG', ...]
$response = $client->tasks()->create([
'name' => 'My Task',
'description' => 'My Task Description',
'status' => 'Completed',
]);
$task = $response->task; // Task object
$task->id; // IF0lK9JcsdaxeLkDZ0nMG
$task->name; // My Task
$task->description; // My Task Description
$task->project; // Project object
$task->toArray(); // ['id' => 'IF0lK9JcsdaxeLkDZ0nMG', ...]
$response = $client->tasks()->delete('IF0lK9JcsdaxeLkDZ0nMG');
$response = $client->tasks()->retrieve('IF0lK9JcsdaxeLkDZ0nMG');
$task = $response->task; // Task object
$task->id; // IF0lK9JcsdaxeLkDZ0nMG
$task->name; // My Task
$task->description; // My Task Description
$task->project; // Project object
$task->toArray(); // ['id' => 'IF0lK9JcsdaxeLkDZ0nMG', ...]
$response = $client->tasks()->move('IF0lK9JcsdaxeLkDZ0nMG', 'IF0lK9JcsdaxeLkDZ0nMG');
$task = $response->task; // Task object
$task->id; // IF0lK9JcsdaxeLkDZ0nMG
$task->name; // My Task
$task->description; // My Task Description
$task->project; // Project object
$task->toArray(); // ['id' => 'IF0lK9JcsdaxeLkDZ0nMG', ...]
$response = $client->recurringTasks()->create([
'name' => 'My Task',
'description' => 'My Task Description',
'status' => 'Completed',
]);
$task = $response->task; // Task object
$task->id; // IF0lK9JcsdaxeLkDZ0nMG
$task->name; // My Task
$response = $client->recurringTasks()->list('workspaceId');
$tasks = $response->tasks; // array of Task objects
$meta = $response->meta; // Meta object
foreach ($tasks as $task) {
$task->id; // IF0lK9JcsdaxeLkDZ0nMG
$task->name; // My Task
$task->project; // Project object
}
$meta->pageSize; // 20
$meta->nextCursor; // IF0lK9JcsdaxeLkDZ0nMG
$response = $client->recurringTasks()->delete('IF0lK9JcsdaxeLkDZ0nMG');
$response = $client->workspaces()->list();
$response->workspaces; // array of Workspace objects
foreach ($response->workspaces as $workspace) {
$workspace->id; // IF0lK9JcsdaxeLkDZ0nMG
$workspace->name; // My Workspace
$workspace->teamId; // 2f0lK9JcsdaxeLkDZ0nMG
$workspace->statuses; // array of Status objects
$workspace->labels; // array of Label objects
$workspace->type; // INDIVIDUAL
}
$response->toArray(); // ['workspaces' => [...]]
$response = $client->workspaces()->statuses('IF0lK9JcsdaxeLkDZ0nMG');
$response->statuses; // array of Status objects
foreach ($response->statuses as $status) {
$status->name; // In Progress
$status->isDefaultStatus // true
$status->isResolvedStatus // false
}
$response->toArray(); // ['statuses' => [...]]
$response = $client->users()->list([
'workspaceId' => 'IF0lK9JcsdaxeLkDZ0nMG'
]);
$response->users; // array of User objects
foreach ($response->users as $user) {
$user->id; // LPSIBmTN2eai9uYoKtMkzWVFTUo2
$user->name; // Adam Paterson
$user->email; // [email protected]
}
$response->toArray(); // ['users' => [...]]
$client = Motion::factory()
->withApiKey($apiKey)
->useMockMode(true)
->make();
$response = $client->tasks()->list();
$response->tasks; // array of Task objects
bash
composer