Summary

The addUserV2() mutation creates a new user account in the LogScale organization or initiates an email invitation for a new user. When you supply a verificationToken, the mutation activates a pending account and records the user's acceptance of the Terms and Conditions. Use this mutation to programmatically provision users instead of adding them through the LogScale interface.

Syntax

graphql
addUserV2(
      input: AddUserInputV2!
   ): userOrPendingUser!

The mutation takes a single required input argument of type AddUserInputV2. The input accepts the user's username, email address, name fields, root access flag, organization owner flag, and invitation settings. See the Input Parameters section for details on each field.

The mutation returns a non-null userOrPendingUser union type. The result is either a User object when the account is created directly, or a PendingUser object when an invitation is sent and the user has not yet accepted it. Use inline fragments (... on User { } and ... on PendingUser { }) to select fields from each type. See the Returned Values section for the fields available from each type.

Example

Raw
graphql
mutation {
  addUserV2 (
    input: {
      username: "steve"
      sendInvite: true
      email: "steve@company.com"
    }
  ) {__typename ... on User {id, 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" : "mutation {
  addUserV2 (
    input: {
      username: \"steve\"
      sendInvite: true
      email: \"steve@company.com\"
    }
  ) {__typename ... on User {id, 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" : "mutation {
  addUserV2 (
    input: {
      username: \"steve\"
      sendInvite: true
      email: \"steve@company.com\"
    }
  ) {__typename ... on User {id, 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" : "mutation { ^
  addUserV2 ( ^
    input: { ^
      username: \"steve\" ^
      sendInvite: true ^
      email: \"steve@company.com\" ^
    } ^
  ) {__typename ... on User {id, username}} ^
}" ^
} '
Windows Powershell and curl
powershell
curl.exe -X POST 
    -H "Authorization: Bearer $TOKEN"
    -H "Content-Type: application/json"
    -d '{"query" : "mutation {
  addUserV2 (
    input: {
      username: \"steve\"
      sendInvite: true
      email: \"steve@company.com\"
    }
  ) {__typename ... on User {id, 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 = "mutation {
  addUserV2 (
    input: {
      username: \"steve\"
      sendInvite: true
      email: \"steve@company.com\"
    }
  ) {__typename ... on User {id, 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" : "mutation {
  addUserV2 (
    input: {
      username: \"steve\"
      sendInvite: true
      email: \"steve@company.com\"
    }
  ) {__typename ... on User {id, 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" : "mutation {
  addUserV2 (
    input: {
      username: \"steve\"
      sendInvite: true
      email: \"steve@company.com\"
    }
  ) {__typename ... on User {id, 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": {
    "addUserV2": {
      "__typename": "User",
      "id": "abc123",
      "username": "steve"
    }
  }
}

This example adds a new user to LogScale with sendInvite set to true. The User inline fragment selects id and username to confirm the result.

Input Parameters

The input argument accepts the user's username, email address, name, root access status, and invitation settings. The following table describes each field in the AddUserInputV2 input type:

Table: AddUserInputV2 Input Datatype

ParameterTypeRequiredDefaultStabilityAvailabilityDescription
companyString     
countryCodeString     
emailString     
firstNameString     
fullNameString     
isOrgOwnerBoolean     
isRootBoolean     
lastNameString     
pictureString     
sendInviteBoolean     
stateCodeString     
usernameStringyes    
verificationTokenString     

The root access flag grants the user root-level access to the entire LogScale instance, which bypasses repository and organization permission boundaries. The organization owner flag grants full administrative control over the organization. Assign these elevated privileges only when required.

Returned Values

The mutation returns a non-null userOrPendingUser union type. This union includes two possible types: User or PendingUser.

The returned type depends on whether the user was created directly or invited. When sendInvite is set to false, LogScale creates the account immediately and returns a User object. When an invitation is sent, LogScale returns a PendingUser object until the user accepts the invitation. After the user accepts and activates the account, subsequent queries return a User object for that account.

The schema for the User type includes all user account attributes. The following table lists each field with its data type, description, and whether the field is always populated.

The schema for the PendingUser type includes fields based on the minimal data collected at invitation time. The following table lists each field with its data type, description, and whether the field is always populated.

Table: PendingUser Datatype

ParameterTypeRequiredDefaultStabilityAvailabilityDescription
createdAtLongyes Long-Term The time the pending user was created
idStringyes Long-Term The id or token for the pending user
idpBooleanyes Long-Term Whether IDP is enabled for the organization
invitedByEmailStringyes Long-Term The email of the user that invited the pending user
invitedByNameStringyes Long-Term The name of the user that invited the pending user
newUserEmailStringyes Long-Term The email of the pending user
orgNameStringyes Long-Term The name of the organization the pending user is about to join
pendingUserStatePendingUserStateyes Long-Term The current organization state for the user, if any.