Summary

The copySavedQuery() mutation creates a clone of an existing saved query in LogScale. Use it to duplicate a saved query and then modify the copy, rather than building a new query from scratch. You can copy the query to the same repository or view, or to a different one.

Syntax

graphql
copySavedQuery(
      id: String!,
      targetSearchDomainName: String,
      sourceSearchDomainName: String!,
      name: String
   ): CopySavedQueryMutation!

The required arguments are id, the unique identifier of the saved query to copy, and sourceSearchDomainName, the name of the repository or view that contains the source query. The optional targetSearchDomainName specifies the destination repository or view. The optional name sets the name for the new copy. The mutation returns a non-null CopySavedQueryMutation object containing details about the new saved query, including its identifier.

Use the Show Query Example in the Related section to retrieve the id of an existing saved query.

Example

Raw
graphql
mutation {
  copySavedQuery(
    id: "abc123",
    sourceSearchDomainName: "humio",
    name: "my_new_savedquery" 
  ) savedQuery { 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 {
  copySavedQuery(
    id: \"abc123\",
    sourceSearchDomainName: \"humio\",
    name: \"my_new_savedquery\" 
  ) savedQuery { 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 {
  copySavedQuery(
    id: \"abc123\",
    sourceSearchDomainName: \"humio\",
    name: \"my_new_savedquery\" 
  ) savedQuery { 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 { ^
  copySavedQuery( ^
    id: \"abc123\", ^
    sourceSearchDomainName: \"humio\", ^
    name: \"my_new_savedquery\"  ^
  ) savedQuery { id } ^
}" ^
} '
Windows Powershell and curl
powershell
curl.exe -X POST 
    -H "Authorization: Bearer $TOKEN"
    -H "Content-Type: application/json"
    -d '{"query" : "mutation {
  copySavedQuery(
    id: \"abc123\",
    sourceSearchDomainName: \"humio\",
    name: \"my_new_savedquery\" 
  ) savedQuery { 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 {
  copySavedQuery(
    id: \"abc123\",
    sourceSearchDomainName: \"humio\",
    name: \"my_new_savedquery\" 
  ) savedQuery { 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 {
  copySavedQuery(
    id: \"abc123\",
    sourceSearchDomainName: \"humio\",
    name: \"my_new_savedquery\" 
  ) savedQuery { 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 {
  copySavedQuery(
    id: \"abc123\",
    sourceSearchDomainName: \"humio\",
    name: \"my_new_savedquery\" 
  ) savedQuery { 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": {
    "copySavedQuery": {
      "id": "def456"
    }
  }
}

Input Parameters

Provide the unique identifier of the saved query to copy and the name of the repository or view that contains it. Optionally, specify a destination repository or view and a name for the new copy. The preceding Related section includes an example query for retrieving saved query identifiers.

Table: Input Parameters and Datatypes

Parameter Type Required Default Description
This table contains all input parameters for this mutation.
id string yes   The unique identifier of the saved query to copy. Use the repositories() query to retrieve saved query identifiers.
name string     The name for the new saved query. If omitted, LogScale uses the original name. When copying within the same repository or view, LogScale appends (copied) to the original name to avoid a naming conflict.
sourceSearchDomainName string yes   The name of the repository or view that contains the saved query to copy.
targetSearchDomainName string     The name of the repository or view where LogScale places the new saved query. If omitted, the source repository or view is used as the destination.

Returned Values

The mutation returns a CopySavedQueryMutation object. This object contains the new saved query, represented by the SavedQuery datatype, which includes the identifier and other properties of the copy. Use the identifier to make subsequent changes through updateSavedQuery().

Table: CopySavedQueryMutation Datatype

ParameterTypeRequiredDefaultStabilityAvailabilityDescription
savedQuerySavedQueryyes Long-Term  

The following table describes the SavedQuery datatype, which is the sub-type returned within CopySavedQueryMutation.