question

Upvotes
Accepted
1 1 1 2

Equivalent Java Code for the C# code[Download Package Deliveries]

Hi,

I am able to extract the list of Package Delivery Id in JAVA but cannot find any API for downloading the files. In the REST API Reference tree Section, I found the following C# code for downloading the files. Can someone provide the download the package deliveries code in JAVA for a given PackageDeliveryId ?

var StandardExtractionsContext = new StandardExtractionsContext(new Uri("https://hosted.datascopeapi.reuters.com/RestApi/v1/"), "<your user id>", "<your password>");
//Returns the list of all available subscriptions.
var subscriptions = StandardExtractionsContext.SubscriptionOperations.GetAll();
//Output
var fromDate = DateTime.UtcNow.AddDays(-1);
var toDate = DateTime.UtcNow.AddDays(1);
foreach (var subscription in subscriptions.Take(1)) {
  //Returns the list of package deliveries for which this user has permissions for a specific subscription and a range of dates.
  var userPackageDeliveries = StandardExtractionsContext.UserPackageDeliveryOperations.GetUserPackageDeliveriesByDateRange(subscription.SubscriptionId, fromDate, toDate);
  //Output
  foreach (var userPackageDelivery in userPackageDeliveries) {
    Debug.WriteLine("{0} ({1} bytes)", userPackageDelivery.Name, userPackageDelivery.FileSizeBytes);
    using (var response = StandardExtractionsContext.UserPackageDeliveryOperations.GetReadStream(userPackageDelivery.PackageDeliveryId)) {
      using (var fileStream = File.Create("..\\" + userPackageDelivery.Name))
      response.Stream.CopyToAsync(fileStream).Wait();
    }
  }
}
dss-rest-apitick-history-rest-api
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

@singh5 - This is a private post

Considering your query, we moved it from the DSS to the TRTH forum, as Standard Extractions are part of the TRTH product. This is more appropriate, and will help people discover it. AHS

Hello @singh5,

Thank you for your participation in the forum.

Is the reply below satisfactory in resolving your query? If yes please click the 'Accept' text next to the appropriate reply. This will guide all community members who have a similar question. Otherwise please post again offering further insight into your question.

Thanks,

-AHS

Hello @singh5,

Please be informed that a reply has been verified as correct in answering the question, and has been marked as such.

Thanks,

-AHS

Upvotes
Accepted
13.7k 26 8 12

@singh5,

The code you pasted comes from the C# example application, from the Standard extractions section, sample Get my Package Deliveries by Date Range . I therefore conclude you are trying to download VBD (Venue By Day) files from TRTH, and will answer on that basis (if I am wrong, please correct me).

That particular sample lists the packages (i.e. files), but does not download them. If you run the next sample, Download My Package Deliveries, it shows in step 2 how to get the package delivery IDs, and in step 3 how to download the files using the IDs. You can see the HTTP code by clicking on HTTP on screen:

The HTTP call to get a package is a GET to an endpoint, using a URL that includes the desired package ID:

https://hosted.datascopeapi.reuters.com/RestApi/v1/StandardExtractions/UserPackageDeliveryGetUserPackageDeliveriesByPackageId(PackageId='0x04f21a8d13459cb1')

Our TRTH Java sample set does not contain code that demonstrates standard extractions.

There is a C# tutorial that explains the entire process all the way to the file downloads, but as that uses the SDK you cannot recreate that directly in Java, so it is of limited use to you, except for the explanations which might be of help.

But the TRTH REST API Tutorial 2 describes all the HTTP requests required to achieve what you want (the calls are also available in a downloadable Postman collection). Creating the same calls in Java is fairly easy, the Programming without SDK tutorial explains this, and gives hints and tips.

I hope this helps.


icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
32.2k 40 11 20

Hello @singh5,

For multiple examples of Java code to retrieve package deliveries see:

Java Code Examples in Datascope REST API Downloads.

These examples show the steps that constitute the Datascope REST workflow, request and receive the authentication token, submit the specific request with the valid token , wait for the completion of the request and receive the valid result. Several request types are shown for completeness.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
1 1 1 2

Hi @zoya.farberov,

Thanks for replying. I cannot find any API for Downloading the Package Delivery File in the DSS Documentation for the given FileId. Can you help with providing the Http Get/Post Request API for the same?

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Hello @singh5,

Perhaps I did not understand the question.

Are you working with VBDs? (Tick History APi area?)

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.