Find the insights and best practices about our product.
🤖 Trackline – Proactive automation
🔎 SmartCheck – Digital evidence
🚀 Use cases by sector
Food sector
Construction sector
Industrial sector
Logistics sector
👤 Role based use cases
📊 Use cases by functionality
🤝🏻 Partners
Trackline & SharePoint Integration
Export Trackline documents and data to SharePoint using HTTP calls

Trackline is a functionality within the Code Contract platform that automates information collection without changing existing workflows and without requiring manual data entry.

 

This post explains how to automatically download documents from a Trackline process and save them into a SharePoint document library using HTTP calls.

 

You can implement this in:

  • Your own backend (Node.js, Python, .NET, Java…)
  • Azure Function / AWS Lambda
  • A corporate server
  • An internal API that syncs Trackline with SharePoint

1. Step 1 — Get the Trackline Token

Before downloading documents, you need a JWT token.

 

🔹 Example request (POST)

POST https://api.codecontractplattform.com/api/login
Content-Type: application/json

 

Body:

{
"email": "YOUR_USER",
"password": "YOUR_PASSWORD"
}

 

Expected response:

{
"token": "eyJ0eXAiOiJKV1QiLCJhbGc..."
}

 

Store this token to use it in the following requests.

2. Step 2 — Retrieve the list of documents for a process

To know which documents exist in Trackline, query the process metadata.

 

🔹 Example request (GET)

GET https://api.codecontractplattform.com/api/track-line/ext/track-path/metadata?process_id=PROCESS_ID
Authorization: Bearer JWT_TOKEN

 

Response:

{
"process_id": "12345",
"documents": [
{
"doc_id": "98765",
"doc_name": "Invoice_001.pdf"
},
{
"doc_id": "98766",
"doc_name": "PackingList_002.pdf"
}
]
}

 

Each document includes:

  • doc_id → used to download the file
  • doc_name → original filename

 

3. Step 3 — Download each document from Trackline

For each doc_id, you can download the binary file.

 

🔹 Request (GET):

GET https://api.codecontractplattform.com/api/track-line/ext/attachment/file?attachment_id=98765
Authorization: Bearer JWT_TOKEN

 

Response:
Binary content (PDF, XML, ZIP, JPG, etc.)

Save it into a variable or as a file on your server.

4. Step 4 — Upload the file to SharePoint

SharePoint allows file uploads to a library using its REST API.

You need a Microsoft Azure AD OAuth2 access token to authenticate.

4.1 Get a SharePoint token (Azure AD)

Typical server-side call:

 

POST https://login.microsoftonline.com/TENANT_ID/oauth2/v2.0/token
Content-Type: application/x-www-form-urlencoded

 

Body:

client_id=APP_ID
scope=https://graph.microsoft.com/.default
client_secret=APP_SECRET
grant_type=client_credentials

 

Response:

{
"access_token": "SP_ACCESS_TOKEN",
"expires_in": 3599
}

 

This access_token is used to upload files.

4.2 Upload documents to a SharePoint library

Assume you want to upload to:

https://yourcompany.sharepoint.com/sites/Documents/Shared Documents/Trackline

 

🔹 Example request (PUT)

PUT https://yourcompany.sharepoint.com/sites/Documents/_api/web/GetFolderByServerRelativeUrl('/sites/Documents/Shared Documents/Trackline')/Files/add(url='Invoice_001.pdf',overwrite=true)
Authorization: Bearer SP_ACCESS_TOKEN
Content-Type: application/octet-stream

<binary_file_content>

 

If the upload succeeds, SharePoint returns file metadata.

5. Full Workflow Summary

1️⃣ Log in to Trackline → get JWT token
2️⃣ Query process metadata → obtain document list
3️⃣ Download each document from Trackline
4️⃣ Authenticate with Azure AD → obtain SharePoint token
5️⃣ Upload each file to the SharePoint library

6. Complete Example (Node.js)

(You can copy/paste this into any backend service)

 

const fetch = require("node-fetch");
const fs = require("fs");

// 1. Get Trackline token
async function getTracklineToken() {
const res = await fetch("https://api.codecontractplattform.com/api/login", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
email: "YOUR_USER",
password: "YOUR_PASSWORD"
})
});
return (await res.json()).token;
}

// 2. Get documents for a process
async function getDocuments(token, processId) {
const res = await fetch(
`https://api.codecontractplattform.com/api/track-line/ext/track-path/metadata?process_id=${processId}`,
{ headers: { Authorization: `Bearer ${token}` } }
);
return (await res.json()).documents;
}

// 3. Download a document
async function downloadFile(token, docId) {
const res = await fetch(
`https://api.codecontractplattform.com/api/track-line/ext/attachment/file?attachment_id=${docId}`,
{ headers: { Authorization: `Bearer ${token}` } }
);
return Buffer.from(await res.arrayBuffer());
}

// 4. Upload file to SharePoint
async function uploadToSharePoint(accessToken, fileName, fileContent) {
const url = `https://yourcompany.sharepoint.com/sites/Documents/_api/web/GetFolderByServerRelativeUrl('/sites/Documents/Shared Documents/Trackline')/Files/add(url='${fileName}',overwrite=true)`;

await fetch(url, {
method: "PUT",
headers: {
"Authorization": `Bearer ${accessToken}`,
"Content-Type": "application/octet-stream"
},
body: fileContent
});
}

(async () => {
const tracklineToken = await getTracklineToken();
const docs = await getDocuments(tracklineToken, "12345");

for (const doc of docs) {
const bin = await downloadFile(tracklineToken, doc.doc_id);

// Here you should fetch SP_ACCESS_TOKEN
const spAccessToken = "SHAREPOINT_TOKEN";

await uploadToSharePoint(spAccessToken, doc.doc_name, bin);
}
})();

 

If you need more information or support, feel free to contact the Code Contract team. 🚀