Infrastructure automation · Hikvision · Microsoft 365 · Microsoft Graph

From CCTV recordings to SharePoint. Without the daily manual routine.

The NVR was already doing its job: recording footage around the clock from 32 active cameras. The problem came afterwards. If someone needed yesterday's footage preserved in SharePoint, somebody had to get involved in the export-and-upload process. I wanted to turn that into a repeatable daily workflow—find the previous day's recordings, export them as MP4 files, and put them in the right SharePoint location automatically.

Hikvision DS-7632NI-K2/16P32 active cameras24/7 recordingMP4 exportMicrosoft GraphWindows automation

The problem I wanted to solve

I wasn't trying to replace the CCTV system or change how the cameras recorded. The NVR remained the source of truth for the footage. What I wanted was a dependable hand-off from that system into Microsoft 365, so that the previous day's recordings would be available in a SharePoint document library without relying on somebody remembering to export them.

That meant treating this as two connected jobs: first, retrieve the correct recordings from the NVR; second, transfer the exported files into SharePoint using an authenticated Microsoft 365 integration. Both sides had to work for the automation to be useful.

The outcome: I got the end-to-end workflow working, including a successful retrieval/export path from the NVR and an upload into SharePoint through Microsoft Graph. The daily process was designed around the previous calendar day's footage, with files retained by date rather than overwritten.

How the pieces fit together

I kept the NVR responsible for recording and used a separate Windows host to run the automation. The script communicates with the Hikvision device to locate and retrieve recordings, stages the MP4 exports locally, then authenticates to Microsoft Graph and uploads those files to the SharePoint document library.

Hikvision NVR32 camera streams
Windows hostScheduled workflow
MP4 exportsLocal staging
Microsoft GraphApp authentication
SharePointDated archive

The Windows machine coordinates the workflow. The NVR remains the recording source; SharePoint is the destination for the exported files.

First, I had to understand how to ask the NVR for footage

The recorder was a Hikvision DS-7632NI-K2/16P, with 32 active cameras recording continuously. I needed to retrieve the footage for the previous day, not just download an arbitrary file or manually select a clip from the NVR interface.

I used the NVR's ISAPI interface to search its recordings. One important discovery during implementation was that the search behaviour needed to be handled carefully: the search was constrained by the recorder's track and result limits. I therefore treated the search as a process that could need multiple requests, rather than assuming one request would return every matching recording across all cameras.

The search results provided the recording information and playback/download references needed for retrieval. The workflow then used those references to request the actual recording files. This distinction mattered: finding a recording and successfully downloading its media are separate steps, and I validated both.

What the retrieval stage had to do

Then I connected the workflow to SharePoint

Once the export side was working, I needed a secure way for the Windows host to upload files into the SharePoint document library. I created an application registration in Microsoft Entra ID and configured a client secret for the integration. Initially, I didn't have the administrative access needed to complete the tenant-side setup, so that became a dependency I had to resolve before I could finish the Microsoft 365 integration.

After the required admin access was available, I used Microsoft Graph for the SharePoint operations. The application authenticates as an application rather than relying on an interactive user signing in every morning. That is what makes unattended scheduled execution practical. The app registration and its permissions are tenant-level security decisions, so I kept the credentials out of the script's public-facing content and out of source control.

For the upload stage, the automation sends the exported video files to the target SharePoint document library. The destination structure is organised around the recording date, so footage can be located later and a subsequent run does not simply overwrite the previous day's archive.

A useful milestone: I initially ran into Microsoft Graph request errors while validating the integration. Once the application access and Graph request flow were corrected, I successfully uploaded a video to SharePoint. That proved the destination side was working; completing the end-to-end workflow connected that upload step to the NVR retrieval process.

Putting the daily process together

The workflow was designed to run from a Windows server or PC. At each scheduled run, it works out which day to process, searches for the corresponding recordings, retrieves the MP4 files, and transfers them into SharePoint. The intended schedule was 02:00 East Africa Time, giving the system a consistent daily point at which to process the previous day's footage.

  1. Determine the date. Calculate the previous calendar day and its recording window.
  2. Search the NVR. Query the relevant camera tracks and handle result limits so the search is not prematurely truncated.
  3. Retrieve the footage. Use the recording references returned by the NVR and export the media as MP4.
  4. Stage and organise. Keep the exported files available to the upload process and associate them with the correct date.
  5. Authenticate to Microsoft Graph. Use the Entra app registration and its application credentials.
  6. Upload to SharePoint. Transfer the files into the designated document library location, preserving the dated archive.

