Http request set Variable

Hello can someone tell me how to write the variable at request. I already have many failed attempts.
It should always be listed the last month period when we start Uipathstudio. Variable value I have already written and works.


Hi,

Can you try to use Parameters property in Properties panel?

Regards,

I have only one variable. Do you think I should make 2 variables?

Hi,

Do you think I should make 2 variables?

Yes, it’s better I think.
If your string is "from=2021-12-01&to=2021-12-31", we can extract each value as the following expression.

mc = System.Text.RegularExpressions.Regex.Matches(yourStr,"\d{4}-\d{2}-\d{2}")

Then

mc(0).Value
mc(1).Value

Note: mc is MatchCollection Type

OR directly

System.Text.RegularExpressions.Regex.Matches(yourStr,"\d{4}-\d{2}-\d{2}")(0).Value
System.Text.RegularExpressions.Regex.Matches(yourStr,"\d{4}-\d{2}-\d{2}")(1).Value

Regards,

Sorry I dont understand. I have no experience with regex. Should I write it in Parameters or in assign activity?

Hi,

Alright. Can you try the following steps?

First, assign each value to variable (Let’s say strFromVar and strToVar) using Assign activity.

strFromVar=System.Text.RegularExpressions.Regex.Matches(yourStr,"\d{4}-\d{2}-\d{2}")(0).Value

strToVar=System.Text.RegularExpressions.Regex.Matches(yourStr,"\d{4}-\d{2}-\d{2}")(1).Value

Next, check content of the variable using WriteLine activity, if necessary.

Finally, set Parameters property of HTTP Request as the following

Regards,


Ok. what do you mean with yourStr?
What should I write there?

Hi,

This will be str_Period. However, I just found you make this variable from the expression in your first post. (Sorry, I didn’t notice it.) So, the following is better.

strFromVar = new DateTime(Now.Year,Now.Month,1).AddMonths(-1).ToString("yyyy-MM-dd")
strToVar = new DateTime(Now.Year,Now.Month,1).AddDays(-1).ToString("yyyy-MM-dd")

Regards,

Thank you for the answers. I tried both of them also with regex. But I get the same error. Maybe you know how I write it this variable Parameters on the Endpoint? I only get the information if I write the date manually on the endpoint:((

Hi,

Unfortunately, HTTP request wizard doesn’t support variable.
So first you need to check it using static value with the wizard.
if it works well, next, set variable and test by actual run(debug).

End point will be https://..........api/v1/activities
and for now set Parameters like the following as not URLSegment but GetOrPost.

|Name|Value     |Type     |
|from|2021-12-01|GetOrPost|
|to  |2021-12-31|GetOrPost|

Regards,

Unfortunately, it did not work. It only works when I write it like this at Endpoint: https://…com/api/activities?from=2021-12-01&to=2021-12-31&
I should not write a date in Value. when we start Uipath studio it should automatically check today’s date, and only list previous month period. for example if we are now in month January the request should automatically check last month in case December.


Hi,

As I mentioned,

Unfortunately, HTTP request wizard doesn’t support variable.

So, first can you try like the following?

Regards,

Oh sorry! yes It works like this

Hi,

If it works well, can you try to modify Parameter property in Property panel (not Wizard)?

from

to

Then run as debug and check if it works

Regards,

ok it’s weird but it works!But you must not touch the Http request after that. if I open the wizard again then no longer works. After that you have to do the same again. But I don’t touch there anymore :)) Thanks for the help. that was the solution

1 Like

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