I have a Curl command which I need to execute as a HTTP Request activity in a UiPath automation.
Below are details on the Curl command…
Command: configure user roles
Action: will assign all listed user roles to the existing users.
curl -X POST https:///pre_refresh_saas/configure_user_roles -k --header ““environment: ”” --data-binary “”@userroles.txt""
“userroles.txt” is an input file which lists user roles with three columns, example syntax role:username:active.
What are the correct steps to replicate this command in UiPath Studio?
Apparently, this doesn’t mean it has worked, has worked.
The output should something like this, when run from Curl…
11/06/2024 11:05:44 Post Refresh SaaS started for command configureUserRoles
11/06/2024 11:05:48 INFO: role Application Implementation Consultant for user FSPS_Service already assigned
11/06/2024 11:05:48 INFO: role Human Resource Specialist for user FSPS_Service already assigned
11/06/2024 11:05:49 INFO: role IT Security Manager for user FSPS_Service already assigned
11/06/2024 11:05:49 INFO: role Integration Specialist for user FSPS_Service already assigned
11/06/2024 11:05:49 Post Refresh SaaS finished
Using httpClient = New HttpClient(handler)
Using request = New HttpRequestMessage(New HttpMethod("POST"), "https://ourserver/post_refresh_saas/configure_user_roles")
request.Headers.TryAddWithoutValidation("environment", "anenviro")
request.Content = New StringContent("c:\temp\userroles.txt")
request.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/x-www-form-urlencoded")
Dim response = Await httpClient.SendAsync(request)
End Using
End Using
Do I pass via a “Invoke Code” activity or is there a better way?
It’s strange how the “curl to C# converter” set the ContentType to “application/x-www-form-urlencoded”.
I haven’t tried it yet.
Is there no way to send a *.txt as --data-binary from a HTTP Request activity?
Created “Invoke Code” activity in VB.NET added the following code…
Dim handler = New HttpClientHandler()
Using httpClient = New HttpClient(handler)
Using request = New HttpRequestMessage(New HttpMethod(“POST”), “https://ourserver/post_refresh_saas/configure_user_roles”)
request.Headers.TryAddWithoutValidation(“environment”, “anenviro”)
request.Content = New StringContent(“c:\temp\userroles.txt”)
request.Content.Headers.ContentType = MediaTypeHeaderValue.Parse(“application/x-www-form-urlencoded”)
Dim response = Await httpClient.SendAsync(request)
End Using
End Using
But it returns the following errors…
Error ERROR Validation Error No compiled code to run
error BC30205: End of statement expected. At line 7
error BC30002: Type ‘HttpClientHandler’ is not defined. At line 1
error BC30057: Too many arguments to ‘Public Overloads Sub New()’. At line 2
error BC36010: ‘Using’ operand of type ‘HttpClient’ must implement ‘System.IDisposable’. At line 2
error BC30002: Type ‘HttpRequestMessage’ is not defined. At line 3
error BC30002: Type ‘StringContent’ is not defined. At line 5
error BC30451: ‘MediaTypeHeaderValue’ is not declared. It may be inaccessible due to its protection level. At line 6
error BC37058: ‘Await’ can only be used within an Async method. Consider marking this method with the ‘Async’ modifier and changing its return type to ‘Task’. At line 7 FSPS_roles.xaml
To proceed forward, have a look at this general rewrite:
Dim handler As HttpClientHandler = New HttpClientHandler()
Using httpClient As System.Net.Http.HttpClient = New System.Net.Http.HttpClient(handler)
Using request As HttpRequestMessage = New HttpRequestMessage(New HttpMethod("POST2"), "https://ourserver/post_refresh_saas/configure_user_roles")
request.Headers.TryAddWithoutValidation("environment", "anenviro")
request.Content = New StringContent("c:\temp\userroles.txt")
request.Content.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/x-www-form-urlencoded")
Dim response As System.Threading.Tasks.Task(Of System.Net.Http.HttpResponseMessage) = httpClient.SendAsync(request)
End Using
End Using