Summary

The createViewPermissionsTokenV2() mutation creates a view permissions token scoped to one or more specific views with defined permissions. Use this mutation instead of createViewPermissionsToken() when you need per-asset permission assignments in addition to view-level permissions. The V2 input type adds the assetPermissionAssignments field, available from version 1.170, which grants access to individual assets such as dashboards and saved queries within the token's views. Optionally restrict usage by setting an expiration time or an IP filter.

Syntax

graphql
createViewPermissionsTokenV2(
      input: CreateViewPermissionsTokenV2Input!
   ): CreateViewPermissionsTokenV2Output!

The mutation accepts a single required input argument of type CreateViewPermissionsTokenV2Input!. Provide the token name, the target view IDs, and the permissions to grant. The mutation returns a non-null CreateViewPermissionsTokenV2Output! object containing the token string and its metadata.

Use the Show View Permissions Query example in the Related section to look up valid Permission enum values before calling this mutation.

Example

Raw
graphql
mutation {
  createViewPermissionsTokenV2(input:
       { name: "my-view-token", 
         viewIds: [ "abc123", "def456" ],
         viewPermissions: [ ReadAccess ]
       } )
  { token, tokenMetadata { name, expireAt } }
}
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" : "mutation {
  createViewPermissionsTokenV2(input:
       { name: \"my-view-token\", 
         viewIds: [ \"abc123\", \"def456\" ],
         viewPermissions: [ ReadAccess ]
       } )
  { token, tokenMetadata { name, expireAt } }
}"
}
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" : "mutation {
  createViewPermissionsTokenV2(input:
       { name: \"my-view-token\", 
         viewIds: [ \"abc123\", \"def456\" ],
         viewPermissions: [ ReadAccess ]
       } )
  { token, tokenMetadata { name, expireAt } }
}"
}
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" : "mutation { ^
  createViewPermissionsTokenV2(input: ^
       { name: \"my-view-token\",  ^
         viewIds: [ \"abc123\", \"def456\" ], ^
         viewPermissions: [ ReadAccess ] ^
       } ) ^
  { token, tokenMetadata { name, expireAt } } ^
}" ^
} '
Windows Powershell and curl
powershell
curl.exe -X POST 
    -H "Authorization: Bearer $TOKEN"
    -H "Content-Type: application/json"
    -d '{"query" : "mutation {
  createViewPermissionsTokenV2(input:
       { name: \"my-view-token\", 
         viewIds: [ \"abc123\", \"def456\" ],
         viewPermissions: [ ReadAccess ]
       } )
  { token, tokenMetadata { name, expireAt } }
}"
}'
    "$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 = "mutation {
  createViewPermissionsTokenV2(input:
       { name: \"my-view-token\", 
         viewIds: [ \"abc123\", \"def456\" ],
         viewPermissions: [ ReadAccess ]
       } )
  { token, tokenMetadata { name, expireAt } }
}";
$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" : "mutation {
  createViewPermissionsTokenV2(input:
       { name: \"my-view-token\", 
         viewIds: [ \"abc123\", \"def456\" ],
         viewPermissions: [ ReadAccess ]
       } )
  { token, tokenMetadata { name, expireAt } }
}"
}'''

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" : "mutation {
  createViewPermissionsTokenV2(input:
       { name: \"my-view-token\", 
         viewIds: [ \"abc123\", \"def456\" ],
         viewPermissions: [ ReadAccess ]
       } )
  { token, tokenMetadata { name, expireAt } }
}"
}
);


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": {
    "createViewPermissionsTokenV2": {
      "token": "ghi789...",
      "tokenMetadata": {
        "name": "my-view-token",
        "expireAt": null
      }
    }
  }
}

Input Parameters

The CreateViewPermissionsTokenV2Input type requires name, viewIds, and viewPermissions. The viewIds field accepts a list of view identifiers; the token can only access those named views, and requests to any other view are rejected. Use the searchDomains() query to look up view identifiers. The viewPermissions field accepts one or more Permission enum values that determine what operations the token holder can perform within the named views — for example, ReadAccess or QueryOnBehalfOf.

The optional expireAt field accepts a Unix epoch time in milliseconds (Long). Omitting it or passing null creates a non-expiring token; set a value for short-lived or scoped programmatic access. The optional ipFilterId field restricts the token to requests originating from a matching IP range; use the ipFilters() query to list available IP filter identifiers. The optional assetPermissionAssignments field, available from version 1.170, grants access to individual view assets such as dashboards and saved queries; each entry pairs an asset resource identifier with an AssetPermission enum value.

Table: CreateViewPermissionsTokenV2Input Input Datatype

ParameterTypeRequiredDefaultStabilityAvailabilityDescription
assetPermissionAssignmentsViewPermissionsTokenAssetPermissionAssignmentInputyes Long-Term The asset permission assignments for the view token. See ViewPermissionsTokenAssetPermissionAssignmentInput.
expireAtLong  Long-Term The date the token expires.
ipFilterIdString  Long-Term The unique identifier for the IP filter.
nameStringyes Long-Term The name of the permissions token.
viewIdsStringyes Long-Term The unique identifiers for the views.
viewPermissionsPermissionyes Long-Term A list of permissions for the token. See Permission.

Returned Values

The mutation returns a non-null CreateViewPermissionsTokenV2Output! object with two fields. The token field contains the raw token string; pass this value in the Authorization: Bearer header in API requests to authenticate with the granted permissions. The tokenMetadata field returns a ViewPermissionsToken object containing the token name, expiration time (null if no expiration was set), the views the token applies to (limited to those the calling user has access to), the granted permissions, and the IP filter if one was assigned.

Table: CreateViewPermissionsTokenV2Output Datatype

ParameterTypeRequiredDefaultStabilityAvailabilityDescription
tokenStringyes Long-Term The token returned.
tokenMetadataViewPermissionsTokenyes Long-Term The meta data related to the token. See ViewPermissionsToken.