Example  Remote Data Analysis at Your Fingertips

The following code snippets demonstrate how third-party applications can log in to the application, find & retrieve entities, upload data, create & start tasks, wait for task completion, and download analysis results. For illustration purposes, each example shows both C# code (written using provided library code), and corresponding raw XML requests and responses. Because entity and message serializing rules are so simple, any application written in any XML-enabled language can use Data Applied's XML-based Web API. Click here to show all details.

Log In

Log In

Receive a ticket and account information

// Set credentials
UserInfo userInfo = new UserInfo();
userInfo.Name =
"user";
userInfo.Password =
"password";

// Get a ticket
LogonMessage logonRequest = new LogonMessage();
logonRequest.Instance = userInfo;
LogonMessage logonResponse =
  (
LogonMessage)Program.Submit(logonRequest);
string ticket = logonResponse.Ticket;
XML

Data Exchanges

Corresponding XML Request and Response

<LogonMessage>
 <Instance>
  <UserInfo>
   <Password>password</Password>
   <Name>user</Name>
  </UserInfo>
 </Instance>
</LogonMessage>
<LogonMessage>
 <Instance>
  <UserInfo>
   <Name>user</Name>
   <Id>8a021090-2980-...</Id>
   <FirstName>first</FirstName>
   <LastName>last</LastName>
   <EmailAddress>user@domain.com</EmailAddress>
   <DateCreated>7/27/2009 9:49:44 AM</DateCreated>
   <LicenseKey>...</LicenseKey>
  </UserInfo>
 </Instance>
 <Ticket>...</Ticket>
 <Version>...</Version>
 </LogonMessage>
Find & Retrieve Objects

Find & Retrieve Objects

Find workspaces owned by the logged-in user

// Find workspaces owned by the user
ValueRestriction ownerValueRestriction = new ValueRestriction
 
("OwningUserInfoId", Condition.Equal, userId);
ConditionRestriction ownerConditionRestriction =
  new
SelectConditionRestriction();
ownerConditionRestriction.AppendRestriction(ownerValueRestriction);
RetrieveMessage retrieveRequest = new RetrieveMessage();
retrieveRequest.Ticket = ticket;
retrieveRequest.TypeName =
typeof(WorkspaceInfo).Name;
retrieveRequest.ConditionRestriction = ownerConditionRestriction;
RetrieveMessage retrieveResponse =
  (
RetrieveMessage)Program.Submit(retrieveRequest);
WorkspaceInfo workspaceInfo = (WorkspaceInfo)retrieveResponse.Instances[0];
XML

Data Exchanges

Corresponding XML Request and Response

<RetrieveMessage>
 <TypeName>WorkspaceInfo</TypeName>
 <Count>1</Count>
 <ConditionRestriction>
  <SelectConditionRestriction>
    <Restrictions>
      <ValueRestriction>
       <Value>
         <Guid>8a021090-2980-46bb-...</Guid>
       </Value>
      <Condition>2</Condition>
      <FieldName>OwningUserInfoId</FieldName>
    </ValueRestriction>
   </Restrictions>
  </SelectConditionRestriction>
 </ConditionRestriction>
 <Ticket>...</Ticket>
</RetrieveMessage>
<RetrieveMessage>
 <TypeName>WorkspaceInfo</TypeName>
 <Count>1</Count>
 <ConditionRestriction>...</ConditionRestriction>
 <Instances>
  <WorkspaceInfo>
   <Id>4f5ad0e3-8ef5-...</Id>
   <DatabaseInfoId>2b25b33d-7822-4a71-...</DatabaseInfoId>
   <OwningUserInfoId>8a021090-2980-...</OwningUserInfoId>
   <Name>My Workspace</Name>
   <Description>Personal workspace</Description>
   <CreatedBy>user</CreatedBy>
   <DateCreated>7/27/2009 9:49:45 AM</DateCreated>
  </WorkspaceInfo>
 </Instances>
 <Ticket>...</Ticket>
 <Version>...</Version>
