Summary

The sessions() GraphQL query provides a paginated list of all current sessions.

API Stability Long-Term

Syntax

graphql
sessions(
      searchFilter: String,
      level: Sessions__Filter_Level = Organization,
      sortBy: Sessions__SortBy = LastActivityTime,
      orderBy: OrderBy = ASC,
      skip: Int = 0,
      limit: Int = 50,
      onlyActiveSessions: Boolean = true
   ): SessionQueryResultSet!

Provide any text on which to search for sessions, indicate whether to include only active ones, whether to filter at organization or user level, how to sort and order results, and the number of results to skip and how many to return. See the Input Parameters section for more details.

Returns a non-nullable SessionQueryResultSet! object. The table below lists all fields.

Example

Raw
graphql
query{
  sessions(
    searchFilter: "company.com"
    limit: 10
    skip: 0
    onlyActiveSessions: false 
    level: Organization
    sortBy: User
    orderBy: DESC
  )
  {totalResults, results {id, user{username}}}
}
Mac OS or Linux (curl)
shell
curl -v -X POST $YOUR_LOGSCALE_URL/graphql \
    -H "Authorization: Bearer $TOKEN" \
    -H "Content-Type: application/json" \
    -d @- << EOF
{"query" : "query{
  sessions(
    searchFilter: \"company.com\"
    limit: 10
    skip: 0
    onlyActiveSessions: false 
    level: Organization
    sortBy: User
    orderBy: DESC
  )
  {totalResults, results {id, user{username}}}
}"
}
EOF
Mac OS or Linux (curl) One-line
shell
curl -v -X POST $YOUR_LOGSCALE_URL/graphql \
    -H "Authorization: Bearer $TOKEN" \
    -H "Content-Type: application/json" \
    -d @- << EOF
{"query" : "query{
  sessions(
    searchFilter: \"company.com\"
    limit: 10
    skip: 0
    onlyActiveSessions: false 
    level: Organization
    sortBy: User
    orderBy: DESC
  )
  {totalResults, results {id, user{username}}}
}"
}
EOF
Windows Cmd and curl
shell
curl -v -X POST $YOUR_LOGSCALE_URL/graphql ^
    -H "Authorization: Bearer $TOKEN" ^
    -H "Content-Type: application/json" ^
    -d @'{"query" : "query{ ^
  sessions( ^
    searchFilter: \"company.com\" ^
    limit: 10 ^
    skip: 0 ^
    onlyActiveSessions: false  ^
    level: Organization ^
    sortBy: User ^
    orderBy: DESC ^
  ) ^
  {totalResults, results {id, user{username}}} ^
}" ^
} '
Windows Powershell and curl
powershell
curl.exe -X POST 
    -H "Authorization: Bearer $TOKEN"
    -H "Content-Type: application/json"
    -d '{"query" : "query{
  sessions(
    searchFilter: \"company.com\"
    limit: 10
    skip: 0
    onlyActiveSessions: false 
    level: Organization
    sortBy: User
    orderBy: DESC
  )
  {totalResults, results {id, user{username}}}
}"
}'
    "$YOUR_LOGSCALE_URL/graphql"
Perl
perl
#!/usr/bin/perl

use HTTP::Request;
use LWP;

my $TOKEN = "TOKEN";

my $uri = '$YOUR_LOGSCALE_URL/graphql';

my $query = "query{
  sessions(
    searchFilter: \"company.com\"
    limit: 10
    skip: 0
    onlyActiveSessions: false 
    level: Organization
    sortBy: User
    orderBy: DESC
  )
  {totalResults, results {id, user{username}}}
}";
$query =~ s/\n/ /g;
my $json = sprintf('{"query" : "%s"}',$query);
my $req = HTTP::Request->new("POST", $uri );

$req->header("Authorization" => "Bearer $TOKEN");
$req->header("Content-Type" => "application/json");

$req->content( $json );

my $lwp = LWP::UserAgent->new;

my $result = $lwp->request( $req );

print $result->{"_content"},"\n";
Python
python
#! /usr/local/bin/python3

import requests

url = '$YOUR_LOGSCALE_URL/graphql'
mydata = r'''{"query" : "query{
  sessions(
    searchFilter: \"company.com\"
    limit: 10
    skip: 0
    onlyActiveSessions: false 
    level: Organization
    sortBy: User
    orderBy: DESC
  )
  {totalResults, results {id, user{username}}}
}"
}'''

