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

session.Create()

Return Object

Session

Authorization Requirement

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

SessionCreateParams Fields

FieldDescription
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.
PartialSessionId
string
Identifier for a partially-completed login

Example Request

import (
    "fmt"
    "errors"

    files_sdk "github.com/Files-com/files-sdk-go/v3"
    "github.com/Files-com/files-sdk-go/v3/session"
)

session, err := session.Create(files_sdk.SessionCreateParams{Username: "username"})
if err != nil {
    var respErr files_sdk.ResponseError
    if errors.As(err, &respErr) {
        fmt.Println("Response Error Occurred (" + respErr.Type + "): " + respErr.ErrorMessage)
    } else {
        fmt.Printf("Unexpected Error: %s\n", err.Error())
    }
}

Delete user session (log out)

SDK Method

session.Delete

Return Object

No return value.

Authorization Requirement

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

Example Request

import (
    "fmt"
    "errors"

    files_sdk "github.com/Files-com/files-sdk-go/v3"
    "github.com/Files-com/files-sdk-go/v3/session"
)

err := session.Delete()
if err != nil {
    var respErr files_sdk.ResponseError
    if errors.As(err, &respErr) {
        fmt.Println("Response Error Occurred (" + respErr.Type + "): " + respErr.ErrorMessage)
    } else {
        fmt.Printf("Unexpected Error: %s\n", err.Error())
    }
}

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
ReadOnly
boolean
Is this session read only?
SftpInsecureCiphers
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.)