Summary

The createRole() mutation creates a named role with a defined set of permissions in LogScale. After creating a role, assign it to users or groups to manage their access. This mutation is available only when roles are not managed externally, for example through LDAP.

Syntax

graphql
createRole(
      input: AddRoleInput!
   ): AddRoleMutation!

The required input argument accepts an AddRoleInput object. Provide the role display name and the view permissions to grant. System, organization, and organization management permissions are optional. The mutation returns an AddRoleMutation object containing the created role. See the Input Parameters and Returned Values sections for details.

Example

Raw
graphql
mutation {
  createRole(input:
      { displayName: "sales",
        viewPermissions: [ReadAccess]
      } )
  { role { id } }
}
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 {
  createRole(input:
      { displayName: \"sales\",
        viewPermissions: [ReadAccess]
      } )
  { role { id } }
}"
}
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 {
  createRole(input:
      { displayName: \"sales\",
        viewPermissions: [ReadAccess]
      } )
  { role { id } }
}"
}
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 { ^
  createRole(input: ^
      { displayName: \"sales\", ^
        viewPermissions: [ReadAccess] ^
      } ) ^
  { role { id } } ^
}" ^
} '
Windows Powershell and curl
powershell
curl.exe -X POST 
    -H "Authorization: Bearer $TOKEN"
    -H "Content-Type: application/json"
    -d '{"query" : "mutation {
  createRole(input:
      { displayName: \"sales\",
        viewPermissions: [ReadAccess]
      } )
  { role { id } }
}"
}'
    "$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 {
  createRole(input:
      { displayName: \"sales\",
        viewPermissions: [ReadAccess]
      } )
  { role { id } }
}";
$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 {
  createRole(input:
      { displayName: \"sales\",
        viewPermissions: [ReadAccess]
      } )
  { role { id } }
}"
}'''

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 {
  createRole(input:
      { displayName: \"sales\",
        viewPermissions: [ReadAccess]
      } )
  { role { id } }
}"
}
);


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": {
    "createRole": {
      "role": {
        "id": "abc123"
      }
    }
  }
}

Input Parameters

Provide the display name of the role to create and the view permissions to assign. The following table describes the available input parameters:

Table: AddRoleInput Input Datatype

ParameterTypeRequiredDefaultStabilityAvailabilityDescription
colorString  Long-Termdeprecated in 1.282The color used for highlighting role added.
displayNameStringyes Long-Term The name to display for the role added.
objectActionObjectAction  Long-Term The object of the action. See ObjectAction.
organizationManagementPermissionsOrganizationManagementPermissionyes Long-Term The management permissions for the organization. See OrganizationManagementPermission.
organizationPermissionsOrganizationPermissionyes Long-Term The permissions for the organization. See OrganizationPermission.
systemPermissionsSystemPermissionyes Long-Term The permissions for the system. See SystemPermission.
viewPermissionsPermissionyes Long-Term The permissions for the view. See Permission.

Returned Values

The mutation returns an AddRoleMutation object containing the newly created Role. Use the returned role data to confirm creation details, retrieve the assigned permissions, or pass the role to subsequent operations such as assigning it to users or groups.

Table: AddRoleMutation Datatype

ParameterTypeRequiredDefaultStabilityAvailabilityDescription
roleRoleyes Long-Term The role to add. See Role.

The AddRoleMutation type contains a Role field. The following table describes the Role datatype:

Table: Role Datatype

ParameterTypeRequiredDefaultStabilityAvailabilityDescription
descriptionString  Long-Term A description of the role.
displayNameStringyes Long-Term The display name of the role.
groupsGroupyes Long-Term The groups related to the role. See Group.
groupsCountIntyes Long-Term The number of groups related to the role.
idStringyes Long-Term The unique identifier for the role.
limitInt,    The amount of results to return.
organizationManagementPermissionsOrganizationManagementPermissionyes Long-Term The organization management permissions given to the role. See OrganizationManagementPermission.
organizationPermissionsOrganizationPermissionyes Long-Term The organization permissions given to the role. See OrganizationPermission.
readonlyDefaultRoleReadonlyDefaultRole  Short-Term The read-only default role. This parameter is a preview and subject to change. See ReadonlyDefaultRole.
skipInt):GroupResultSetTypeyes Long-Term The number of results to skip or the offset to use. For instance if implementing pagination, set skip = limit * (page - 1)
systemPermissionsSystemPermissionyes Long-Term The system permissions given to the role. See SystemPermission.
usersUseryes Long-Term A list of users assigned the role. See User.
usersCountIntyes Long-Term The number of users assigned the role.
viewPermissionsPermissionyes Long-Term The view permissions given to the role. See Permission.