Summary

The createPersonalUserTokenV2() mutation creates a personal user token for the authenticated user. The token inherits the same permissions as the user who creates it. Use this mutation for programmatic API access scoped to a specific user identity. To create a token through the UI instead, see Personal API Token.

Syntax

graphql
createPersonalUserTokenV2(
      input: CreatePersonalUserTokenV2Input!
   ): CreatePersonalUserTokenV2Output!

The mutation accepts a required input argument of type CreatePersonalUserTokenV2Input. The input accepts an optional IP filter ID and an optional expiration timestamp. The mutation returns a non-null CreatePersonalUserTokenV2Output containing the token string and its associated metadata.

Example

Raw
graphql
mutation {
  createPersonalUserTokenV2(input:
       { expireAt: null } )
  { token, tokenMetadata { name } }
}
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 {
  createPersonalUserTokenV2(input:
       { expireAt: null } )
  { token, tokenMetadata { name } }
}"
}
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 {
  createPersonalUserTokenV2(input:
       { expireAt: null } )
  { token, tokenMetadata { name } }
}"
}
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 { ^
  createPersonalUserTokenV2(input: ^
       { expireAt: null } ) ^
  { token, tokenMetadata { name } } ^
}" ^
} '
Windows Powershell and curl
powershell
curl.exe -X POST 
    -H "Authorization: Bearer $TOKEN"
    -H "Content-Type: application/json"
    -d '{"query" : "mutation {
  createPersonalUserTokenV2(input:
       { expireAt: null } )
  { token, tokenMetadata { name } }
}"
}'
    "$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 {
  createPersonalUserTokenV2(input:
       { expireAt: null } )
  { token, tokenMetadata { name } }
}";
$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 {
  createPersonalUserTokenV2(input:
       { expireAt: null } )
  { token, tokenMetadata { name } }
}"
}'''

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 {
  createPersonalUserTokenV2(input:
       { expireAt: null } )
  { token, tokenMetadata { name } }
}"
}
);


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": {
    "createPersonalUserTokenV2": {
      "token": "abc123-def456-ghi789",
      "tokenMetadata": {
        "name": "Personal token"
      }
    }
  }
}

Input Parameters

The CreatePersonalUserTokenV2Input type accepts two optional parameters. Provide an IP filter ID to restrict token usage by IP address, or provide an expiration timestamp to limit the token's validity period. Omit both parameters to create a token with no IP restriction and no expiration.

Table: CreatePersonalUserTokenV2Input Input Datatype

ParameterTypeRequiredDefaultStabilityAvailabilityDescription
expireAtLong  Long-Term The date when the token expires.
ipFilterIdString  Long-Term The IP address on which to filter access.

Returned Values

The mutation returns a CreatePersonalUserTokenV2Output object containing the raw token string and a tokenMetadata field of type PersonalUserToken. Request token to retrieve the token value. Use tokenMetadata to inspect the token's name, IP filter assignment, expiration time, and other attributes.

Table: CreatePersonalUserTokenV2Output Datatype

ParameterTypeRequiredDefaultStabilityAvailabilityDescription
tokenStringyes Long-Term The personal user token.
tokenMetadataPersonalUserTokenyes Long-Term Metadata about the token. See PersonalUserToken, which implements Token.

The CreatePersonalUserTokenV2Output type includes a tokenMetadata field that returns the full PersonalUserToken datatype. The following table describes the fields available on that sub-type.

Table: PersonalUserToken Datatype

ParameterTypeRequiredDefaultStabilityAvailabilityDescription
createdAtlongyes Long-Term The date the token was created.
expireAtlong  Long-Term When the token expires.
idstringyes Long-Term The identifier of the token.
ipFilterstring  Long-Term The IP filter on the token.
ipFilterV2IPFilter  Long-Term The IP filter on the token. See IPFilter.
namestringyes Long-Term The name of the token.