The createSavedQueryFromPackageTemplate() GraphQL mutation field is used to create a saved query from a package saved query template.

Similar to this mutation, there is the copySavedQuery() for copying a saved query, and createSavedQueryFromTemplate() for creating one from a YAML template. There are also the mutations, createSavedQuery(), updateSavedQuery() and deleteSavedQueryV2() for creating, updating, and deleting saved queries. There is also setDefaultSavedQuery() for marking a saved query as the default.

Hide Query Example

Show Saved Queries Query

For more information on saved queries, see the Saved Searches (User Functions) reference page where saved queries are discussed. You may also want to look at the Package Management page for related information. Also, look at the Search Data documentation page as it relates to recent queries and saving queries.

API Stability Long-Term

Syntax

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

For the input, you'll have to give the name of the view involved, the package identifier, and the name of the saved query template in the package. See the Given Datatype section for more details.

For the results, you can get a yaml template of the saved query, and other related data. See the Returned Datatype section for more details.

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)"
        }
      }
    }
  }
}

Given Datatype

For the input, you'll have to give the name of the view involved, the package identifier — the name of the package, followed by an ampersand and the version number — and the name of the saved query template in the package.

Table: Input Using Standard Datatypes

Parameter Type Required Default Description
overrideName string     The name of the new saved query to create.
packageId VersionedPackageSpecifier yes   The identifier of the package containing the saved query template. VersionedPackageSpecifier is a scalar
savedQueryTemplateName string yes   The name of the saved query template in the package.
viewName string yes   The name of the view where the package is installed.

Returned Datatype

With the returned datatype, through sub-parameters (see the second table below), you can get a yaml template of the saved query, when and who created it, and other related data — some of which you will know since you will have just created it with this mutation.

Table: CreateSavedQueryFromPackageTemplateMutation

ParameterTypeRequiredDefaultStabilityDescription
Some arguments may be required, as indicated in the Required column. For return datatypes, this indicates that you must specify which fields you want returned in the results.
Table last updated: Sep 24, 2024
savedQuerySavedQueryyes Long-TermThe saved query to create from the package template. See SavedQuery.

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

Table: SavedQuery

ParameterTypeRequiredDefaultStabilityDescription
Some arguments may be required, as indicated in the Required column. For return datatypes, this indicates that you must specify which fields you want returned in the results.
Table last updated: Apr 13, 2026
allowedActions[AssetAction]yes Short-TermThe allowed asset actions. See AssetAction . This is a preview and subject to change.
createdInfoAssetCommitMetadata  Long-TermMetadata related to the creation of the saved query. See AssetCommitMetadata.
descriptionstring  Long-TermA description of the saved query.
displayNamestringyes Long-TermThe display name of the saved query.
idstringyes Long-TermThe unique identifier for the saved query.
interactions[QueryBasedWidgetInteraction]yes Long-TermThe interactions of the saved query. See QueryBasedWidgetInteraction.
isStarredbooleanyes Long-TermWhether the saved query has been marked with a star.
labels[string]yes Long-TermThe labels associated with this saved query.
modifiedInfoAssetCommitMetadata  Long-TermMetadata related to the latest modification of the saved query. See AssetCommitMetadata.
namestringyes Long-TermThe name of the saved query.
optionsJSONyes Long-TermOptions related to the saved query, in JSON form. JSON is a scalar.
packagePackageInstallation  Long-TermThe package, if there is one, in which the saved query is included. See PackageInstallation.
packageIdVersionedPackageSpecifier  Long-TermThe unique identifier of the package. VersionedPackageSpecifier is a scalar value.
qualifiedNamestringyes PreviewThe fully qualified reference format, including the view.
queryHumioQueryyes Long-TermThe saved query itself. See HumioQuery.
resourcestringyes Short-TermThe resource identifier for this saved query.
widgetTypestringyes Long-TermThe type of widget used with the saved query.
yamlTemplateYAMLyes Long-TermA yaml formatted string that describes the saved query. YAML is a scalar. This replaced templateYaml starting in LogScale version 1.225.