Summary

The createView() mutation creates a new view in LogScale. A view queries across one or more repositories and applies optional filters to each connection. Use this mutation to provision a view programmatically as part of a repository setup workflow. To update an existing view after creation, use updateView().

Syntax

graphql
createView(
      name: String!,
      description: String,
      connections: [ViewConnectionInput!],
      federatedViews: [String!],
      isFederated: Boolean
   ): View!

The name argument is required. All other arguments are optional. Provide connections to specify the repositories the view queries and the filters to apply to each. Set isFederated to true and supply federatedViews to create a federated view that spans multiple existing views. The mutation returns a non-null View object containing the full details of the created view.

For the returned values, request id to obtain the new view's unique identifier for use with updateView() and other mutations. The Returned Values section lists all available View fields.

Example

Raw
graphql
mutation {
  createView(
        name: "vh-view",
        description: "V-Host View",
        connections: [ { repositoryName: "humio", filter: "#vhost" } ]
       )
  { 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 {
  createView(
        name: \"vh-view\",
        description: \"V-Host View\",
        connections: [ { repositoryName: \"humio\", filter: \"#vhost\" } ]
       )
  { 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 {
  createView(
        name: \"vh-view\",
        description: \"V-Host View\",
        connections: [ { repositoryName: \"humio\", filter: \"#vhost\" } ]
       )
  { 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 { ^
  createView( ^
        name: \"vh-view\", ^
        description: \"V-Host View\", ^
        connections: [ { repositoryName: \"humio\", filter: \"#vhost\" } ] ^
       ) ^
  { id } ^
}" ^
} '
Windows Powershell and curl
powershell
curl.exe -X POST 
    -H "Authorization: Bearer $TOKEN"
    -H "Content-Type: application/json"
    -d '{"query" : "mutation {
  createView(
        name: \"vh-view\",
        description: \"V-Host View\",
        connections: [ { repositoryName: \"humio\", filter: \"#vhost\" } ]
       )
  { 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 {
  createView(
        name: \"vh-view\",
        description: \"V-Host View\",
        connections: [ { repositoryName: \"humio\", filter: \"#vhost\" } ]
       )
  { 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 {
  createView(
        name: \"vh-view\",
        description: \"V-Host View\",
        connections: [ { repositoryName: \"humio\", filter: \"#vhost\" } ]
       )
  { 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 {
  createView(
        name: \"vh-view\",
        description: \"V-Host View\",
        connections: [ { repositoryName: \"humio\", filter: \"#vhost\" } ]
       )
  { 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": {
    "createView": {
      "id": "abc123"
    }
  }
}

Input Parameters

Provide the name of the view to create. Optionally supply a description, specify the repository connections with their filters, and configure federation settings. The following table lists all input parameters:

Table: Input Parameters & Datatypes

Parameter Type Required Default Description
This table contains all input parameters for this mutation. The connections parameter uses a special datatype; an additional table below describes its fields.
connections [ViewConnectionInput]     A list of repositories to connect to the view, each with an optional filter. Omitting this argument creates a view with no repository connections.
description string     A human-readable description of the view's purpose. Omitting this argument leaves the description empty.
federatedViews [string]     A list of existing view names to include in this federated view. Provide this argument when isFederated is true.
isFederated boolean   false When true, the view aggregates query results across the views listed in federatedViews.
name string yes   The unique name for the view. This name identifies the view throughout LogScale.

Each entry in connections specifies a repository name and an optional filter to restrict the data the view draws from that repository. The following table describes the ViewConnectionInput fields:

Table: ViewConnectionInput Input Datatype

ParameterTypeRequiredDefaultStabilityAvailabilityDescription
filterStringyes   The filter applied to all results from the repository.
languageVersionLanguageVersionEnum     
repositoryNameStringyes   The name of the connected repository.

Returned Values

The mutation returns a non-null View! object. Request id to obtain the unique identifier assigned to the new view. Use this identifier with updateView() and other mutations that reference an existing view.