How to use curl script in UiPath

Hi,

i have to change the status in jira but i unable to update using jira fields so i searched on net about how to chnage status using api call.
so found below document which is having curl commands
and i dont have any idea how to use that in uipath .
please explain how to use this so ican try.

below is the full command

curl -u username:password -X POST --data ‘{“transition”:{“id”:“11”}}’ -H “Content-Type: application/json” http://jira/rest/api/2/issue/TEST-1/transitions

Kindly check doc link also.
@Adrian_Star @Vishal_K

Hi,
Have you read my post?

First you need to get information about the issue and find out what possible transitions are available, then you have to make the transitions one by one according to the available hierarchy - just like a human does.

Yes checked . but not understod fully.
can we update status also by this ?
here are my pics of jira , status workflow and jason


2

Try to invoke C# code (I don’t know is it suitable).
This is cUrl to C# code using RestSharp library (You can download it from the Package Manager in UiPath. NuGet link for preview: NuGet Gallery | RestSharp 106.11.7)

var client = new RestSharp.RestClient("http://jira/rest/api/2/issue/TEST-1/transitions");
client.Timeout = -1;
var request = new RestSharp.RestRequest(Method.POST);
var base64authorization = Convert.ToBase64String(Encoding.ASCII.GetBytes(username +":"+password));
request.AddHeader("Authorization", $"Basic {base64authorization}"); // or ("Authorization", String.Format("Basic {0}",base64authorization))
request.AddHeader("Content-Type", "application/json");
request.AddJsonBody("{""transition"":{""id"":""11""}}");
response = client.Execute(request);

An easy way to look at an ID transition is: hover your mouse over the transition (action) button and see what number is next to the action in the bar at the bottom of the browser.
image
Then you just need to find this transition ID after geting the Issue details by Jira GET Issue.

i am trying ur code using postman can u tell me i am doing right or wrong ?
here are the screenshots




i have my username and password with me for jira.
but dont know where to update in postman with respect to ur code and i have token generated by pistman.
kindly suggest if i have put wrong values , and what need to be change

I’m not familiar with postman, but the authentication header you should rather add in the Authentication tab and choose the Basic method (type).

yes checked with that also but still some issue checking …

I think all you can do with curl you can also do with the http client activity, it would be a clean solution to use that in your project.

I have transitions done like this:

Jira Get Issue Transitions:

Additional in Arguments:
ProjectKey As String = eg.: “ABC-1234”

'Create a new HTTP request
Dim client  As HttpClient =  New HttpClient()

'Specify the target address
client.BaseAddress =  New Uri(uri)  'argument IN

'Clear header for new iteration
client.DefaultRequestHeaders.Accept.Clear()

'Enter new header parameters
client.DefaultRequestHeaders.Accept.Add( New MediaTypeWithQualityHeaderValue( "application/json" ))
client.DefaultRequestHeaders.Authorization =  New AuthenticationHeaderValue(“Basic”, token)

'Create query parameters
Dim request  As HttpRequestMessage =  New HttpRequestMessage (HttpMethod.Get,  ("rest/api/2/issue/" +ProjectKey+ "/transitions" ) '(Method type, relative access path)

'No Body of the query

'Indicate the service from which to reply to the inquiry
response = client.SendAsync(request).Result

Next:
Deserialize JSON from response.Content.ReadAsStringAsync.Result to Response_JsonObject

Next:
Build Data Table with 1 column ( ID As Int32)
For each transition in Response_JsonObject("transitions")
Assign: id = transition.Item("id").ToString
Add id to Data Row

Next:
Sort ascending Data Table

Next:
I have used swith activity and when I have specific ID’s then I set new status_ID:
image

Then:
Post New Transition
Jira Do Issue Transition:

'Create a new HTTP request
Dim client As HttpClient = New HttpClient()
'Specify the target address
client.BaseAddress = New Uri(uri) 'argument IN

'Clear header for new iteration
client.DefaultRequestHeaders.Accept.Clear()

'Enter new header parameters
client.DefaultRequestHeaders.Accept.Add( New MediaTypeWithQualityHeaderValue( "application/json" ))
client.DefaultRequestHeaders.Authorization = New AuthenticationHeaderValue(“Basic”, token)

'Create query parameters
Dim request As HttpRequestMessage = New HttpRequestMessage (HttpMethod.Post, ("rest/api/2/issue/" +ProjectKey+ "/transitions" ) '(Method type, relative access path)

'Body of the query
request.Content = New StringContent(JsonString, System.Text.Encoding.UTF8, "application/json" )

'Indicate the service from which to reply to the inquiry
response = client.SendAsync(request).Result

Hi,

i have downloaded package as suggested and using invoke code .
some errors i am getting please find below screenshots.



Hi,
Add ‘RestSharp’ to imports:

image

Specify invoked language in Activity propoerties:
image

StringContent: you can escape " with double "":
image

Or pass values as atributes to invoked code:

My C# Code from some webservice:
image

Hi have done modifications suggested by u
please check these screenshots .still some error in restsharp


2
3
4

passed values for username and password in default section

Declare variables as new in lowercase notation in C# (case sensitive):

image

Authorization line write as:

("Authorization", String.Format("Basic {0}",base64authorization)

modified as per suggestion . now no error is showing in code but what is these error
check below screenshots



3

Remove: ' from string:
image

not understood.is i have to remove StringContent ?

understood removed but giving error as ’ ’ expected.
some error is line 6 i guess
1
@Adrian_Star

Okay, let’s do it differently.
I have it done like this:

Build a dictionary and then convert it to JSON String. Pass Json_String as argument to C# code.

Json_String = Newtonsoft.Json.JsonConvert.SerializeObject(your_dict)

Set of useful Microsoft Activities:
image

created workflow as u suggested.
what more changes are required kindly suggest.
1


Edit C# code:

Replace:

request.Content = new StringContent("{""transition"":{""id"":""11""}}");

To:

request.Content = new StringContent(JsonString);

In your code it will be:
image

request.Content = new StringContent(transition);