Import from Project Online Introduction
This example explains how to import project from project online by providing Token or Login and Password credentials, and save it to file using Aspose.Tasks Cloud API in your applications. You can use our REST API with any language: .NET, Java, PHP, Ruby, Rails, Python, jQuery and many more.
API
Type
Description
Resource Link
/tasks/{name}/importfromprojectonline
PUT
Imports project from Project Online and saves it to specified file
PutImportProjectFromProjectOnline
cURL Example
Case 1: Import project online using login and password credentials
Case 2: Import project online using token credentials
SDKs
The Aspose.Tasks Cloud SDKs can be downloaded from the following page: Available SDKs
SDK Examples
Case 1: Import project online using login and password credentials
C#
This file contains hidden or 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 fileName = "NewProductDev.mpp";
var getFileRequest = new DownloadFileRequest
{
Path = fileName
};
var importFileRequest = new PutImportProjectFromProjectOnlineRequest
{
Name = fileName,
Guid = Guid.Parse("E6426C44-D6CB-4B9C-AF16-48910ACE0F54"),
UserName = "SomeLogin",
XSharepointPassword = "SomePassword",
SiteUrl = "http://project_server_instance.local/sites/pwa",
Format = ProjectFileFormat.Xml
};
Stream binaryResponse = null;
var exception = Assert.ThrowsAsync<ApiException>(async () => binaryResponse = await TasksApi.DownloadFileAsync(getFileRequest));
Assert.AreEqual(HttpStatusCode.NotFound, exception.HttpStatusCode);
var response = await TasksApi.PutImportProjectFromProjectOnlineAsync(importFileRequest);
Assert.AreEqual(HttpStatusCode.OK.ToString(), (string)response.Status);
Assert.DoesNotThrowAsync(async () => binaryResponse = await TasksApi.DownloadFileAsync(getFileRequest));
Assert.That(binaryResponse, Is.Not.Null);
binaryResponse.Dispose();
await TasksApi.DeleteFileAsync((new DeleteRequest(fileName)));
PHP
This file contains hidden or 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/
static::markTestSkipped('Ignored because real credentials for project server online is required');
$remoteName = "ImportFromProjectOnline.pdf";
$response = $this->tasks->putImportFromProjectOnline(new Requests\PutImportFromProjectOnlineRequest($remoteName,
"http://project_server_instance.local/sites/pwa",
"262e5ead-1048-4a26-b558-c5eab06bcc5b",
null,
"SomeLogin",
"SomePassword",
Model\ProjectFileFormat::PDF));
Assert::assertEquals(200, $response->getCode());
$response = $this->tasks->downloadFile($remoteName);
Assert::assertNotNull($response);
Python
This file contains hidden or 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
put_request = PutImportProjectFromProjectOnlineRequest('NewProductDev.mpp', 'E6426C44-D6CB-4B9C-AF16-48910ACE0F54',
'http://project_server_instance.local/sites/pwa')
put_request.user_name = 'SomeUserName'
put_request.x_sharepoint_password = 'SomePassword'
put_request.format = ProjectFileFormat.P6XML
put_result = self.tasks_api.put_import_project_from_project_online(put_request)
self.assertIsNotNone(put_result)
self.assertIsInstance(put_result, AsposeResponse)
get_request = DownloadFileRequest('NewProductDev.mpp')
get_result = self.tasks_api.download_file(get_request)
self.assertIsNotNone(get_result)
with open(get_result) as f:
self.assertTrue(f.readable())
Node.js
This file contains hidden or 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 request1 = new PutImportProjectFromProjectOnlineRequest();
request1.name = "NewProductDev.mpp"
request1.guid = "E6426C44-D6CB-4B9C-AF16-48910ACE0F54";
request1.userName = "SomeLogin";
request1.xSharepointPassword = "SomePassword";
request1.folder = "Temp/Data/";
request1.siteUrl = "http://project_server_instance.local/sites/pwa";
request1.format = ProjectFileFormat.P6xml;
const result1 = await tasksApi.putImportProjectFromProjectOnline(request1);
expect(result1.response.statusCode).to.equal(200);
const request2 = new DownloadFileRequest();
request2.path = "NewProductDev.mpp";
const result2 = await tasksApi.downloadFile(request2);
expect(result2.response.statusCode).to.equal(200);
expect(result2.body).is.not.undefined.and.not.null;
expect(result2.body.length).to.be.at.least(1);
Go
This file contains hidden or 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 := PrepareTest(t, config)
putOptions := &requests.PutImportProjectFromProjectOnlineOpts{
Name: "NewProductDev.mpp",
Guid: "E6426C44-D6CB-4B9C-AF16-48910ACE0F54",
SiteUrl: "http://project_server_instance.local/sites/pwa",
UserName: optional.NewString("SomeLogin"),
XSharepointPassword: optional.NewString("SomePassword"),
Format: optional.NewString(string(models.P6XML_ProjectFileFormat)),
Folder: optional.NewString(remoteBaseTestDataFolder),
}
putProjectResult, _, err := client.TasksApi.PutImportProjectFromProjectOnline(ctx, putOptions)
if err != nil {
t.Error(err)
}
assert.Equal(t, int32(200), putProjectResult.Code)
file, response, err := client.TasksApi.DownloadFile(ctx, &requests.DownloadFileOpts{
Path: putOptions.Folder.Value() + "/" + putOptions.Name,
})
if err != nil {
t.Error(err)
}
assert.Equal(t, 200, response.StatusCode)
assert.Less(t, 1, len(file))
Java
This file contains hidden or 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/
PutImportProjectFromProjectOnlineRequest request1 = new PutImportProjectFromProjectOnlineRequest("NewProductDev.mpp", "E6426C44-D6CB-4B9C-AF16-48910ACE0F54", "http://project_server_instance.local/sites/pwa", "SomeLogin", ProjectFileFormat.P6XML.getValue(), null, null, null, "SomePassword");
AsposeResponse result1 = TestInitializer.tasksApi.putImportProjectFromProjectOnline(request1);
assertNotNull(result1);
assertEquals(200, result1.getCode().intValue());
DownloadFileRequest request2 = new DownloadFileRequest(request1.getname(), null, null);
File result2 = TestInitializer.tasksApi.downloadFile(request2);
TestInitializer.uploadedFiles.add(request1.getname());
assertNotNull(result2);
assertTrue(result2.exists());
Case 2: Import project online using token credentials
C#
This file contains hidden or 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 fileName = "NewProductDev.mpp";
var getFileRequest = new DownloadFileRequest
{
Path = fileName
};
var importFileRequest = new PutImportProjectFromProjectOnlineRequest
{
Name = fileName,
Guid = Guid.Parse("E6426C44-D6CB-4B9C-AF16-48910ACE0F54"),
Token = "SOMESECRETTOKEN",
SiteUrl = "http://project_server_instance.local/sites/pwa",
Format = ProjectFileFormat.Xml
};
Stream binaryResponse = null;
var exception = Assert.ThrowsAsync<ApiException>(async () => binaryResponse = await TasksApi.DownloadFileAsync(getFileRequest));
Assert.AreEqual(HttpStatusCode.NotFound, exception.HttpStatusCode);
var response = await TasksApi.PutImportProjectFromProjectOnlineAsync(importFileRequest);
Assert.AreEqual(HttpStatusCode.OK.ToString(), (string)response.Status);
Assert.DoesNotThrowAsync(async () => binaryResponse = await TasksApi.DownloadFileAsync(getFileRequest));
Assert.That(binaryResponse, Is.Not.Null);
binaryResponse.Dispose();
await TasksApi.DeleteFileAsync((new DeleteRequest(fileName)));
PHP
This file contains hidden or 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/
static::markTestSkipped('Ignored because real credentials for project server online is required');
$remoteName = "ImportFromProjectOnline.pdf";
$response = $this->tasks->putImportFromProjectOnline(new Requests\PutImportFromProjectOnlineRequest($remoteName,
"http://project_server_instance.local/sites/pwa",
"262e5ead-1048-4a26-b558-c5eab06bcc5b",
"SOMESECRETTOKEN",
null,
null,
Model\ProjectFileFormat::PDF));
Assert::assertEquals(200, $response->getCode());
$response = $this->tasks->downloadFile($remoteName);
Assert::assertNotNull($response);
Python
This file contains hidden or 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
put_request = PutImportProjectFromProjectOnlineRequest('NewProductDev.mpp', 'E6426C44-D6CB-4B9C-AF16-48910ACE0F54',
'http://project_server_instance.local/sites/pwa')
put_request.x_project_online_token = 'SOMESECRETTOKEN';
put_request.format = ProjectFileFormat.P6XML
put_result = self.tasks_api.put_import_project_from_project_online(put_request)
self.assertIsNotNone(put_result)
self.assertIsInstance(put_result, AsposeResponse)
get_request = DownloadFileRequest('NewProductDev.mpp')
get_result = self.tasks_api.download_file(get_request)
self.assertIsNotNone(get_result)
with open(get_result) as f:
self.assertTrue(f.readable())
Node.js
This file contains hidden or 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 request1 = new PutImportProjectFromProjectOnlineRequest();
request1.name = "NewProductDev.mpp"
request1.guid = "E6426C44-D6CB-4B9C-AF16-48910ACE0F54";
request1.xProjectOnlineToken = "SOMESECRETTOKEN";
request1.folder = "Temp/Data/";
request1.siteUrl = "http://project_server_instance.local/sites/pwa";
request1.format = ProjectFileFormat.P6xml;
const result1 = await tasksApi.putImportProjectFromProjectOnline(request1);
expect(result1.response.statusCode).to.equal(200);
const request2 = new DownloadFileRequest();
request2.path = "NewProductDev.mpp";
const result2 = await tasksApi.downloadFile(request2);
expect(result2.response.statusCode).to.equal(200);
expect(result2.body).is.not.undefined.and.not.null;
expect(result2.body.length).to.be.at.least(1);
Go
This file contains hidden or 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 := PrepareTest(t, config)
putOptions := &requests.PutImportProjectFromProjectOnlineOpts{
Name: "NewProductDev.mpp",
Guid: "E6426C44-D6CB-4B9C-AF16-48910ACE0F54",
SiteUrl: "http://project_server_instance.local/sites/pwa",
XProjectOnlineToken: optional.NewString("SOMESECRETTOKEN"),
Format: optional.NewString(string(models.P6XML_ProjectFileFormat)),
Folder: optional.NewString(remoteBaseTestDataFolder),
}
putProjectResult, _, err := client.TasksApi.PutImportProjectFromProjectOnline(ctx, putOptions)
if err != nil {
t.Error(err)
}
assert.Equal(t, int32(200), putProjectResult.Code)
file, response, err := client.TasksApi.DownloadFile(ctx, &requests.DownloadFileOpts{
Path: putOptions.Folder.Value() + "/" + putOptions.Name,
})
if err != nil {
t.Error(err)
}
assert.Equal(t, 200, response.StatusCode)
assert.Less(t, 1, len(file))
Java
This file contains hidden or 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/
PutImportProjectFromProjectOnlineRequest request1 = new PutImportProjectFromProjectOnlineRequest("NewProductDev.mpp", "E6426C44-D6CB-4B9C-AF16-48910ACE0F54", "http://project_server_instance.local/sites/pwa", null, ProjectFileFormat.P6XML.getValue(), null, null, "SOMESECRETTOKEN", null);
AsposeResponse result1 = TestInitializer.tasksApi.putImportProjectFromProjectOnline(request1);
assertNotNull(result1);
assertEquals(200, result1.getCode().intValue());
DownloadFileRequest request2 = new DownloadFileRequest(request1.getname(), null, null);
File result2 = TestInitializer.tasksApi.downloadFile(request2);
TestInitializer.uploadedFiles.add(request1.getname());
assertNotNull(result2);
assertTrue(result2.exists());