The upload design also accounted for video files that may be too large for a simple one-shot request by using Microsoft Graph's upload-session approach. That gives the workflow a way to transfer larger files in chunks rather than treating every recording as a small document.

Building the integration from the beginning

I approached the implementation in stages so I could prove each side independently before joining them. The first stage was the recorder connection; the second was the Microsoft 365 application identity; the third was the SharePoint upload; and the final stage was bringing the steps together into a repeatable daily process.

1. Preparing the Windows automation machine

I used a Windows machine as the automation host. Python provided the runtime for the integration, while the supporting packages handled HTTP communication, Hikvision digest authentication, Microsoft identity authentication, and secure local credential storage. The scripts were organised around a configuration file for non-secret settings and Windows Credential Manager for the client secret.

The implementation used Python libraries including requests for HTTP requests, msal for Microsoft Entra application authentication, and keyring to retrieve the Graph client secret from the Windows user's credential store. This kept the secret out of the source code and ordinary configuration.

2. Connecting to the Hikvision NVR using ISAPI

The recorder was a Hikvision DS-7632NI-K2/16P. I used Hikvision's ISAPI interface rather than relying on manual exports through the NVR's graphical interface. The recording-search stage sent a time-bounded request to the NVR and processed the XML response. Each matching recording contained fields such as its track ID, start and end timestamps, and playback URI. Those values identified the media segment to retrieve.

The download logic then built the NVR's downloadRequest XML payload around the returned playback URI and posted it to the ISAPI content-download endpoint. It authenticated with HTTP Digest Authentication and streamed the response to disk in chunks, rather than loading an entire video into memory. It also checked whether the NVR had returned XML error content instead of video, rejected empty downloads, wrote to a temporary .part file while the transfer was in progress, and renamed the file only after the transfer completed.

Why the validation mattered

A successful HTTP response alone did not prove that the file was usable footage. The retrieval process checked the response content, the downloaded byte count and, where the NVR supplied an expected size, compared the received size with it. The resulting file was kept with a neutral .bin extension until its actual media container could be verified.

3. Registering the application in Microsoft Entra ID

For the SharePoint side, I created an application registration in Microsoft Entra ID. This gave the automation its own application identity, so the scheduled job did not depend on a person signing in interactively each day.

  1. Open the Microsoft Entra admin centre and go to Identity > Applications > App registrations.
  2. Select New registration, give the integration a recognisable name, and register it in the organisation's tenant.
  3. After registration, record the application's Application (client) ID and the tenant's Directory (tenant) ID. These identify the application and the tenant to the authentication code.
  4. Open Certificates & secrets, create a new client secret, and securely copy its value at creation time. The secret value is only shown once.
  5. Open API permissions, add Microsoft Graph Application permissions, and configure the SharePoint site permission required by the implementation. The authentication diagnostic checked for the Sites.ReadWrite.All application role in the issued token.
  6. Have an appropriately authorised administrator grant tenant-wide admin consent for the application permission. Without consent, the app-only token may not contain the required application role.

The project used application (app-only) authentication. The client secret is a credential and must never be published in the portfolio, committed to Git, or pasted into screenshots. The exact tenant IDs, client ID and secret are deliberately not reproduced here.

4. Configuring the application and protecting its secret

The application configuration supplied the tenant ID, client ID, SharePoint site and document-library details, plus the archive root folder and logging settings. The client secret was stored separately in Windows Credential Manager under the service name HikvisionSharePointArchive, using the credential target graph_client_secret. The Graph diagnostic retrieved that secret through keyring and used MSAL's confidential-client flow to request a token for https://graph.microsoft.com/.default.

The authentication check decoded the token claims locally and reported the tenant ID, application ID, Graph audience and application roles. It specifically checked that the configured tenant and client matched the token and that Sites.ReadWrite.All was present. It printed claims for diagnosis, not the access token itself.

