Automating Xray UI Actions with API Calls

Angello Maggio
2018-11-28 22:35

How to use API calls to trigger UI actions that are not in the Xray REST API documentation
You can use your browser's developer console to catch calls to different actions made in the UI to format your own cURL call for automation.

On our task to automate DevOps pipeline we must sometimes look for creative ways to perform certain tasks that may not be automate-able by nature. One example of this is our offline Xray sync.
For the offline sync we must manually click on  "Generate Download Command" to get the command to download the sync, and once that's finished we must click on "Upload local update". This is sometimes too uch human-dependent interactions and would slow down certain automatic deployments. Luckily we have a way to get these actions as calls.


For example on Chrome we open developer tools and go to the Network tab.
Then we click on the action we want the API for, in this case "Generate Download Command", and we'll see it there.

On the request headers we see it's a GET request to /ui/db/sync/generate and on the Response tab we can see the expected output.

Putting it all together we got our cURL command:

curl -u<user>:<password> "http://<hostname>:<port>/ui/db/sync/generate"

For "Upload local update", we do the same and get:

POST /ui/update
HTTP/1.1 Host: <hostName>:<port>
Connection: keep-alive
Content-Length: 0
Accept: application/json, text/plain

Which we can make into a cURL command to get the following:

 curl -X POST -uadmin:password "http://<host>:<port>/ui/update" 
*   Trying 1*******...
* Connected to ******* (*******) port ***** (#0)
* Server auth using Basic with user 'admin'
> POST /ui/update HTTP/1.1
> Host: ****:*****
> Authorization: Basic *****
> User-Agent: curl/7.47.0
> Accept: */*

< HTTP/1.1 200 OK
< Date: Tue, 07 Aug 2018 19:00:10 GMT
< Content-Length: 32
< Content-Type: text/plain; charset=utf-8

* Connection #0 to ***** left intact
{"info":"Local updates started"}