Session API

/v1/session starts and ends a session.

HTTP Methods

Security

See Also

Format

The following API are available:

Session: POST

Session: DELETE

Purpose Method URL
Start a session POST https://zvm_ip:port/v1/session/Add
End a session DELETE https://zvm_ip:port/v1/session

HTTP Methods

POST, DELETE

Security

The API is exposed over HTTPS. Client code must use the x-zerto-session HTTP authorization header when ending a session.

See Also

Starting a session: Session: POST

Format

Json, XML

Session: POST

Sets up an authenticated session for the Zerto RESTful API.

URL
Start session https://zvm_ip:port/v1/session/Add

Where:

zvm_ip The IP address of the Zerto Virtual Manager where the API is run.
port The port to access the Zerto Virtual Manager. The default port is 9669.
Response In Json Format

The response body is empty.

Session: DELETE

Ends a session for the Zerto RESTful API.

Note: If a session is dormant for thirty minutes the session is automatically terminated.
URL
End session https://zvm_ip:port/v1/session

Where:

zvm_ip The IP address of the Zerto Virtual Manager where the API is run.
port The port to access the Zerto Virtual Manager. The default port is 9669.
Request Body Using Json Format

The request body is empty.

Response In Json Format

The response body is empty.

PowerShell Samples
Starting a Session with VMware vCenter Server or Microsoft SCVMM Credentials

The following code sample shows how to start a session with VMware vCenter Server or Microsoft SCVMM authentication.

$strZVMIP = "{ZVM IP}"
$strZVMPort = "{ZVM HTTPS port}"
$strZVMUser = "{ZVM user}"
$strZVMPwd = "{ZVM user password}"
## Perform authentication so that Zerto APIs can run. Return a session identifier that needs to be inserted in the header for subsequent requests.
function getxZertoSession ($userName, $password){
  $baseURL = "https://" + $strZVMIP + ":"+$strZVMPort
  $xZertoSessionURL = $baseURL +"/v1/session/add"
  $authInfo = ("{0}: {1}" -f $userName,$password)
  $authInfo = [System.Text.Encoding]::UTF8.GetBytes($authInfo)
  $authInfo = [System.Convert]::ToBase64String($authInfo)
  $headers = @{Authorization=("Basic {0}" -f $authInfo)}
  $contentType = "application/json"
  $xZertoSessionResponse = Invoke-WebRequest -Uri $xZertoSessionURL -Headers $headers -Method POST -Body $body -ContentType $contentType
    #$xZertoSessionResponse = Invoke-WebRequest -Uri $xZertoSessionURL -Headers $headers -Body $body -Method POST
    return $xZertoSessionResponse.headers.get_item("x-zerto-session")
}
#Extract x-zerto-session from the response, and add it to the actual API:
$xZertoSession = getxZertoSession $strZVMUser $strZVMPwd
$zertoSessionHeader = @{"x-zerto-session"=$xZertoSession}

Starting a Session with Windows Credentials

To start a session with Windows authentication, replace the line in the above code:

String loginType = args.Length > 4 ? args[4] : "1";

with:

String loginType = args.Length > 4 ? args[4] : "0";

Ending a Session

The following code sample shows how to end a session:

private void LogOut() {
  String addSessionUri = m_baseAddress + "/session";
  HttpWebRequest request = WebRequest.Create(addSessionUri) as HttpWebRequest;
  //logging-out is about DELETING a session, with the DELETE http command
  request.Method = "DELETE";
  request.Timeout = 10000;
  //you need to set the id of the session to be deleted --> logged-out
  request.Headers.Add(c_authorizationHeader, m_sessionId);
  HttpWebResponse httpResponse = request.GetResponse() as HttpWebResponse;
  if (httpResponse.StatusCode == HttpStatusCode.OK) {
    m_sessionId = String.Empty;
    Console.WriteLine("\nLogged out - by deleting the session");
  }
  else {
    Console.WriteLine("Request {0} failed with code: {1}, {2}", request, httpResponse.StatusCode, httpResponse.StatusDescription);
  }
}