Summary

The createViewPermissionsToken() mutation creates a view permissions token in LogScale. The token grants the specified permissions on the views identified in the input. Use this mutation to create an access token for view-level authorization. For an alternative with additional input options, use createViewPermissionsTokenV2().

Syntax

graphql
createViewPermissionsToken(
      input: CreateViewPermissionsTokenInput!
   ): String!

The mutation accepts a single required input argument of type CreateViewPermissionsTokenInput!. The input specifies the token name, an optional expiration time, the view identifiers to grant access to, and the permissions to assign.

On success, the mutation returns a non-null String! containing the created token value. The Returned Values section describes how to use this value.

Example

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

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 {
  createViewPermissionsToken(input:
        { name: \"reader-token\",
          expireAt: null,
          viewIds: [ \"abc123\",
                     \"def456\" ],
          permissions: [ ReadAccess ]
        } )
}"
}
);


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": {
    "createViewPermissionsToken": "abc123-def456-ghi789"
  }
}

Input Parameters

Provide the token name, the view identifiers to grant access to, and the permissions to assign. Optionally, set an expiration time. The following table describes the CreateViewPermissionsTokenInput fields:

Table: CreateViewPermissionsTokenInput Input Datatype

ParameterTypeRequiredDefaultStabilityAvailabilityDescription
expireAtLong  Long-Term When the permission token will expire.
ipFilterIdString  Long-Term The unique identifier of the IP filter.
nameStringyes Long-Term The name of the view permission token to create.
permissionsPermissionyes Long-Term A list of permissions related to the view that are granted. See Permission.
viewIdsStringyes Long-Term The unique identifiers for the views associated with the permission token.

Returned Values

The mutation returns a non-null String! containing the token value. Use this value as the bearer token in API requests to authenticate against the views specified in the input. Store the token value securely after creation.