Summary

The addSavedQueryLabels() mutation adds one or more labels to an existing saved query in a repository or view. Labels help you organize and filter saved queries in LogScale. Use this mutation to add labels after saved query creation; a saved query supports at most ten labels, each with a maximum length of sixty characters.

Syntax

graphql
addSavedQueryLabels(
      input: AddSavedQueryLabels!
   ): SavedQuery

The mutation takes a single required input argument of type AddSavedQueryLabels!. The input requires a view or repository name, a saved query ID, and a list of labels to add. The mutation returns a SavedQuery object on success, or null on failure.

For the full list of available fields on the returned SavedQuery object, see the Returned Values section.

Hide Query Example

Show Saved Query Identifiers Query

Example

Raw
graphql
mutation {
  addSavedQueryLabels(
    input: { 
      viewName: "humio",
      id: "abc123",
      labels: [ "bobs-savedqueries",
                "admin-focus" ]
    }
  )
  { displayName }
}
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 {
  addSavedQueryLabels(
    input: { 
      viewName: \"humio\",
      id: \"abc123\",
      labels: [ \"bobs-savedqueries\",
                \"admin-focus\" ]
    }
  )
  { displayName }
}"
}
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 {
  addSavedQueryLabels(
    input: { 
      viewName: \"humio\",
      id: \"abc123\",
      labels: [ \"bobs-savedqueries\",
                \"admin-focus\" ]
    }
  )
  { displayName }
}"
}
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 { ^
  addSavedQueryLabels( ^
    input: {  ^
      viewName: \"humio\", ^
      id: \"abc123\", ^
      labels: [ \"bobs-savedqueries\", ^
                \"admin-focus\" ] ^
    } ^
  ) ^
  { displayName } ^
}" ^
} '
Windows Powershell and curl
powershell
curl.exe -X POST 
    -H "Authorization: Bearer $TOKEN"
    -H "Content-Type: application/json"
    -d '{"query" : "mutation {
  addSavedQueryLabels(
    input: { 
      viewName: \"humio\",
      id: \"abc123\",
      labels: [ \"bobs-savedqueries\",
                \"admin-focus\" ]
    }
  )
  { displayName }
}"
}'
    "$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 {
  addSavedQueryLabels(
    input: { 
      viewName: \"humio\",
      id: \"abc123\",
      labels: [ \"bobs-savedqueries\",
                \"admin-focus\" ]
    }
  )
  { displayName }
}";
$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 {
  addSavedQueryLabels(
    input: { 
      viewName: \"humio\",
      id: \"abc123\",
      labels: [ \"bobs-savedqueries\",
                \"admin-focus\" ]
    }
  )
  { displayName }
}"
}'''

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 {
  addSavedQueryLabels(
    input: { 
      viewName: \"humio\",
      id: \"abc123\",
      labels: [ \"bobs-savedqueries\",
                \"admin-focus\" ]
    }
  )
  { displayName }
}"
}
);


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": {
    "addSavedQueryLabels": {
      "displayName": "Admin Saved Query"
    }
  }
}

Input Parameters

The input argument requires three fields: the view or repository name (viewName), the unique identifier of the saved query (id), and a list of labels to add (labels). The viewName field accepts either a repository name or a view name; views are read-only abstractions over one or more repositories and are valid scopes for this mutation. The id field is the system-generated unique identifier for the saved query, not its display name. Use the repository() query to retrieve saved query IDs, as shown in the Syntax section. Each label in labels can be at most sixty characters; a saved query supports at most ten labels in total.

Table: AddSavedQueryLabels Input Datatype

ParameterTypeRequiredDefaultStabilityAvailabilityDescription
idStringyes   Id of the saved query.
labelsStringyes   Labels for the saved query. There can be at most 10 labels, with a max length of 60 characters per label.
viewNameRepoOrViewNameyes   Name of the view of the saved query.

Returned Values

This mutation returns a SavedQuery object on success. The labels field contains the full updated list of labels for the saved query. The following table lists all available fields.