Sessions

A Session is an operation that allows you to make further API calls using our REST API or SDKs as a specific user. This is the only way to use the API if you know a username/password but not an API key.

Sessions in the API and SDKs use the exact same mechanism (and work the same) as sessions in the web interface.

After creating a session, the Session object returned will include plenty of relevant information about the current user, often used to customize the interface or enable further automation.

Create user session (log in)

SDK Method

\Files\Model\Session::create;

Return Object

Session

Authorization Requirement

No authentication required; you may call this endpoint without a key or session.

Method Arguments

ArgumentDescription
username
string
Username to sign in as
password
string
Password for sign in
otp
string
If this user has a 2FA device, provide its OTP or code here.
partial_session_id
string
Identifier for a partially-completed login

Example Request

try {
  $session = \Files\Model\Session::create([
    'username' => "username"
  ]);
  // Operate on $session
} catch (\Files\NotAuthenticated\InvalidUsernameOrPasswordException $e) {
  echo 'Authentication Error Occurred (' . get_class($e) . '): ', $e->getMessage(), "\n";
} catch (\Files\FilesException $e) {
  echo 'Unknown Error Occurred (' . get_class($e) . '): ', $e->getMessage(), "\n";
}

Delete user session (log out)

SDK Method

\Files\Model\Session::delete;

Return Object

No return value.

Authorization Requirement

No authentication required; you may call this endpoint without a key or session.

Example Request

try {
  \Files\Model\Session::delete();
} catch (\Files\NotAuthenticated\InvalidUsernameOrPasswordException $e) {
  echo 'Authentication Error Occurred (' . get_class($e) . '): ', $e->getMessage(), "\n";
} catch (\Files\FilesException $e) {
  echo 'Unknown Error Occurred (' . get_class($e) . '): ', $e->getMessage(), "\n";
}

The Session Object

Some of the methods above return a Session object. The attributes of this object are listed below.

AttributeDescription
id
string
Session ID
language
string
Session language
read_only
boolean
Is this session read only?
sftp_insecure_ciphers
boolean
Are insecure SFTP ciphers allowed for this user? (If this is set to true, the site administrator has signaled that it is ok to use less secure SSH ciphers for this user.)