The createSavedQuery() GraphQL mutation may be used to create a saved query in LogScale. This is a preview and subject to change.

For more information on saved queries, see the User Functions (Saved Searches) reference page where saved queries are discussed. Also, look at the Searching Data documentation page as it relates to recent queries and saving queries.

Syntax

Below is the syntax for the createSavedQuery() mutation field:

graphql
createSavedQuery(
      input: CreateSavedQueryInput!
   ): CreateSavedQueryPayload!

Below is an example of how this mutation field might be used:

Raw
graphql
mutation {
  createSavedQuery( input:
   { name: "my-saved-query",
     viewName: "humio",
     queryString: "@host=localhost"
  }  )
  { savedQuery {id, allowedActions}  }
}
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 {
  createSavedQuery( input:
   { name: \"my-saved-query\",
     viewName: \"humio\",
     queryString: \"@host=localhost\"
  }  )
  { savedQuery {id, allowedActions}  }
}"
}
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 {
  createSavedQuery( input:
   { name: \"my-saved-query\",
     viewName: \"humio\",
     queryString: \"@host=localhost\"
  }  )
  { savedQuery {id, allowedActions}  }
}"
}
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 { ^
  createSavedQuery( input: ^
   { name: \"my-saved-query\", ^
     viewName: \"humio\", ^
     queryString: \"@host=localhost\" ^
  }  ) ^
  { savedQuery {id, allowedActions}  } ^
}" ^
} '
Windows Powershell and curl
powershell
curl.exe -X POST 
    -H "Authorization: Bearer $TOKEN"
    -H "Content-Type: application/json"
    -d '{"query" : "mutation {
  createSavedQuery( input:
   { name: \"my-saved-query\",
     viewName: \"humio\",
     queryString: \"@host=localhost\"
  }  )
  { savedQuery {id, allowedActions}  }
}"
}'
    "$YOUR_LOGSCALE_URL/graphql"
Perl
perl
#!/usr/bin/perl

use HTTP::Request;
use LWP;

my $INGEST_TOKEN = "TOKEN";

my $uri = '$YOUR_LOGSCALE_URL/graphql';

my $json = '{"query" : "mutation {
  createSavedQuery( input:
   { name: \"my-saved-query\",
     viewName: \"humio\",
     queryString: \"@host=localhost\"
  }  )
  { savedQuery {id, allowedActions}  }
}"
}';
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 {
  createSavedQuery( input:
   { name: \"my-saved-query\",
     viewName: \"humio\",
     queryString: \"@host=localhost\"
  }  )
  { savedQuery {id, allowedActions}  }
}"
}'''

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 {
  createSavedQuery( input:
   { name: \"my-saved-query\",
     viewName: \"humio\",
     queryString: \"@host=localhost\"
  }  )
  { savedQuery {id, allowedActions}  }
}"
}
);


const options = {
  hostname: '$YOUR_LOGSCALE_URL/graphql',
  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": {
    "createSavedQuery": {
      "savedQuery": {
        "id": "S07kKBwioqCaOwkmpz7m9XSfQ9v1eWXb",
        "allowedActions": [
          "Read",
          "Update"
        ]
      }
    }
  }
}

Given Datatypes

For the given datatype, CreateSavedQueryInput, there are several parameters that may be given. Below is a list of them along with descriptions of each:

Table: CreateSavedQueryInput

ParameterTypeRequiredDefaultDescription
Some arguments may be required, as indicated in the Required column. For some fields, this column indicates that a result will always be returned for this column.
Table last updated: Sep 17, 2024
customLinkInteractions[CustomLinkInteractionInput]yes The custom links for interactions. See CustomLinkInteractionInput.
dashboardLinkInteractions[DashboardLinkInteractionInput]yes The dashboard links for interactions. See DashboardLinkInteractionInput.
endstring  The end point for events processed by the saved query.
isLiveboolean  Whether the saved query uses live, streaming data.
namestringyes The name of the saved query to create.
optionsstring  Any options related to the saved query.
queryStringstringyes The query to be used, to be saved.
searchLinkInteractions[SearchLinkInteractionInput]yes The search links for interactions. See SearchLinkInteractionInput.
startstring  The start point for events processed by the saved query.
updateParametersInteractions[UpdateParametersInteractionInput]yes The parameters to update for interactions. See UpdateParametersInteractionInput.
viewNamestringyes The name of the view associated with the saved query.
widgetTypestring  The type of widget to use for dispaly the results for the saved query.

Returned Datatypes

CreateSavedQueryPayload has one parameter, but if you click on it in the table below, you'll see that it has several sub-parameters:

Table: CreateSavedQueryPayload

ParameterTypeRequiredDefaultDescription
Some arguments may be required, as indicated in the Required column. For some fields, this column indicates that a result will always be returned for this column.
Table last updated: Sep 24, 2024
savedQuerySavedQueryyes The saved query to create from payload. See SavedQuery.