</RetrieveMessage>
Upload Data

Upload Data

Upload chunks of data from a file

Guid tableInfoId = Guid.NewGuid();
byte[] buffer = new byte[65536];
CreateMessage createRequest = new CreateMessage();
int order = 0;
using (FileStream fileStream =  File.OpenRead("data.csv"))
{
    
while (true)
    {
        
// Check if done reading file content
        int read = fileStream.Read(buffer, 0, buffer.Length);
        
if (0 >= read)
            
break;
        
        
// Adjust the buffer if not full
        if (read < buffer.Length)
        {
            
byte[] newBytes = new byte[read];
            
Array.Copy(buffer, newBytes, read);
            buffer = newBytes;
        }

        
// Prepare a data chunk
        ChunkInfo chunkInfo = new ChunkInfo();
        chunkInfo.TableInfoId = tableInfoId;
        chunkInfo.WorkspaceInfoId = workspaceInfo.Id;
        chunkInfo.FileName =
"data.csv";
        chunkInfo.HasFieldHeader =
true;
        chunkInfo.Content =
Convert.ToBase64String(buffer);
        chunkInfo.ChunkOrder = order++;
        
        
// Upload the data chunk
        createRequest.Ticket = ticket;
        createRequest.Instance = chunkInfo;
        
Program.Submit(createRequest);
    }
}
XML

Data Exchanges

Corresponding XML Request and Response

<CreateMessage>
 <Instance>
  <ChunkInfo>
   <WorkspaceInfoId>4f5ad0e3-8ef5-...</WorkspaceInfoId>
   <TableInfoId>ddb37ed0-cc91-...</TableInfoId>
   <FileName>data.csv</FileName>
   <Content>...[base64 data]...</Content>
   <HasFieldHeader>True</HasFieldHeader>
  </ChunkInfo>
 </Instance>
 <Ticket>...</Ticket>
</CreateMessage>
<CreateMessage>
 <Instance>
  <ChunkInfo>
   <WorkspaceInfoId>4f5ad0e3-8ef5-...</WorkspaceInfoId>
   <TableInfoId>10b52631-5dfb-460c-...</TableInfoId>
   <FileName>data.csv</FileName>
   <HasFieldHeader>True</HasFieldHeader>
   <Id>1d05a8d7-116e-46e5-...</Id>
   <OwningUserInfoId>8a021090-2980-...</OwningUserInfoId>
   <CreatedBy>user</CreatedBy>
   <DateCreated>7/27/2009 10:51:37 PM</DateCreated>
  </ChunkInfo>
 </Instance>
 <Ticket>...</Ticket>
 <Version>...</Version>
</CreateMessage>
Create & Start a Task

Create & Start a Task

Create a new task and request execution

// Create a data upload task
Guid uploadTaskId = Guid.NewGuid();
RootDataUploadTaskInfo rootDataUploadTaskInfo =
 
new RootDataUploadTaskInfo();
rootDataUploadTaskInfo.Id = uploadTaskId;
rootDataUploadTaskInfo.Description =
"Data Upload Task";
rootDataUploadTaskInfo.FileType =
".csv";
rootDataUploadTaskInfo.TargetTableInfoId = tableInfoId;
rootDataUploadTaskInfo.WorkspaceInfoId = workspaceInfo.Id;
createRequest =
new CreateMessage();
createRequest.Ticket = ticket;
createRequest.Instance = rootDataUploadTaskInfo;
Program.Submit(createRequest);

// Start the data upload task
StartTaskMessage startUploadRequest = new StartTaskMessage();
startUploadRequest.Ticket = ticket;
startUploadRequest.RootAlgorithmTaskInfo = rootDataUploadTaskInfo;
Program.Submit(startUploadRequest);
XML

Data Exchanges

Corresponding XML Request and Response

