Integration of Trackline with Microsoft Dynamics 365
Export documents and additional data from Trackline to Microsoft Dynamics 365 via API queries
Learn step-by-step how to integrate Trackline with Microsoft Dynamics 365
Trackline is a functionality within the Code Contract platform that enables automation of data collection without modifying work processes or requiring manual records.
If you want to integrate Trackline with Microsoft Dynamics 365 to retrieve documents and process data, follow these steps using JWT Token authentication.
Step 1: Obtain the authentication token
Microsoft Dynamics 365 must authenticate with the Trackline API by sending a POST request to obtain a JWT token. This token will be used in subsequent requests.
Request from Microsoft Dynamics 365 (HTTP Request)
POST /login HTTP/1.1
Host: api.codecontractplattform.com
Content-Type: application/json
{
"email": "dynamics_integration_user",
"password": "dynamics_secure_password"
}
Expected Response
HTTP/1.1 200 OK
Content-Type: application/json
{
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJmcmV..."
}
The token value must be stored in Dynamics 365 and sent in each request as a Bearer Token in the authorization header.
Step 2: Query additional data and files in Trackline from Dynamics 365
Query additional data from a process
Microsoft Dynamics 365 can retrieve information about a specific process using process_id or process_name.
Request from Dynamics 365
GET /track-line/ext/track-path/metadata?process_id=12345 HTTP/1.1
Host: api.codecontractplattform.com
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJmcmV...
Expected Response
{
"process_id": "12345",
"name": "Dynamics 365 Billing Process",
"status": "In Progress",
"created_at": "2024-02-09T10:30:00Z",
"documents": [
{
"doc_id": "98765",
"doc_name": "Invoice_001.pdf",
"doc_type": "Invoice"
}
]
}
Microsoft Dynamics 365 can use this information to automatically manage processes and documents.
Download an attachment
Once the metadata has been retrieved, Microsoft Dynamics 365 can download an attachment using its attachment_id.
Request from Dynamics 365
GET /track-line/ext/attachment/file?attachment_id=98765 HTTP/1.1
Host: api.codecontractplattform.com
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJmcmV...
Expected Response (File)
The server will respond with a file in PDF, XML, or another supported format, which Dynamics 365 can store or process.
Integration in Microsoft Dynamics 365 (C# with .NET Example)
If you need to integrate this functionality into Microsoft Dynamics 365 using C# and .NET, you can use the following example code:
using System;
using System.IO;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
class TracklineIntegration
{
private static readonly HttpClient client = new HttpClient();
static async Task Main()
{
try
{
// Step 1: Obtain JWT Token
var loginUrl = "https://api.codecontractplattform.com/api/login";
var loginData = new StringContent("{\"email\": \"dynamics_integration_user\", \"password\": \"dynamics_secure_password\"}", System.Text.Encoding.UTF8, "application/json");
var loginResponse = await client.PostAsync(loginUrl, loginData);
loginResponse.EnsureSuccessStatusCode();
var token = await loginResponse.Content.ReadAsStringAsync();
token = token.Split(":")[1].Trim('"', '}'); // Extract token
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
// Step 2: Query Process Metadata in Trackline
var metadataUrl = "https://api.codecontractplattform.com/api/track-line/ext/track-path/metadata?process_id=12345";
var metadataResponse = await client.GetAsync(metadataUrl);
metadataResponse.EnsureSuccessStatusCode();
var metadata = await metadataResponse.Content.ReadAsStringAsync();
Console.WriteLine("Retrieved Metadata: " + metadata);
// Step 3: Download attachment
var attachmentId = "98765"; // This ID should be obtained from metadata
var attachmentUrl = $"https://api.codecontractplattform.com/api/track-line/ext/attachment/file?attachment_id={attachmentId}";
var attachmentResponse = await client.GetAsync(attachmentUrl);
attachmentResponse.EnsureSuccessStatusCode();
var fileBytes = await attachmentResponse.Content.ReadAsByteArrayAsync();
await File.WriteAllBytesAsync("Invoice_001.pdf", fileBytes);
Console.WriteLine("File downloaded successfully.");
}
catch (Exception ex)
{
Console.WriteLine("Integration error: " + ex.Message);
}
}
}
Summary
✔️ Step 1: Microsoft Dynamics 365 obtains the JWT token via authentication.
✔️ Step 2: Microsoft Dynamics 365 queries process metadata using process_id.
✔️ Step 3: Microsoft Dynamics 365 downloads attachments using attachment_id.
✔️ Step 4: Microsoft Dynamics 365 can automate these processes using C#, .NET or an API connector.
If you need more information or support, contact the Code Contract team. 🚀
