Summary

The addRecentQuery() GraphQL mutation is used to add a query to the list of recent queries. The query is a JSON encoded query and visualization structure produced by the user-interface.

API Stability Long-Term

Syntax

graphql
addRecentQuery(
      input: AddRecentQueryInput!
    ): AddRecentQuery!

For the input, you'll have to give the view's name, the query and its arguments, when it starts and ends, etc. See the Input Parameters section for details.

For the results, you can get the query used and any arguments, when it's run, etc. See the Returned Values section for more.

Example

Raw
graphql
mutation test {
  addRecentQuery(input: {
    viewName: "humio",
    queryArguments: [],
    queryString: "#kind=threaddumps | NOT \"(Native Method)\" | top(humioLine)",
		start: "3d",
    end: "now",
    isLive: false,
  }) {
    recentQueries {
      query {
        queryString,
        start,
        end,
        arguments {
          key,
          value,
        }
      }
    }
  }
}
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 test {
  addRecentQuery(input: {
    viewName: \"humio\",
    queryArguments: [],
    queryString: \"#kind=threaddumps | NOT \\"(Native Method)\\" | top(humioLine)\",
		start: \"3d\",
    end: \"now\",
    isLive: false,
  }) {
    recentQueries {
      query {
        queryString,
        start,
        end,
        arguments {
          key,
          value,
        }
      }
    }
  }
}"
}
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 test {
  addRecentQuery(input: {
    viewName: \"humio\",
    queryArguments: [],
    queryString: \"#kind=threaddumps | NOT \\"(Native Method)\\" | top(humioLine)\",
		start: \"3d\",
    end: \"now\",
    isLive: false,
  }) {
    recentQueries {
      query {
        queryString,
        start,
        end,
        arguments {
          key,
          value,
        }
      }
    }
  }
}"
}
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 test { ^
  addRecentQuery(input: { ^
    viewName: \"humio\", ^
    queryArguments: [], ^
    queryString: \"#kind=threaddumps | NOT \\"(Native Method)\\" | top(humioLine)\", ^
		start: \"3d\", ^
    end: \"now\", ^
    isLive: false, ^
  }) { ^
    recentQueries { ^
      query { ^
        queryString, ^
        start, ^
        end, ^
        arguments { ^
          key, ^
          value, ^
        } ^
      } ^
    } ^
  } ^
}" ^
} '
Windows Powershell and curl
powershell
curl.exe -X POST 
    -H "Authorization: Bearer $TOKEN"
    -H "Content-Type: application/json"
    -d '{"query" : "mutation test {
  addRecentQuery(input: {
    viewName: \"humio\",
    queryArguments: [],
    queryString: \"#kind=threaddumps | NOT \\"(Native Method)\\" | top(humioLine)\",
		start: \"3d\",
    end: \"now\",
    isLive: false,
  }) {
    recentQueries {
      query {
        queryString,
        start,
        end,
        arguments {
          key,
          value,
        }
      }
    }
  }
}"
}'
    "$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 test {
  addRecentQuery(input: {
    viewName: \"humio\",
    queryArguments: [],
    queryString: \"#kind=threaddumps | NOT \\"(Native Method)\\" | top(humioLine)\",
		start: \"3d\",
    end: \"now\",
    isLive: false,
  }) {
    recentQueries {
      query {
        queryString,
        start,
        end,
        arguments {
          key,
          value,
        }
      }
    }
  }
}";
$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 test {
  addRecentQuery(input: {
    viewName: \"humio\",
    queryArguments: [],
    queryString: \"#kind=threaddumps | NOT \\"(Native Method)\\" | top(humioLine)\",
		start: \"3d\",
    end: \"now\",
    isLive: false,
  }) {
    recentQueries {
      query {
        queryString,
        start,
        end,
        arguments {
          key,
          value,
        }
      }
    }
  }
}"
}'''

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 test {
  addRecentQuery(input: {
    viewName: \"humio\",
    queryArguments: [],
    queryString: \"#kind=threaddumps | NOT \\"(Native Method)\\" | top(humioLine)\",
		start: \"3d\",
    end: \"now\",
    isLive: false,
  }) {
    recentQueries {
      query {
        queryString,
        start,
        end,
        arguments {
          key,
          value,
        }
      }
    }
  }
}"
}
);


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();

Input Parameters

For the input, you'll have to give the name of the view, the query and its arguments, when it starts and ends, and other factors. These are described in the table below:

Table: AddRecentQueryInput Input Datatype

ParameterTypeRequiredDefaultStabilityDescription
Some input parameters may be required, as indicated in the Required column. For return values, this indicates that you are assured a value if the field is requested for the results.
Table last updated: Sep 17, 2024
endstringyes Long-TermThe end of the relative time interval for the query.
isLivebooleanyes Long-TermWhether the query is live.
optionsJSON  Long-TermAny options related to the query. JSON is a scalar.
queryArguments[InputDictionaryEntry]yes Long-TermArguments related to the recent query. See InputDictionaryEntry.
queryStringstringyes Long-TermThe query string.
startstringyes Long-TermThe start of the relative time interval for the query.
viewNamestringyes Long-TermThe name of the view.
widgetTypestring  Long-TermThe type of widget used, if one.

Returned Values

For the results, you can get the LogScale query used and any arguments for the query, when it's run and related information.

Table: AddRecentQuery Datatype

ParameterTypeRequiredDefaultStabilityDescription
Some input parameters may be required, as indicated in the Required column. For return values, this indicates that you are assured a value if the field is requested for the results.
Table last updated: Sep 23, 2024
recentQueries[RecentQuery]yes Long-TermA list of recently run queries. See RecentQuery.

Table: RecentQuery Datatype

ParameterTypeRequiredDefaultStabilityDescription
Some input parameters may be required, as indicated in the Required column. For return values, this indicates that you are assured a value if the field is requested for the results.
Table last updated: Oct 3, 2024
languageVersionLanguageVersionyes Long-TermThe language version used by LogScale See LanguageVersion.
queryHumioQueryyes Long-TermThe query used most recently. See HumioQuery.
runAtdatetimeyes Long-TermThe date and time in the ISO-8601 instant format (e.g., 2022-12-03T10:15:30.00Z).
widgetOptionsJSON  Long-TermAny widget options used, in JSON format. JSON is a scalar.
widgetTypestring  Long-TermThe type of widget used, if one, with the recent query.