Example Code

Automating the Download of Test Attachments From a List of Result IDs in Systemlink Using Python

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Programming Language

  • Python

Code and Documents

Attachment

Description

Description-Separate-1

This example shows how to communicate with SystemLink using Python to download specific test result attachments. 

The Python script (attached) uses the SystemLink API Key authentication but it can be modified to use username and password for authentication.  It also omits the SSL verification but you can enable it and add the path to your corresponding certificate.

The example takes a list of result IDs and allows you to filter the attachments by extension (in case you want only *.csv files or similar), it also receives the workspace ID so you must edit that field.

Finally, it will download the attachments associated with the results IDs that meet the filter criteria (workspace, extension) and it will use the download path you specified. The results will be organized in subfolders named after the corresponding result ID.

You can edit the download behavior too. The code is organized with three different functions:

  1. get_file_ids: this one just takes the result ID and returns a list of the file IDs of the files that are attached to that result.
  2. get_filtered_files: filters the list of file IDs based on the extension and workspace provided.
  3. download_file_data: downloads the files that meet the corresponding criteria in subfolders named after their corresponding result id.
Description-Separate-2

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Contributors