<CreateMessage>
 <Instance>
  <RootDataUploadTaskInfo>
    <WorkspaceInfoId>4f5ad0e3-8ef5-...</WorkspaceInfoId>
    <TargetTableInfoId>eab8d934-778e-...</TargetTableInfoId>
    <Description>Data Upload Task</Description>
    <FileType>.csv</FileType>
    <Id>ae58b6fd-9677-4c75-...</Id>
   </RootDataUploadTaskInfo>
  </Instance>
 <Ticket>...</Ticket>
</CreateMessage>

<StartTaskMessage>
 <RootAlgorithmTaskInfo>
  <RootDataUploadTaskInfo>
   <WorkspaceInfoId>4f5ad0e3-8ef5-...</WorkspaceInfoId>
   <Id>ae58b6fd-9677-4c75-...</Id>
  </RootDataUploadTaskInfo>
 </RootAlgorithmTaskInfo>
 <Ticket>...</Ticket>
 <Version>...</Version>
</StartTaskMessage>
<CreateMessage>
 <Instance>
  <RootDataUploadTaskInfo>
   <WorkspaceInfoId>4f5ad0e3-8ef5-...</WorkspaceInfoId>
   <TargetTableInfoId>eab8d934-778e-...</TargetTableInfoId>
   <Description>Data Upload Task</Description>
   <FileType>.csv</FileType>
   <Id>ae58b6fd-9677-4c75-...</Id>
   <OwningUserInfoId>8a021090-2980-...</OwningUserInfoId>
   <CreatedBy>user</CreatedBy>
   <DateCreated>7/27/2009 11:20:49 PM</DateCreated>
  </RootDataUploadTaskInfo>
 </Instance>
 <Ticket>...</Ticket>
</CreateMessage>

<StartTaskMessage>
 <RootAlgorithmTaskInfo>
    ...
 </RootAlgorithmTaskInfo>
 <Ticket>...</Ticket>
 <Version>...</Version>
</StartTaskMessage>
Wait for Task Completion

Wait for Task Completion

Poll to determine when the task completed

// Wait for the task to complete
while (true)
{
    
// Get the task status
    ValueRestriction idValueRestriction =
        new
ValueRestriction("Id", Condition.Equal, uploadTaskId);
    
ConditionRestriction idConditionRestriction =
        new
SelectConditionRestriction();
    idConditionRestriction.AppendRestriction(idValueRestriction);
    
RetrieveTaskMessage retrieveTaskRequest =
       
new RetrieveTaskMessage();
    retrieveTaskRequest.Ticket = ticket;
    retrieveTaskRequest.WorkspaceInfo = workspaceInfo;
    retrieveTaskRequest.TypeName =

        typeof
(RootDataUploadTaskInfo).Name;
    retrieveTaskRequest.ConditionRestriction = idConditionRestriction;
    retrieveTaskRequest.Count = 1;
// one expected
    RetrieveTaskMessage retrieveTaskResponse =
        (
RetrieveTaskMessage)
           
Program.Submit(retrieveTaskRequest);
    rootDataUploadTaskInfo =
        (
RootDataUploadTaskInfo)retrieveTaskResponse.Instances[0];
    
if (RunState.Completed == rootDataUploadTaskInfo.RunState)
        
break;
    
Thread.Sleep(1000);
}
XML

Data Exchanges

Corresponding XML Request and Response

<RetrieveTaskMessage>
 <WorkspaceInfo>
  <WorkspaceInfo>
   <Id>4f5ad0e3-8ef5-...</Id>
  </WorkspaceInfo>
 </WorkspaceInfo>
 <TypeName>RootDataUploadTaskInfo</TypeName>
 <Count>1</Count>
 <ConditionRestriction>
  <SelectConditionRestriction>
   <Restrictions>
    <ValueRestriction>
     <Value>
       <Guid>961e964f-eb99-4895-...</Guid>
     </Value>
     <Condition>2</Condition>
     <FieldName>Id</FieldName>
    </ValueRestriction>
   </Restrictions>
  </SelectConditionRestriction>
 </ConditionRestriction>
 <Ticket>...</Ticket>
