CURL ($curl) request using UiPath Studio Activities

Hi,

I have a few questions about CURL and CURL to Swagger in UiPath Studio:

  1. Is it possible to call $ curl commands from the level of activity available in UiPath Studio? Eg HTTP Request? If so, how?

Sample $ curl command:
curl login:password@localhost:8080/oauth/token -d grant_type=password -d username=robot -d system=robot

  1. Can I translate $ curl commands into ‘Request URL’ commands understood by Swagger in Swagger 'Try It out" mode?
    So that I can adapt them to my custom activities or in HTTP Request activity. If so, how?

@Adrian_Star

I doubt you can use the http request for curl but you can try with VB.net Invoke code activity . Please refer one of my posts below

1 Like

Thanks @Vishal_K for tip.

How to pass ‘login’ and ‘password’ in this VB.NET code as prefix before http://?
curl login:password@localhost:8080/

I have prepared something like this and I have response.

Dim client As HttpClient = New HttpClient()
client.BaseAddress = New Uri(“http://localhost:8080/my-app/”)
client.DefaultRequestHeaders.Accept.Clear()
client.DefaultRequestHeaders.Accept.Add(New MediaTypeWithQualityHeaderValue(“application/json”))
Dim request As MultipartFormDataContent = New MultipartFormDataContent()
request.Add(New StringContent(“password”), “grant_type”)
request.Add(New StringContent(“robot”), “username”)
request.Add(New StringContent(“robot”), “system”)
response = client.PostAsync(“oauth/token”, request).Result
If response.IsSuccessStatusCode Then
responseContent = response.Content
responseString = responseContent.ReadAsStringAsync.Result
Console.WriteLine(responseString)
Else
Console.WriteLine(("failed: " + response.Content.ReadAsStringAsync.Result))
End If

UiPath variables and arguments:

Respone:
image

@Adrian_Star

  1. Try running your endpoint in postman and make sure it works fine there.
  2. Add

client.DefaultRequestHeaders.Authorization = New AuthenticationHeaderValue(“Basic”, “ your hash code ”)

Get the has code (you can see in my post), where I used postman to get the hash code

Also did you try login:password @localhost:8080/my-app/ within base header

Please let me know if you still have issue

@Vishal_K

with this query I retrieve the authorization token (hash code):

curl login:password@localhost:8080/oauth/token -d grant_type=password -d username=robot -d system=robot

Therefore, the username and password are thrown into the query (login:password@local...).
Which further serves this Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9[...]

About Postman:
We do not use external tools such as POSTMAN or Chrome add-ons like Talend API Tester in my organization. Access is blocked.

I don’t have how to test it.

I did something like that in VB.NET code:
client.DefaultRequestHeaders.Authorization = New AuthenticationHeaderValue(“Basic”, “username:password”)
But query fails.
I need to read the documentation.

I have Response StatusCode 200 after passing this query:

Dim client As HttpClient = New HttpClient()
client.BaseAddress = New Uri(“http://localhost:8080/my-app/”)
client.DefaultRequestHeaders.Accept.Clear()
client.DefaultRequestHeaders.Accept.Add(New MediaTypeWithQualityHeaderValue(“application/json”))
Dim byteArray As Byte() = Encoding.ASCII.GetBytes(“username:password”)
client.DefaultRequestHeaders.Authorization = New AuthenticationHeaderValue(“Basic”, Convert.ToBase64String(byteArray))
Dim request As MultipartFormDataContent = New MultipartFormDataContent()
request.Add(New StringContent(“password”), “grant_type”)
request.Add(New StringContent(“robot”), “username”)
request.Add(New StringContent(“robot”), “system”)
response = client.PostAsync(“oauth/token”, request).Result
If response.IsSuccessStatusCode Then
responseContent = response.Content
responseString = responseContent.ReadAsStringAsync.Result
Console.WriteLine(responseString)
Else
Console.WriteLine(("failed: " + response.Content.ReadAsStringAsync.Result))
End If

which is the equivalent of CURL:
curl login:password@localhost:8080/oauth/token -d grant_type=password -d username=robot -d system=robot

image

Source of bold text: https://gist.github.com/bryanbarnard/8102915

Thanks for good advice @Vishal_K.

2 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.