Skip to Content

Downloading files via API

Files uploaded to CMW Tracker can be downloaded both in the interface and externally through the open API of the system. In order to be able to do that:

1. Generate an API token in the Administration area.

2. Write a C# script. Below is a piece of C# code that will download a file with ID 33854 (rev is an analogue of ID when working with attachments):

HttpClient cl = new HttpClient();
cl.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", "your_token_b21c46016cpb42ca9f1374a481746281"); // API-key

var GetTask = cl.GetAsync("https://your_domain.comindware.net/Api/Attachment/Content/rev.33854"); // receiving the file
GetTask.Wait();
var GetTask_NAME = cl.GetAsync("https://your_domain.comindware.net/Api/Attachment/?query.revisionId=rev.33854"); // receiving the file's metadata
GetTask_NAME.Wait();
string name_file = GetTask_NAME.Result.Content.ReadAsStringAsync().Result;
name_file = name_file.Substring(name_file.IndexOf("name") + 8, name_file.IndexOf("GetAttachment.ashx?id=rev.") - name_file.IndexOf("name") - 27); // extracting the file name from the metadata

using (var fs = new FileStream(@"c:\report\Tracker\" + name_file, FileMode.CreateNew)) // saving the file to the specified path
{
var ResponseTask = GetTask.Result.Content.CopyToAsync(fs);
ResponseTask.Wait();
}