</RetrieveTaskMessage>
<RetrieveTaskMessage>
 <WorkspaceInfo>
  <WorkspaceInfo>...</WorkspaceInfo>
 </WorkspaceInfo>
 <TypeName>RootDataUploadTaskInfo</TypeName>
 <Count>1</Count>
 <ConditionRestriction>...</ConditionRestriction>
 <Instances>
  <RootDataUploadTaskInfo>
   <WorkspaceInfoId>4f5ad0e3-8ef5-...</WorkspaceInfoId>
   <TargetTableInfoId>4dced3ac-0ee3-...</TargetTableInfoId>
   <Description>Data Upload Task</Description>
   <Id>961e964f-eb99-...</Id>
   <OwningUserInfoId>8a021090-2980-...</OwningUserInfoId>
   <CreatedBy>user</CreatedBy>
   <DateCreated>7/27/2009 11:57:00 PM</DateCreated>
   <RunState>3</RunState>
  </RootDataUploadTaskInfo>
 </Instances>
 <Ticket>...</Ticket>
 <Version>...</Version>
</RetrieveTaskMessage>
Download Analysis Results

Download Analysis Results

Retrieve results following task execution

// Retrieve association results
RetrieveTaskResultMessage retrieveTaskResultRequest
  =
new RetrieveTaskResultMessage();
retrieveTaskResultRequest.Ticket = ticket;
retrieveTaskResultRequest.RootAlgorithmTaskInfo =
  rootAssociationTaskInfo;
retrieveTaskResultRequest.TypeName =

 typeof
(AssociationResultInfo).Name;
RetrieveTaskResultMessage retrieveTaskResultResponse =
  (
RetrieveTaskResultMessage)
 
Program.Submit(retrieveTaskResultRequest);
foreach (AssociationResultInfo associationResultInfo in retrieveTaskResultResponse.Instances)
{
    
Console.WriteLine(
        
String.Format(CultureInfo.InvariantCulture,
        
"Found association: actual={0}, expected={1}, rule={2}",
        associationResultInfo.Actual, associationResultInfo.Expected, associationResultInfo.RuleXml));
}
XML

Data Exchanges

Corresponding XML Request and Response

<RetrieveTaskResultMessage>
  <RootAlgorithmTaskInfo>
    <RootAssociationTaskInfo>
      <WorkspaceInfoId>e1f5ee79-4bae-...</WorkspaceInfoId>
      <TargetTableInfoId>1f8cfa69-0f41-...</TargetTableInfoId>
      <Id>2153c6ca-e0fb-43f3-8dc0-1fb874e0a44e</Id>
    </RootAssociationTaskInfo>
  </RootAlgorithmTaskInfo>
  <TypeName>AssociationResultInfo</TypeName
  <Ticket>...</Ticket>
</RetrieveTaskResultMessage>
<RetrieveTaskResultMessage>
  <RootAlgorithmTaskInfo>
    <RootAssociationTaskInfo>
      <WorkspaceInfoId>e1f5ee79-4bae-...</WorkspaceInfoId>
      <TargetTableInfoId>1f8cfa69-0f41-...</TargetTableInfoId>
      <Id>2153c6ca-e0fb-43f3-8dc0-1fb874e0a44e</Id>
    </RootAssociationTaskInfo>
  </RootAlgorithmTaskInfo>
  <TypeName>AssociationResultInfo</TypeName>
  <Instances>
    <AssociationResultInfo>
      <Expected>5</Expected>
        <Actual>11</Actual>
        <Strength>2.04254254254254</Strength>
        <RuleXml>...</RuleXml>
        <Id>e483905d-7980-44fa-...</Id>
        <OwnerId>4d2d1467-c42f-...</OwnerId>
      </AssociationResultInfo>
      ...
  </Instances>
  <Ticket>...</Ticket>
  <Version>...</Version>
</RetrieveTaskResultMessage>