cancel
Showing results for 
Search instead for 
Did you mean: 

Using Network Credentials in BP Web API

SamuelEzeala
Level 2
Hi Guys, 
I am having difficulty calling an API on Blue Prism. the API uses network Credentials. In C#, the code below does the job for me, But am unable to archive same using the Web API Services on Blue Prism. 

Please is they any work around it, or do i have to write a custom object for this purpose?


Thanks.

    var _data = new Data();
    var userName = _username;
    var password = _password;

            
    var credentials = new NetworkCredential(userName, password);
    using (var httpClient = new HttpClient(new HttpClientHandler { Credentials = credentials }))
            {
              
                httpClient.DefaultRequestHeaders.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/json;odata=verbose"));
                var response = await httpClient.GetAsync(endpointUrl2);

                if (response.IsSuccessStatusCode)
                {

                    string apiResponse = await response.Content.ReadAsStringAsync();
                    _data = JsonConvert.DeserializeObject<Data>(apiResponse);
                }
            }​


------------------------------
Samuel Ezeala
Software Engineer | RPA Developer
eProcess, Ecobank Group
Lagos, Nigeria
------------------------------
Samuel Ezeala Software Engineer | RPA Developer eProcess, Ecobank Group Lagos, Nigeria
10 REPLIES 10

ewilson
Staff
Staff
The NetworkCredentials class supports a couple different authentication schemes including basic, digest, NTLM, and Kerberos. Do you know what specific scheme is being used in your network?

The WebAPI services feature supports HTTP Basic, token, OAuth2 Client, and OAuth2 JWT. If your network/web service is just using HTTP Basic, you should be good. There is an option to pre-send the authentication request as opposed to the traditional challenge/response format, so that may be something to consider.

Cheers,



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

@ewilson, can you please give an example of such an option? I have similar case with as posted above. I'm using NTLM scheme. So far I' ve been using a code stage, but I would like to know if  it is possible to use the embedded Web API in this case.

------------------------------
Tomasz Sukiennik
RPA Developer
Digital Teammates
Europe/Lodz
------------------------------

@Tomasz Sukiennik I don't believe you'll be able to use the Web API feature unless you implement a different form of authentication in the web service itself. In other words, if you set it up to use an OAuth2 provider, a bearer token scheme, or even HTTP Basic (which is generally not recommended as it's not very secure)  then you could use the Web API feature.

If you have to use NTLM for the authentication against the web service then I think you're stuck with doing it via the code stage you have.

Cheers,


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

Thanks for response Eric.

Kind regards


------------------------------
Tomasz Sukiennik
RPA Developer
Digital Teammates
Europe/Lodz
------------------------------

GoranRosander
Level 2

Hi, i cant use this, compile error for NetworkCredential? I have reference to System.Net in code option?

string GetsalesagentbySalesID(string salesId,string userName,string password,string url,string salesId)
{
try
{
// Initialization.
responseObj = string.Empty;
//...
//Inparameters
//userName
//password
//url
//salesId
var credentials = new NetworkCredential(userName, password);
// Posting.
using (var httpClient = new HttpClient(new HttpClientHandler { Credentials = credentials }))
{
// Setting content type.
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
//...
// Initialization.

// HTTP POST
var response = httpClient.GetAsync(url + salesId);

// Verification
if (response.IsSuccessStatusCode)
{
responseObj = response.Result.Content.ReadAsStringAsync().Result;
}
}

return responseObj;
}
catch
{
return "Error";
}
}



------------------------------
Goran Rosander
------------------------------

Hi Goran,

have you included an "External Reference" to "System.Net.Http.dll"?



------------------------------
Tobias Arnold
RPA Developer
ITERGO GmbH
Europe/Duesseldorf
------------------------------

Yes but i find that the .Net Framework is 4.0 and it must be 4.5 to use HttpClient



------------------------------
Goran Rosander
------------------------------

Hi @Tomasz Sukiennik, would you mind sharing the code that you use for NTLM authentication in BP? I have been trying to get several codes to work (including the one posted above by Samuel Ezeala), but I'm getting an error message indicating that asynchronous calls are not working in BP.

Any guidance that you can provide would be much appreciated! Thanks a lot!



------------------------------
Martina Kralova
------------------------------
Martina Kralova RPA Developer Cannypack Europe/Bratislava

Hi @Tomasz Sukiennik,

Can you share the code that you use for NTLM authentication in BP? I am facing the same issue.

@Eric Wilson: Since this thread is a bit long, is this been implemented somehow in Web APIs now, or do you have any code for the same in BP?

Thanks a lot in advance :)​​​

------------------------------
Manish Rawat
Project Manager
Mercer
New Delhi
------------------------------