5. Resolving the SharePoint destination

After obtaining a Graph access token, the upload component resolved the configured SharePoint site and document library, then worked with the library's drive and folder identifiers. It created the date-based destination folders when needed. The archive structure followed the recording date and camera, using a hierarchy equivalent to year/month/day/camera, so footage could be found by date rather than collected in one flat folder.

6. Validating the video before uploading

The upload pilot accepted a local recording path, archive date and camera name. Before sending anything to SharePoint, it checked that the file existed and was not empty. It optionally used ffprobe to report the media container, duration and streams, then checked the MP4 file signature (the ftyp marker in the file header). If a downloaded file had a .bin extension but its content was confirmed as MP4, the process made a separate MP4-named copy and preserved the original download. It refused to label an unverified file as MP4.

7. Uploading recordings through Microsoft Graph

The SharePoint upload component used Microsoft Graph to place recordings in the resolved document library folder. For larger video files, the implementation used Graph's upload-session mechanism so the file could be transferred in byte ranges rather than relying on a single small-file upload request. It used a no-overwrite conflict policy and checked whether a destination item already existed before treating the upload as new.

After upload, the pilot compared the remote SharePoint item size with the local file size. A mismatch was treated as an error; the local recording was retained for investigation rather than being marked as successfully archived. On success, the process reported the SharePoint item ID, verified size and item URL.

8. Testing the Graph upload-session behaviour

During troubleshooting, I created a separate diagnostic to isolate upload-session creation from the full video transfer. It resolved the destination folder, requested a uniquely named temporary upload session, and tested both an explicit conflictBehavior: fail request body and a minimal request body. When a session was successfully created, the diagnostic cancelled the empty session. This allowed me to test the Graph request format without uploading a video or leaving a test file behind.

9. Bringing the stages into a daily workflow

The intended operating cycle was to run at 02:00 East Africa Time and process the previous calendar day's recordings. The workflow determines the date window, searches the NVR, retrieves the matching footage, validates the media, and uploads each recording into its dated SharePoint location. The Windows host was intended to run this process unattended through Windows Task Scheduler.

End-to-end result: I validated the NVR retrieval path, established app-only Microsoft Graph authentication, and successfully uploaded a video into SharePoint. The resulting design provides a date-organised archive and avoids silently overwriting an existing recording.

Implementation notes and lessons from troubleshooting

What made the project interesting

NVR integrationSearch is not the same as download

I had to understand the recorder's search response and then use its recording references to retrieve the actual media. I also had to account for the NVR's track and result limits.

Microsoft 365Application access needed admin involvement

The Entra app registration and tenant permissions were not just coding details. I needed the right administrative access before the Graph integration could be completed.

Large filesVideo uploads need a reliable transfer path

Because CCTV exports can be large, I designed the SharePoint transfer around Microsoft Graph upload sessions rather than assuming every file would fit a basic upload request.

AutomationDate handling had to be predictable

The job is based on the previous calendar day. Consistent date boundaries and a dated SharePoint structure make the archive easier to retrieve and reduce accidental overwrites.

What I took away from it

This project brought together two systems that solve very different problems. The NVR is built to record and serve surveillance footage; SharePoint is built to store and organise business documents. The automation sits between them and has to respect the way each platform works.

It also reinforced that automation is more than getting an API call to return success. I had to validate the recording search, retrieve the media, authenticate to the tenant, upload the file, and make sure the result landed in the right place. The successful SharePoint upload was an important checkpoint, but the real value was connecting that capability to the daily recording workflow.

Project result

A repeatable CCTV-to-SharePoint workflow

The completed workflow connects the Hikvision NVR's previous-day recordings to a dated SharePoint archive using a Windows automation host and Microsoft Graph. It reduces the manual effort involved in preserving footage and gives the team a central location to retrieve exported recordings by date.

Technology used

Hikvision ISAPIHikvision NVRWindows Server / PCMicrosoft Entra IDMicrosoft Graph APISharePoint OnlineMP4Task Scheduler
Operational note: The app registration's client secret is a credential. It must be stored securely, rotated before expiry, and never committed to the public portfolio repository. Production operation should also include logging, failure alerts, retry handling, and periodic checks that recordings are arriving in SharePoint as expected.