Summary

The addRecentQuery() mutation adds a query to the recent query history for a view. The input specifies the query string, time range, live status, arguments, and optional visualization settings. To remove all entries from the recent query history, call clearRecentQueries().

Syntax

graphql
addRecentQuery(
      input: AddRecentQueryInput!
   ): AddRecentQuery!

The mutation accepts a single required input argument of type AddRecentQueryInput, which specifies the view, query string, time range, arguments, and visualization options. The mutation returns a non-null AddRecentQuery object containing the updated list of recent queries for the view.

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

AddRecentQueryInput has six required fields: viewName, queryString, queryArguments, start, end, and isLive. The start and end fields accept relative time strings (for example, 1h or 3d) or absolute timestamps. The queryArguments field is a list of key-value pairs that parameterize the query string. The optional widgetType field identifies the visualization widget associated with the query. The optional options field is a JSON object that contains additional widget settings.

Table: AddRecentQueryInput Input Datatype

ParameterTypeRequiredDefaultStabilityAvailabilityDescription
endStringyes    
isLiveBooleanyes    
optionsJSON     
queryArgumentsInputDictionaryEntryyes    
queryStringStringyes    
startStringyes    
viewNameStringyes    
widgetTypeString     

Returned Values

The mutation returns an AddRecentQuery object. The recentQueries field contains the updated list of recent queries for the view. Each RecentQuery entry includes the execution timestamp (runAt), the associated HumioQuery object (which contains the query string, time range, and live status), the query language version, and optional widget type and widget options.

Table: AddRecentQuery Datatype

ParameterTypeRequiredDefaultStabilityAvailabilityDescription
recentQueriesRecentQueryyes Long-Term  

Table: RecentQuery Datatype

ParameterTypeRequiredDefaultStabilityAvailabilityDescription
languageVersionLanguageVersionyes Long-Term  
queryHumioQueryyes Long-Term  
runAtDateTimeyes Long-Term  
widgetOptionsJSON  Long-Term  
widgetTypeString  Long-Term Â