resp = requests.post(url,
                     data = mydata,
                     headers = {
   "Authorization" : "Bearer $TOKEN",
   "Content-Type" : "application/json"
}
)

print(resp.text)
Node.js
javascript
const https = require('https');

const data = JSON.stringify(
    {"query" : "query{
  sessions(
    searchFilter: \"company.com\"
    limit: 10
    skip: 0
    onlyActiveSessions: false 
    level: Organization
    sortBy: User
    orderBy: DESC
  )
  {totalResults, results {id, user{username}}}
}"
}
);


const options = {
  hostname: '$YOUR_LOGSCALE_URL',
  path: 'graphql',
  port: 443,
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Content-Length': data.length,
    Authorization: 'BEARER ' + process.env.TOKEN,
    'User-Agent': 'Node',
  },
};

const req = https.request(options, (res) => {
  let data = '';
  console.log(`statusCode: ${res.statusCode}`);

  res.on('data', (d) => {
    data += d;
  });
  res.on('end', () => {
    console.log(JSON.parse(data).data);
  });
});

req.on('error', (error) => {
  console.error(error);
});

req.write(data);
req.end();
Example Responses
Success (HTTP Response Code 200 OK)
json
{
  "data": {
    "sessions": {
      "totalResults": 2,
      "results": [
        {
          "id": "abc123",
          "user": {
            "username": "steve@company.com"
          }
        },
        {
          "id": "def456",
          "user": {
            "username": "bob@company.com"
          }
        }
      ]
    }
  }
}

This example searches for sessions with users who have an email address using company.com. It includes active and inactive sessions. And sorts by users in descending order. For the results, it is requesting the ID and username for each session.

Input Parameters

Provide any text on which to search for sessions, indicate whether to include only active sessions, whether to filter at organization or user level (see second table below), how to sort results (see third table), how to order results (see fourth), and the number of results to skip and how many to return.

Table: Input Parameters & Datatypes

Parameter Type Required Default Description
This table contains all input parameters for this query. Since some of the parameters use special datatypes, additional tables for them are included below.
level Sessions__Filter_Level     Whether to sort by user or organization. See table below.
limit Int   50 The maximum number of results to return.
onlyActiveSessions Boolean   true Whether to include only active sessions in results.
orderBy OrderBy   ASC How to order results. See table below.
searchFilter String     Any text on which to filter results.
skip Int yes 0 The number of results to skip, or offset to use.
sortBy Sessions__SortBy     The session factor by which to sort the results. See table below.

For this special input datatype, there is a short enumerated list to filter at organization or user level.

The second special datatype is used to sort results by key factors (for example, log in time, IP address). The choices for this are listed in the table below:

The other input datatype is a simple one. You can return results based on whether they are in ascending or descending order, alphanumerically.

Returned Values

Returns a non-nullable SessionQueryResultSet! object. The table below lists all fields:

Table: SessionQueryResultSet Datatype

ParameterTypeRequiredDefaultStabilityAvailabilityDescription
Some input parameters may be required, as indicated in the Required column. For return values, this indicates that you are assured a value if the field is requested for the results. 
Table last updated: Oct 14, 2026 
resultsSessionyes Long-Term The paginated results set. See Session.
totalResultsIntyes Long-Term The total number of matching results.

The SessionQueryResultSet type contains Session objects. For reference, the Session datatype table is included here:

Table: Session Datatype

ParameterTypeRequiredDefaultStabilityAvailabilityDescription
Some input parameters may be required, as indicated in the Required column. For return values, this indicates that you are assured a value if the field is requested for the results. 
Table last updated: Oct 14, 2026 
cityString  Long-Term Approximate city from IP address.
clientInfoStringyes Long-Term Information about the client.
countryString  Long-Term Country from IP address.
createdAtLong  Long-Term The time at which the session was created.
idStringyes Long-Term The unique identifier of the session.
ipStringyes Long-Term The IP of the client when the session was created.
isCurrentSessionBooleanyes Long-Term Whether the session is the current session for the user.
lastActivityAtLong  Long-Term The time at which the session was last active.
userUseryes Long-Term The user that created the session. See User.