Get all Tasks of a Project Introduction
This example explains how read task information from a MS Project File, using Aspose.Tasks Cloud. Aspose.Tasks Cloud is a REST API which can be used with any language: .NET, Java, PHP, Ruby, Rails, Python, jQuery and many more.
API
Type
Description
Resource Link
/tasks/{name}/tasks
GET
Read project’s tasks
GetTasks
cURL Example
Request
Copy
curl - X GET "https://api.aspose.cloud/v3.0/tasks/Home%20move%20plan.mpp/tasks" - H "accept: application/json"
Response
Copy
{
"code" : 0 ,
"status" : "string" ,
"tasks" : {
"link" : {
"href" : "string" ,
"rel" : "string" ,
"type" : "string" ,
"title" : "string"
},
"taskItem" : [
{
"link" : {
"href" : "string" ,
"rel" : "string" ,
"type" : "string" ,
"title" : "string"
},
"uid" : 0 ,
"id" : 0 ,
"name" : "string" ,
"start" : "2020-09-18T07:18:50.238Z" ,
"finish" : "2020-09-18T07:18:50.238Z" ,
"duration" : "string"
}
]
}
}
SDKs
The Aspose.Tasks Cloud SDKs can be downloaded from the following page: Available SDKs
SDK Examples
C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-tasks-cloud/aspose-tasks-cloud-dotnet/
var remoteName = await UploadFileToStorageAsync("Project2016.mpp");
var tasksResponse = await TasksApi.GetTasksAsync(new GetTasksRequest
{
Name = remoteName,
Folder = this.DataFolder
});
Assert.AreEqual((int)HttpStatusCode.OK, tasksResponse.Code);
Assert.IsNotNull(tasksResponse.Tasks);
Assert.AreEqual(6, tasksResponse.Tasks.TaskItem.Count);
var firstTask = tasksResponse.Tasks.TaskItem.FirstOrDefault(i => i.Uid == 5);
Assert.IsNotNull(firstTask);
Assert.AreEqual("Summary Task 1", firstTask.Name);
Assert.AreEqual(new DateTime(2015, 8, 3, 8, 0, 0), firstTask.Start);
Assert.AreEqual(new DateTime(2015, 8, 6, 17, 0, 0), firstTask.Finish);
Assert.AreEqual("/5", firstTask.Link.Href);
PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?
// For complete examples and data files, please go to https://github.com/aspose-tasks-cloud/aspose-tasks-cloud-php/
$remoteName = "GetTasks.mpp";
$folder = $this->uploadFile("Project2016.mpp", $remoteName, '');
$response = $this->tasks->getTasks(new Requests\GetTasksRequest($remoteName, self::$storageName, $folder));
Assert::assertEquals(200, $response->getCode());
Assert::assertNotNull($response->getTasks());
Assert::assertEquals(6, count($response->getTasks()->getTaskItem()));
foreach($response->getTasks()->getTaskItem() as $t)
{
if($t->getUid() == 5)
{
$task = $t;
break;
}
}
Assert::assertNotNull($task);
Assert::assertEquals("Summary Task 1", $task->getName());
Assert::assertEquals("2015-08-03T08:00:00", $task->getStart()->format("Y-m-d\\TH:i:s"));
Assert::assertEquals("2015-08-06T17:00:00", $task->getFinish()->format("Y-m-d\\TH:i:s"));
Assert::assertEquals("/5", $task->getLink()->getHref());
Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# For complete examples and data files, please go to https://github.com/aspose-tasks-cloud/aspose-tasks-cloud-python
filename = 'Project2016.mpp'
self.upload_file(filename)
get_request = GetTasksRequest(filename)
get_result = self.tasks_api.get_tasks(get_request)
self.assertIsNotNone(get_result)
self.assertIsInstance(get_result, TaskItemsResponse)
self.assertIsNotNone(get_result.tasks)
self.assertEqual(6, len(get_result.tasks.task_item))
first_task = next(t for t in get_result.tasks.task_item if t.uid == 5)
self.assertEqual('Summary Task 1', first_task.name)
self.assertEqual(datetime(2015, 8, 3, 8, 0, 0), first_task.start)
self.assertEqual(datetime(2015, 8, 6, 17, 0, 0), first_task.finish)
self.assertEqual('/5', first_task.link.href)
Node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-tasks-cloud/aspose-tasks-cloud-node
const fileName = "Project2016.mpp";
const localPath = "./Data/" + fileName;
const remotePath = "Temp/Data";
const remoteFullPath = remotePath + "/" + fileName;
await tasksApi.uploadFileToStorage(remoteFullPath, localPath);
const request = new GetTasksRequest();
request.name = fileName;
request.folder = remotePath;
const result = await tasksApi.getTasks(request);
expect(result.response.statusCode).to.equal(200);
expect(result.body.tasks).is.not.undefined.and.not.null;
expect(result.body.tasks.taskItem.length).to.equal(6);
Go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-tasks-cloud/aspose-tasks-cloud-go/
client, ctx := UploadTestFileToStorage(t, localFileName, remoteBaseTestDataFolder+"/"+remoteFileName)
opts := &requests.GetTasksOpts{
Name: remoteFileName,
Folder: optional.NewString(remoteBaseTestDataFolder),
}
result, _, err := client.TasksApi.GetTasks(ctx, opts)
if err != nil {
t.Error(err)
}
assert.Equal(t, int32(200), result.Code)
assert.NotNil(t, result.Tasks)
assert.Equal(t, 6, len(result.Tasks.TaskItem))
var firstTask models.TaskItem
for _, t := range result.Tasks.TaskItem {
if t.Uid == 5 {
firstTask = t
break
}
}
assert.NotNil(t, firstTask)
assert.Equal(t, "Summary Task 1", firstTask.Name)
assert.Equal(t, CreateTime(2015, 8, 3, 8, 0, 0), firstTask.Start)
assert.Equal(t, CreateTime(2015, 8, 6, 17, 0, 0), firstTask.Finish)
assert.Equal(t, "/5", firstTask.Link.Href)
Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-tasks-cloud/aspose-tasks-cloud-java/
String localFileName = "Project2016.mpp";
String remoteFileName = TestInitializer.UploadFile(localFileName);
GetTasksRequest request = new GetTasksRequest(remoteFileName, null,null);
TaskItemsResponse result = TestInitializer.tasksApi.getTasks(request);
assertNotNull(result);
assertEquals(Integer.valueOf(200), result.getCode());
assertNotNull(result.getTasks());
assertEquals(6, result.getTasks().getTaskItem().size());
TaskItem firstTask = result.getTasks().getTaskItem().stream().filter(d -> d.getUid() == 5).findAny().get();
assertEquals("Summary Task 1", firstTask.getName());
assertEquals(OffsetDateTime.of(2015, 8, 3, 8, 0, 0, 0, ZoneOffset.UTC), firstTask.getStart());
assertEquals(OffsetDateTime.of(2015, 8, 6, 17, 0, 0, 0, ZoneOffset.UTC), firstTask.getFinish());
assertEquals("/5", firstTask.getLink().getHref());