Session API
Session Capture API
Fetch timestamps for a session
Get the number of TLS exceptions for each host in a session
Get all sessions in your org
Optional Parameters
- <code class="dcode">?include_all={true|false}</code>: If <code class="dcode">true</code>, this will return both live (active) sessions and ended (inactive sessions). If this value is <code class="dcode">false</code>, only live sessions will be included. The default value is <code class="dcode">false</code>.
- <code class="dcode">?num_sessions={n}</code>: The number of sessions you want the API request to return, sorted by most recent. The default value is <code class="dcode">10</code>.
- <code class="dcode">?tag={key}:{value}</code>: Select sessions that contain the tag defined by tag key <code class="dcode">key</code> and tag value <code class="dcode">value</code>. Spaces in either the tag key or value may be represented using <code class="dcode">+</code>. For example, sessions containing the tag <code class="dcode">my example: this is an example tag</code> could be selected using the query argument <code class="dcode">?tag=my+example:this+is+an+example+tag</code>. This query argument may be provided multiple times to select sessions containing at least one of the tags provided.
- <code class="dcode">?next_token={value}</code>: Use this value as a start index to continue from a previous request.
Example
To get a list of the most recent 20 sessions, both active and inactive:
To get sessions containing at least one of the tags <code class="dcode">my:tag</code> or <code class="dcode">my other:example tag</code>:
Response
The response is a JSON object with the <code class="dcode">sessions</code> key, and it contains a list of sessions in your org matching the optional parameters <code class="dcode">include_all</code> and <code class="dcode">num_sessions</code>. For pagination, a <code class="dcode">next_token</code> value is also provided from which to continue in the next request.
NOTE: The last page may contain up to <code class="dcode">num_sessions</code> sessions and their <code class="dcode">next_token</code>. A response of <code class="dcode">{"sessions": [], "next_token": null}</code> indicates the end of the set matching the given query. The type of <code class="dcode">next_token</code> should be assumed to be a <code class="dcode">string</code> or <code class="dcode">null</code>.
Fetch timestamps for a session
Fetch all timestamps associated with capture for the target session.
Example
Response
If the request is successful, a <code class="dcode">HTTP 200 OK</code> response is returned with a JSON object containing key-value pairs for any available timestamps associated with the capture session ID.
A <code class="dcode">HTTP 404</code> response is returned if no timestamps are available or the session does not exist.
Create a session
To start a session on a device, you must first lock that device. Lock the device through the HeadSpin UI or using the Android Device API or iOS Device API. Browsers require starting and stopping a capture session using the HeadSpin Selenium capture capabilities. Please refer to Selenium Capabilities and Chrome DevTools.
Request Body
The request body must contain a JSON object with a minimum of:
Optional session configuration parameters:
Example
Response
If the request is successful, the response is a JSON object with details of the created session, including <code class="dcode">session_id</code>.
If the request fails, you may get:
- <code class="dcode">{"status": "Device is currently in use by someone else.", "status_code": 403}</code>: Someone else is currently using the device. Choose another device to create a session, or wait until this device is free.
- <code class="dcode">{"status": "Invalid device ID.", "status_code": 404}</code>: The device ID specified doesn't exist. Double check that the device ID is correct.
- <code class="dcode">{"status": "Device must be locked before capture.", "status_code": 403}</code>: The device must be locked by you before a session can be created. Lock the device through the HeadSpin UI or an API call.
The <code class="dcode">nowait</code> option may help if you run Espresso tests on a device and the Espresso test code itself calls the session start endpoint. The default <code class="dcode">nowait: false</code> value keeps the HTTP connection until the session starts; however, as network capture setup happens the device will temporarily disconnect from the network causing HTTP connections to disconnect, resulting in the start session request returning an error.
To avoid such a situation, you can use the <code class="dcode">nowait: true</code> option, which starts a capture session and immediately responds without waiting for the session to reach the ready state. Then, you can determine if the session is ready for testing by polling the <code class="dcode">timestamps</code> endpoint until requests return <code class="dcode">HTTP 200 OK</code>, indicating that the capture session is ready for testing. Note that errors may occur while polling the <code class="dcode">timestamps</code> endpoint since the device will temporarily disconnect from the network as it prepares for network capture. Such errors should be ignored and polling should continue until the <code class="dcode">HTTP 200 OK</code> response is received.
Actions for Hosts with TLS Exceptions
When using hosts with pinned TLS certificates, one of these two actions should be taken to enable accurate and comprehensive network capture:
- Add HeadSpin as a trusted cert per our documentation on Android Network Security Configuration, or
- Use HeadSpin's Instrumentation API to enable profiling for already built apps
If it is not possible to trust the HeadSpin cert or enable profiling via instrumentation, hosts with pinned TLS certificates may fail to establish secure connections with our network capture setup, which can cause TLS Exceptions and undesirable app performance degradations. To prevent this from affecting your tests, hosts experiencing TLS exceptions may be filtered from the network capture using the <code class="dcode">mitm_ignore</code> argument.
The <code class="dcode">mitm_ignore</code> argument accepts an array of ignored <code class="dcode">host:port</code> or <code class="dcode">ip:port</code> regex patterns. If just the host name is provided, all ports will be matched. These hosts are ignored from the network capture session.
Example usage may include the following: <code class="dcode">['abc\.example\.com:443', '.*\.mydomain.com']</code>
The <code class="dcode">network_keep_in_session_patterns</code> argument controls whether a destination <code class="dcode">host:port</code> (or <code class="dcode">ip:port</code>) is kept in the session after an error. Add glob patterns here to keep a destination with an error in the session, to continue to try to parse the network protocol for that destination.
Stop a session
Browsers require starting and stopping a capture session using the HeadSpin Selenium capture capabilities. Please refer to Selenium Capabilities and Chrome DevTools.
Request Body
The request body must be this JSON object:
Optional session configuration parameters:
Example
Response
- A <code class="dcode">HTTP 200 OK</code> response with <code class="dcode">{"msg": "Video uploaded to https://api-dev.headspin.io/v0/sessions/{session_id}.mp4"}</code> is returned. This message contains a link to the captured video. The name of the video is the session ID.
- A <code class="dcode">HTTP 500</code> response if the request fails. Check that you have the right JSON object in the request body.
- A <code class="dcode">HTTP 404</code> Not Found response if the request fails. Make sure that the session id in your request is valid.
The <code class="dcode">nowait</code> option may help if you run Espresso tests on a device and the Espresso test code calls the session stop endpoint. The default <code class="dcode">nowait: false</code> value will keep the HTTP connection until the session has completely ended. However, as the session ends and network capture terminates, the device disconnects from the network temporarily causing the request to fail with a network disconnect error. To avoid such a situation, you can use <code class="dcode">nowait: true</code> value to stop a capture session, but return a response immediately without waiting for the session to end completely. In this case, you can determine if the session has ended completely by polling the <code class="dcode">timestamps</code> endpoint until it returns a <code class="dcode">HTTP 200 OK</code> response and the body contains the <code class="dcode">capture-complete</code> key indicating that the capture session has ended completely. Note that errors may occurs while polling the <code class="dcode">timestamps</code> endpoint since the device will temporarily disconnect from the network as it terminates network capture. In this case, the error should be ignored and polling should continue until an <code class="dcode">HTTP 200 OK</code> response is received.
Delete a session
Permanently delete a session and all associated data. Use with caution!
Example
Response
- A <code class="dcode">HTTP 200 OK</code> response if the session was successfully deleted.
- A <code class="dcode">HTTP 409 Conflict</code> response if the session is still active and as a result cannot yet be deleted.
- A <code class="dcode">HTTP 500</code> response if the request fails. Make sure that the session id in your request is valid.
Get the number of TLS exceptions for each host in a session
Example
Response
The response is a JSON object where each key is a host name, and the value is the number of TLS exceptions for that host.
If the request contains an invalid session ID (such as one that doesn't exist), a <code class="dcode">404</code> response will be returned.
Import a Video Analysis Session
External videos in a MP4 container may be imported to create a HeadSpin video analysis session.
Example
To upload a video using <code class="dcode">curl</code>, use the <code class="dcode">--data-binary "@<path_to_your_mp4>"</code> syntax, for example <code class="dcode">--data-binary "@/Users/headspin/somevideo.mp4"</code>.
Response
Download Data for a Session
Download captured session data
Download a summary of session Issues
Retrieve the most significant Issue by Issue Burst
Get the session video metadata
Download captured session data
{ext} (extension) specifies what type of data to download for this session. Extension must be one of:
- <code class="dcode">mp4</code>: HeadSpin screen recording for this session. This extension supports a <code class="dcode">fps</code> query parameter with a positive integer value greater than 1 and less than 120. If the <code class="dcode">fps</code> parameters is provided, the screen recording video will be resampled to a constant frame rate at the specified frame rate.
- <code class="dcode">har</code>: Standardized HTTP message archive, containing all HTTP traffic content as a JSON object. This extension supports an <code class="dcode">enhanced</code> query parameter that (if <code class="dcode">True</code>) will enhance the HTTP message archive with the actual HTTP body content extracted from the binary network traffic capture. Entries can be temporally filtered by supplying a <code class="dcode">label_id</code> query parameter corresponding to a session label that spans the desired temporal range. Currently only supports HTTP/1.X.
- <code class="dcode">mar</code>: HeadSpin's variant of HTTP message archive, containing additional metadata. This is also a JSON object.
- <code class="dcode">csv</code>: <code class="dcode">mar</code> data in <code class="dcode">.csv</code> form
- <code class="dcode">pcap</code>: Binary network traffic capture. See Reading Network Packet Data.
- <code class="dcode">sslkeylog.txt</code>: TLS/SSL master secret key log for the pcap data. See Reading Network Packet Data.
- <code class="dcode">appium.log.gz</code> or <code class="dcode">appium.log</code>: Appium session log. The log is available for all sessions, including capture sessions and non-capture sessions.
- <code class="dcode">selenium.log.gz</code> or <code class="dcode">selenium.log</code>: Selenium driver session log. The log is available for all sessions, including capture sessions and non-capture sessions.
- <code class="dcode">device.log.gz</code> or <code class="dcode">device.log</code>: Device event log.
- <code class="dcode">jsconsole.log.gz</code> or <code class="dcode">jsconsole.log:</code> JavaScript console log. <code class="dcode">headspin:enableJSConsoleLog</code> capability collects them. Please read Appium Capabilities and Selenium Capabilities for more details about the capability. The log is available for all sessions, including capture sessions and non-capture sessions.
Examples
To save the downloaded data as files on your computer, use the flag -o {filepath} in your cURL commands.
To download the video screen recording:
To download the video screen recording resampled to a constant frame rate of 15 frames per second:
To download the enhanced HAR data containing request and response bodies for HTTP/1.X traffic:
To download the <code class="dcode">pcap</code> data:
To download the TLS/SSL master secret:
To download the Appium log:
To download the Selenium driver log:
To download the device log:
To download the device log:
Response
The response is a stream of the content of the data file. To save the data into a file on your disk, use the <code class="dcode">-o {filepath}</code> flag in your <code class="dcode">cURL</code> request.
Reading Network Packet Data
The downloaded packet capture (PCAP) is binary data, with the network traffic encrypted using TLS/SSL. To read this data, you must use a tool that can read <code class="dcode">pcap</code> packets, and decrypt the traffic data with the <code class="dcode">sslkeylog.txt</code> file. To do this:
- Download Wireshark.
- Open Wireshark. In Wireshark, open the pcap file with <code class="dcode">File > Open</code>, and select the <code class="dcode">pcap</code> file.
- Next, you'll need to speciy the key log file. Go to <code class="dcode">Wireshark > Preferences > Protocols > TLS</code>.
- In <code class="dcode">(Pre)-Master-Secret log filename</code>, select the downloaded <code class="dcode">sslkeylog.txt</code> file.
- The traffic data should now be decrypted. You can read the <code class="dcode">pcap</code> data in Wireshark.
Alternatively, you can open and decrypt a pcap directly using the <code class="dcode">wireshark</code> command line interface with wireshark <code class="dcode">-o ssl.keylog_file:path/to/sslkeylog.txt path/to/file.pcap,/code>.
Download a summary of session Issues
This data is the same as that shown in the Waterfall UI issue card.
Optional Parameters
- <code class="dcode">orient</code>: This parameter can have the value <code class="dcode">column</code> (default) or <code class="dcode">record</code>. This specifies the return format of the data:
- The <code class="dcode">column</code> orientation outputs the data by Issue category and then by column of data available for that issue (e.g. Status, Impact Time, Content Type...).
- The <code class="dcode">record</code> orientation outputs the data by Issue category and then by each instance of the issue.
Example
To get the data by issue category and by issue:
Response
Example of a column response:
Example of a record response:
Retrieve the most significant Issue by Issue Burst
This endpoint is deprecated since November 2019. Please use the Retrieve a summary of issues endpoint instead.
Get the session video metadata
Example
Response
If the session video has audio:
If the session video does not have audio:
Session Time Series Data
Retrieve Available Session Time Series
Retrieve Available Session Time Series
Examples
To save the retrieved data as files on your computer, use the flag <code class="dcode">-o {filepath}</code> in your <code class="dcoed">cURL</code> commands.
To output the dictionary to a file, use the following:
Response
The response is a json dictionary of attributes for all available time series classes (in a given session). This dictionary contains a mapping of time_series_key -> time_series_name, time_series_category, and time_series_units.
Download Session Time Series
Required Parameters
The <code class="dcode">key</code> parameter is used to retrieve data for that particular time series.
Examples
To save the retrieved data as files on your computer, use the flag <code class="dcode">-o {filepath}</code> in your <code class="dcode">cURL</code> commands.
To output to a file (i.e. a csv), use the following:
Response
The response is the time series data for a particular time series and session in CSV format.