Summary

The createSavedQueryFromPackageTemplate() mutation creates a saved query in a view from a saved query template defined in an installed package. Package templates provide standardized query configurations — including the query string, time range, and display settings — that you can deploy consistently across views. You must supply the view name, the versioned package identifier, and the template name from that package.

Syntax

graphql
createSavedQueryFromPackageTemplate(
      viewName: String!,
      packageId: VersionedPackageSpecifier!,
      savedQueryTemplateName: String!,
      overrideName: String
   ): CreateSavedQueryFromPackageTemplateMutation!

The mutation requires the view name, a versioned package identifier, and the name of the saved query template within that package. The overrideName argument is optional; omit it to use the template's default name. Provide overrideName when installing the same package more than once to avoid name conflicts with an existing saved query. Use the query example in the Input Parameters section to retrieve valid packageId and savedQueryTemplateName values from an installed package.

The mutation returns a CreateSavedQueryFromPackageTemplateMutation object, which includes the created saved query and its YAML template representation. See the Returned Values section for the full field list.

Hide Installed Packages Query

Show Installed Packages Query

Example

Raw
graphql
mutation {
  createSavedQueryFromPackageTemplate(
    viewName: "humio",
     packageId: "humio/insights@0.0.14",
    savedQueryTemplateName: "ingestErrors",
    overrideName: "my-ingest-errors-query"
    )
  { savedQuery {id, query {queryString} }  }
}
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 {
  createSavedQueryFromPackageTemplate(
    viewName: \"humio\",
     packageId: \"humio/insights@0.0.14\",
    savedQueryTemplateName: \"ingestErrors\",
    overrideName: \"my-ingest-errors-query\"
    )
  { savedQuery {id, query {queryString} }  }
}"
}
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 {
  createSavedQueryFromPackageTemplate(
    viewName: \"humio\",
     packageId: \"humio/insights@0.0.14\",
    savedQueryTemplateName: \"ingestErrors\",
    overrideName: \"my-ingest-errors-query\"
    )
  { savedQuery {id, query {queryString} }  }
}"
}
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 { ^
  createSavedQueryFromPackageTemplate( ^
    viewName: \"humio\", ^
     packageId: \"humio/insights@0.0.14\", ^
    savedQueryTemplateName: \"ingestErrors\", ^
    overrideName: \"my-ingest-errors-query\" ^
    ) ^
  { savedQuery {id, query {queryString} }  } ^
}" ^
} '
Windows Powershell and curl
powershell
curl.exe -X POST 
    -H "Authorization: Bearer $TOKEN"
    -H "Content-Type: application/json"
    -d '{"query" : "mutation {
  createSavedQueryFromPackageTemplate(
    viewName: \"humio\",
     packageId: \"humio/insights@0.0.14\",
    savedQueryTemplateName: \"ingestErrors\",
    overrideName: \"my-ingest-errors-query\"
    )
  { savedQuery {id, query {queryString} }  }
}"
}'
    "$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 {
  createSavedQueryFromPackageTemplate(
    viewName: \"humio\",
     packageId: \"humio/insights@0.0.14\",
    savedQueryTemplateName: \"ingestErrors\",
    overrideName: \"my-ingest-errors-query\"
    )
  { savedQuery {id, query {queryString} }  }
}";
$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 {
  createSavedQueryFromPackageTemplate(
    viewName: \"humio\",
     packageId: \"humio/insights@0.0.14\",
    savedQueryTemplateName: \"ingestErrors\",
    overrideName: \"my-ingest-errors-query\"
    )
  { savedQuery {id, query {queryString} }  }
}"
}'''

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 {
  createSavedQueryFromPackageTemplate(
    viewName: \"humio\",
     packageId: \"humio/insights@0.0.14\",
    savedQueryTemplateName: \"ingestErrors\",
    overrideName: \"my-ingest-errors-query\"
    )
  { savedQuery {id, query {queryString} }  }
}"
}
);


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": {
    "createSavedQueryFromPackageTemplate": {
      "savedQuery": {
        "id": "abc123",
        "query": {
          "queryString": "#type=humio #kind=metrics |
                          name=/^data-ingester-errors\\/([^/]+\\/)?(?<repo>\\S+)/ |
                          timechart(repo, function={groupBy(#vhost, function=avg(m1)) |
                          sum(_avg)}, limit=100, minSpan=1m)"
        }
      }
    }
  }
}

Input Parameters

Supply the name of the view where the package is installed, the versioned package identifier, and the name of the saved query template within that package. The versioned package identifier uses the format namespace/package-name@version — for example, humio/insights@0.0.14. Use the query example in the Syntax section to retrieve these values from an installed package.

Table: Input Parameters & Datatypes

Parameter Type Required Default Description
This table contains all input parameters for this mutation.
overrideName string     The name to assign to the new saved query. When omitted, the mutation uses the template's default name. Supply this argument when installing the same package more than once to avoid name conflicts with an existing saved query.
packageId VersionedPackageSpecifier yes   The versioned identifier of the package containing the saved query template. Uses the format namespace/package-name@version — for example, humio/insights@0.0.14. VersionedPackageSpecifier is a scalar.
savedQueryTemplateName string yes   The name of the saved query template in the package. This value is case-sensitive. Use the savedQueryTemplates { name } field on an installed package to retrieve available template names.
viewName string yes   The name of the view where the package is installed.

Returned Values

The mutation returns a CreateSavedQueryFromPackageTemplateMutation object containing the newly created saved query and its YAML template representation. Inspect the yamlTemplate field to verify the deployed configuration or export it for use with the createSavedQueryFromTemplate() mutation. The SavedQuery sub-type provides query details including the query string, creation time, and author.

Table: CreateSavedQueryFromPackageTemplateMutation Datatype

ParameterTypeRequiredDefaultStabilityAvailabilityDescription
savedQuerySavedQueryyes Long-Term  

The datatype above uses another datatype for information on a saved query. For your convenience, the table for that sub-datatype is included here: