API POST request using UI Vision + Python

Continuing the discussion from Sending post-requests:

I understand I’m able to call Python with XRunAndWait to launch a script. I plan to use a simple python script to push an API POST request. However this request should have several variables that I need to push from UI Vision. For example a different link. So each loop would have ${link} (it changes) and I would want to push it into the python script each time it would execute.

How can I push UI Vision variable to python script variable be as an integer or string inside python script? Thanks!

Maybe this helps: You do not need to use Python. You can call any API directly from within Ui.Vision.

Or do you want/need to use Python? XRunAndWait supports command line parameters (3rd column in the table view). So you can send the values as command line parameters to Python.

1 Like

I mark it as solution as I see it works with other APIs but not with mine, however I will write in another thread to see if we could troubleshoot it, thanks for the answer!

Edit: When I switched to executeScript from executeScript_Sandbox - it worked!!! So strange, but it is all working now, so that’s great news.

Edit2: Okay so I was having a lot of trouble with the variables having “” marks for each string.

I was able to convert some variables to integers using executeScript_Sandbox return Number (${variable})

However could not find a way to make it work with strings to be added to the javascript without the quote marks. Could not find any info on Store command either. Does anyone maybe have any idea? The script works, just not with variables as it messes up the URL with adding “” for each variable on both start and end, resulting in wrongly formatted url.

Edit3: Solved my edit2 lol. So apparently I had to modify my string and wrap up the strings with “” and then + each variable from Ui Vision, this way the variables are treated as they are without quote marks and finally I got a fully working solution. Probably could delete it all and say solved, but actually this journey took me several hours so someone who is trying to do the same could potentially benefit too. Cheers!

1 Like

Exactly! Thanks a lot for posting this information.