Blue Prism Product

last person joined: 11 hours ago 

Chat about Blue Prism products
Expand all | Collapse all

How to download a file using web api.

  • 1.  How to download a file using web api.

    Posted 04-25-2020 13:24
    I want to download a file using Web API. After making request we are getting File data as text in the response content data item.

    For your reference I am getting the response as below as text type.

    %PDF-1.4 %����
    68 0 obj <</Linearized 1/L 1850803/O 70/E 262535/N 13/T 1849323/H [ 916 320]>> endobj
    xref
    68 31
    0000000016 00000 n
    0000001236 00000 n
    0000001456 00000 n
    0000001821 00000 n
    0000001957 00000 n
    0000002087 00000 n
    0000002229 00000 n
    0000002972 00000 n
    0000003602 00000 n
    0000004428 00000 n
    0000005000 00000 n
    0000005715 00000 n

    I am not adding all the content here.

    How can we save this content as a original file.

    Please help, its an urgent.

    Thanks
    K

    ------------------------------
    A Z
    ------------------------------


  • 2.  RE: How to download a file using web api.

    Posted 04-26-2020 00:41
    Unfortunately, binary streams are not supported as a return type of a Web API service. They only return string data. This has been raised with product as a limitation of the feature and should be addressed in a future release.

    In the meantime, I would suggest using a code stage and something like the .NET HttpClient class to retrieve your file.

    Cheers,

    ------------------------------
    Eric Wilson
    Director, Partner Integrations for Digital Exchange
    Blue Prism
    ------------------------------



  • 3.  RE: How to download a file using web api.

    Posted 09-18-2020 12:57
    Hi Eric and Blue Prism support team,

    I am trying to download PDF file in Box using BP Web API.

    Does the Web API limitation still persists in BP 6.4? or it has been fixed already.
    Please, can you provide instruction on where to add the .Net Code in Web API and how to handle the Response.

    var client = new RestClient("https://api.box.com/2.0/files/71*****************/content");
    client.Timeout = -1;
    var request = new RestRequest(Method.GET);
    request.AddHeader("Authorization", "Bearer *********************");
    request.AddHeader("Cookie", "box_visitor_id=*******************");
    IRestResponse response = client.Execute(request);
    Console.WriteLine(response.Content);

    Thanks,
    Michael



    ------------------------------
    Michael Ng
    ------------------------------



  • 4.  RE: How to download a file using web api.

    Posted 09-18-2020 14:32
    Hi ​Michael,

    Box supports several different integration options. The two that probably make the most sense for Blue Prism are their REST interface and their .NET SDK. Since you're wanting to download binary content from Box, a PDF in this example, you won't be able to use the Web API feature of Blue Prism. However, you can still integrate with Box's REST API using a new version of the HttpClient VBO, or you can use Code stages if you want to work through their .NET SDK.

    Give me a few minutes and I will post the updated HttpClient VBO which now includes a method called "Http Request File". With this you'll be able to download a PDF and write it to disk.

    Cheers,

    ------------------------------
    Eric Wilson
    Director, Partner Integrations for Digital Exchange
    Blue Prism
    ------------------------------



  • 5.  RE: How to download a file using web api.

    Posted 09-18-2020 14:51
    Edited by Eric Wilson 09-18-2020 15:48
      |   view attached
    Michael,

    See the attached VBO. There is a new method called 'HTTP Request File'. You can use that to download your PDF from Box. This is also being added to the DX.

    Here's what I believe the set up for the 'HTTP Request File' call would look like in your scenario:


    The Collection called 'CustomHeaders' holds the definition of the Cookie header in your example:


    Cheers,

    ------------------------------
    Eric Wilson
    Director, Partner Integrations for Digital Exchange
    Blue Prism
    ------------------------------

    Attachment(s)



  • 6.  RE: How to download a file using web api.

    Posted 09-20-2020 22:00
      |   view attached
    Thank you Eric for the HTTP Request File Object.
    I was able to download file using your object on REST API with Basic Authentication.
    However, I had to make a small code change in your code to connect to Box Integration (Oauth 2.0).
    Bearer token is only good for one hour. Need to figure it a way to generate new Bearer token using client_id and client_secrete every request.
    Box provided javascript code to generate new token (Find attached) Now, I need to convert it from javascript to VB and incorporate it to Request File Object.   https://developer.box.com/guides/tooling/postman/quick-start/.

    Try
    Dim request As WebRequest = WebRequest.Create(addressURL)
    If forcePreAuth Then
    'Sometimes a web server will require the authorisation header in the initial request
    'In which case we have to add the basic authorization header manually.
    Dim bytes() As Byte = System.Text.Encoding.UTF8.GetBytes(String.Format("{0}:{1}",username,password))
    Dim base64 As String = Convert.ToBase64String(bytes)

    'For Basic Authorization
    'request.Headers.Add("Authorization", "Basic " & base64)

    ' Box doesn't support Basic Authentication. 
    'Have to use Oauth2, Bearer token is only good for one hour. Need to figure it a way to generate new Bearer token using client_id and client_secrete every request
    request.Headers.Add("Authorization", ": Bearer *token************************************")


    ------------------------------
    Michael Ng
    ------------------------------

    Attachment(s)



  • 7.  RE: How to download a file using web api.

    Posted 09-21-2020 07:56
    Ah, that example is from a Postman collection for Box, so it might be a little difficult to translate to VB because of some of the Postman-specific objects. If you have trouble with it, let me know and I'll spend some time looking it over.

    Cheers,

    ------------------------------
    Eric Wilson
    Director, Partner Integrations for Digital Exchange
    Blue Prism
    ------------------------------



  • 8.  RE: How to download a file using web api.

    Posted 11-20-2020 10:32
    Hi,
    I have a similar case. I am trying to download a (pdf) file using this object, but authorization is via baerar token.
    how can i use this object? possibly is there any ready-made solution?


    ------------------------------
    Marcin Grzelak
    RPA Developer
    Open Life TU Życie S.A.
    Europe/Warsaw
    ------------------------------



  • 9.  RE: How to download a file using web api.

    Posted 11-20-2020 10:39
    @Marcin Grzelak are you talking about plain bearer token where you already have the token (aka API key) and it just needs to be added to an authentication header? Or are you referring to something like OAuth2 JWT?

    Cheers,


    ------------------------------
    Eric Wilson
    Director, Partner Integrations for Digital Exchange
    Blue Prism
    ------------------------------



  • 10.  RE: How to download a file using web api.

    Posted 11-20-2020 10:43
    yes, I mean about plain bearer token. I already have the token.

    ------------------------------
    Marcin Grzelak
    RPA Developer
    Open Life TU Życie S.A.
    Europe/Warsaw
    ------------------------------



  • 11.  RE: How to download a file using web api.

    Posted 11-20-2020 10:55
    If you open the VBO and go to the HTTP Request File action, you should be able to add the following code to include a bearer token header in your request instead of HTTP Basic Auth. Please note, THIS IS A TOTAL HACK. This is a quick fix to address your question. You would need to either define a new input parameter called "token" and pass in your token value or you could just hardcode it in the VB. Ultimately, if you want something maintainable and flexible you'd adjust this code to possibly include a flag to discern between using HTTP Basic or Bearer auth.

    Hopefully that makes sense? I'll add an item to our backlog to update the published VBO to include this capability.


    Cheers,

    ------------------------------
    Eric Wilson
    Director, Partner Integrations for Digital Exchange
    Blue Prism
    ------------------------------



Share