How to get ExtractedFileId for Scheduled Completed Extractions.

pkosakowski
pkosakowski Newcomer

How do we get the ExtractedFileId values?

I am trying this code, but it does not seem to return any value that I can use to download?

var ExtractionsContext = newExtractionsContext(newUri("https://hosted.datascopeapi.reuters.com/RestApi/v1/"), "USERNAME", “PASSWORD");

var
completedExtractions = ExtractionsContext.ReportExtractionOperations.GetCompletedByDateRange(

DateTime.UtcNow.Date.AddDays(-5),
DateTime.UtcNow.AddMinutes(5));

Best Answer

  • @pkosakowski

    The download links you provided is for Web GUI only. To programmatically download the extracted file via .Net SDK, you need to call ExtractedFileOperations.GetReadStream() on the extracted file object retrieved by the code I provided in the previous answer. The extracted file normally is downloaded as data stream, so application needs to write the stream to file.

    Below is the sample code modified to download an extracted data file of the first completed Report Extraction in the list returned from GetCompletedDateRange.

    var completedExtractions = ExtractionsContext.ReportExtractionOperations.GetCompletedByDateRange(

    DateTime.UtcNow.Date.AddDays(-5), DateTime.UtcNow.AddMinutes(5));

    var extraction = completedExtractions.FirstOrDefault(e => e.Status == ThomsonReuters.Dss.Api.Extractions.ReportExtractions.ReportExtractionStatus.Completed);
    if (extraction != null)
    {
    System.Console.WriteLine("Report Extraction Id: {0}", extraction.ReportExtractionId);
    ExtractionsContext.LoadProperty(extraction, "Files");

    //Find the extract file. Other ExtractedFileTypes are: Note, RicMaintenanceNote, Full, Partial, Other
    var extractFile = extraction.Files.FirstOrDefault(f => f.FileType == ThomsonReuters.Dss.Api.Extractions.ReportExtractions.ExtractedFileType.Full);
    if (extractFile != null)
    {
    //Output the contents of the extracted file
    var streamResponse = ExtractionsContext.ExtractedFileOperations.GetReadStream(extractFile);
    string path = "./" + extractFile.ExtractedFileName;


    //Disable automatic decompression
    ExtractionsContext.Options.AutomaticDecompression = false;

    //Save stream to file
    using (Stream s = File.Create(path))
    {
    streamResponse.Stream.CopyTo(s);
    }
    }
    }

    Please note that the ReadStream will automatically decode data if the extracted file is in gzip format. You can add "ExtractionsContext.Options.AutomaticDecompression = false" to directly write the file without decoding.

    For more detail, please see the "Retrieving the extracted files" section in this tutorial and the Streaming section in DSS Key Mechanism.

Answers