create

splunkjs.Service.Jobs.create
Endpoint: search/jobs

Creates a search job with a given search query and optional parameters, including exec_mode to specify the type of search:

  • Use exec_mode=normal to return a search job ID immediately (default). Poll for completion to find out when you can retrieve search results.

  • Use exec_mode=blocking to return the search job ID when the search has finished.

To run a oneshot search, which does not create a job but rather returns the search results, use Service.Jobs.oneshotSearch.

Syntax

create: function(query, params, response_timeout)

Parameters

Name Type Description
query String

The search query.

params Object

A dictionary of properties for the search job. For a list of available parameters, see Search job parameters on Splunk Developer Portal.

response_timeout Number

A timeout period for aborting a request in milisecs (0 means no timeout).

init

splunkjs.Service.Jobs.init

Constructor for splunkjs.Service.Jobs.

Syntax

init: function (service, namespace)

Parameters

Name Type Description
service splunkjs.Service

A Service instance.

namespace Object

Namespace information:
- owner (string): The Splunk username, such as "admin". A value of "nobody" means no specific user. The "-" wildcard means all users.
- app (string): The app context for this resource (such as "search"). The "-" wildcard means all apps.
- sharing (string): A mode that indicates how the resource is shared. The sharing mode can be "user", "app", "global", or "system".

Return

splunkjs.Service.Jobs.

A new splunkjs.Service.Jobs instance.

instantiateEntity

splunkjs.Service.Jobs.instantiateEntity

Creates a local instance of a job.

Syntax

instantiateEntity: function(props)

Parameters

Name Type Description
props Object

The properties for this new job. For a list of available parameters, see Search job parameters on Splunk Developer Portal.

Return

splunkjs.Service.Job.

A new splunkjs.Service.Job instance.

oneshotSearch

splunkjs.Service.Jobs.oneshotSearch
Endpoint: search/jobs

Creates a oneshot search from a given search query and parameters.

Syntax

oneshotSearch: function(query, params, response_timeout)

Parameters

Name Type Description
query String

The search query.

params Object

A dictionary of properties for the search:
- output_mode (string): Specifies the output format of the results (XML, JSON, or CSV).
- earliest_time (string): Specifies the earliest time in the time range to search. The time string can be a UTC time (with fractional seconds), a relative time specifier (to now), or a formatted time string.
- latest_time (string): Specifies the latest time in the time range to search. The time string can be a UTC time (with fractional seconds), a relative time specifier (to now), or a formatted time string.
- rf (string): Specifies one or more fields to add to the search.

response_timeout Number

A timeout period for aborting a request in milisecs (0 means no timeout).

Examples

 let jobs = service.jobs();
 let results = await jobs.oneshotSearch("search ERROR", {id: "myjob_123"});
 console.log("RESULT FIELDS": results.fields);

path

splunkjs.Service.Jobs.path

Retrieves the REST endpoint path for this resource (with no namespace).

Syntax

path: function ()

createUrl

splunkjs.Service.Endpoint.createUrl

Create the URL for the get and post methods This is to allow v1 fallback if the service was instantiated with v2+ and a relpath v1 was provided

Syntax

createUrl: function (qualifiedPath, relpath)

Parameters

Name Type Description
qualifiedPath String

A fully-qualified relative endpoint path (for example, "/services/search/jobs").

relpath String

A relative path to append to the endpoint path.

Examples

 // Parameters
 v2 example:
     qualifiedPath = "/servicesNS/admin/foo/search/v2/jobs/id5_1649796951725"
     qualifiedPath = "/services/search/v2/jobs/id5_1649796951725"
     relpath = "search/v2/jobs/id5_1649796951725/events"
     relpath = "events"
 // Step 1:
 Specifically for splunkjs.Service.Job method, the service endpoint may be provided
 Retrieve the service prefix and suffix
     servicesNS:
         - servicePrefix = "/servicesNS/admin/foo"
         - serviceSuffix = "foo/v2/jobs/id5_1649796951725"
     services:
         - servicePrefix = "/services"
         - serviceSuffix = "search/v2/jobs/id5_1649796951725"
 // Step 2:
 Retrieve Service API version
 If version can't be detected, default to 1 (v1)
     qualifiedPathVersion = 2
 // Step 3:
 Retrieve relpath version
 If version can't be detected, default to 1 (v1)
     relpath = "search/v2/jobs/id5_1649796951725/events"
       => relPathVersion = 2
 Check if relpath is a one segment relative path, if so, set to -1
     relpath = "events"
       => relPathVersion = -1
 // Step 4:
 Create the URL based on set criteria
     url = "/servicesNS/admin/foo/search/v2/jobs/id5_1649796951725/events"
     url = "/services/search/v2/jobs/id5_1649796951725/events"

del

splunkjs.Service.Endpoint.del

Performs a relative DELETE request on an endpoint's path, combined with the parameters and a relative path if specified.

Syntax

del: function(relpath, params, response_timeout)

Parameters

Name Type Description
relpath String

A relative path to append to the endpoint path.

params Object

A dictionary of entity-specific parameters to add to the query string.

response_timeout Number

A timeout period for aborting a request in milisecs (0 means no timeout).

Examples

 // Will make a request to {service.prefix}/search/jobs/123456
 let endpoint = new splunkjs.Service.Endpoint(service, "search/jobs/12345");
 let res = await endpoint.delete("", {});
 console.log("DELETED");

fetch

splunkjs.Service.Collection.fetch

Refreshes the resource by fetching the object from the server and loading it.

Syntax

fetch: function(options, response_timeout)

Parameters

Name Type Description
options Object

A dictionary of collection filtering and pagination options:
- count (integer): The maximum number of items to return.
- offset (integer): The offset of the first item to return.
- search (string): The search query to filter responses.
- sort_dir (string): The direction to sort returned items: “asc” or “desc”.
- sort_key (string): The field to use for sorting (optional).
- sort_mode (string): The collating sequence for sorting returned items: “auto”, “alpha”, “alpha_case”, or “num”.

response_timeout Number

A timeout period for aborting a request in milisecs (0 means no timeout).

fetchAsync

splunkjs.Service.Collection.fetchAsync

It's an asynchronous version of fetch(options, response_timeout) function.

Refreshes the resource by fetching the object from the server and loading it.

Syntax

fetchAsync: async function(options, response_timeout)

Parameters

Name Type Description
options Object

A dictionary of collection filtering and pagination options:
- count (integer): The maximum number of items to return.
- offset (integer): The offset of the first item to return.
- search (string): The search query to filter responses.
- sort_dir (string): The direction to sort returned items: “asc” or “desc”.
- sort_key (string): The field to use for sorting (optional).
- sort_mode (string): The collating sequence for sorting returned items: “auto”, “alpha”, “alpha_case”, or “num”.

response_timeout Number

A timeout period for aborting a request in milisecs (0 means no timeout).

fetchOnEntityCreation

splunkjs.Service.Collection.fetchOnEntityCreation

A static property that indicates whether to call fetch after an entity has been created. By default, the entity is not fetched because the endpoint returns (echoes) the new entity.

get

splunkjs.Service.Endpoint.get

Performs a relative GET request on an endpoint's path, combined with the parameters and a relative path if specified.

Syntax

get: function(relpath, params, response_timeout, isAsync)

Parameters

Name Type Description
relpath String

A relative path to append to the endpoint path.

params Object

A dictionary of entity-specific parameters to add to the query string.

response_timeout Number

A timeout period for aborting a request in milisecs (0 means no timeout).

Examples

 // Will make a request to {service.prefix}/search/jobs/123456/results?offset=1
 let endpoint = new splunkjs.Service.Endpoint(service, "search/jobs/12345");
 let res = await endpoint.get("results", {offset: 1});
 console.log("DONE");

item

splunkjs.Service.Collection.item

Returns a specific entity from the collection.

Syntax

item: function(id, namespace)

Parameters

Name Type Description
id String

The name of the entity to retrieve.

namespace Object

Namespace information:
- owner (string): The Splunk username, such as "admin". A value of "nobody" means no specific user. The wildcard value "-", is not acceptable when searching for an entity.
- app (string): The app context for this resource (such as "search"). The wildcard value "-" is unacceptable when searching for an entity.
- sharing (string): A mode that indicates how the resource is shared. The sharing mode can be "user", "app", "global", or "system".

Examples

 let apps = service.apps();
 let res = await apps.fetch();
 let app = res.item("search");
 console.log("Search App Found: " + !!app);
 // `app` is an Application object.

list

splunkjs.Service.Collection.list

Retrieves a list of all entities in the collection.

Syntax

list: function()

Examples

 let apps = service.apps();
 let res = await apps.fetch();
 let appList = res.list();
 console.log(appList.length);

paging

splunkjs.Service.Collection.paging

Retrieves the author information for this collection.

Syntax

paging: function()

Return

String.

The author.

post

splunkjs.Service.Endpoint.post

Performs a relative POST request on an endpoint's path, combined with the parameters and a relative path if specified.

Syntax

post: function(relpath, params, response_timeout)

Parameters

Name Type Description
relpath String

A relative path to append to the endpoint path.

params Object

A dictionary of entity-specific parameters to add to the body.

response_timeout Number

A timeout period for aborting a request in milisecs (0 means no timeout).

Examples

 // Will make a request to {service.prefix}/search/jobs/123456/control
 let endpoint = new splunkjs.Service.Endpoint(service, "search/jobs/12345");
 let res = await endpoint.post("control", {action: "cancel"});
 console.log("CANCELLED");

properties

splunkjs.Service.Resource.properties

Retrieves the current properties for this resource.

Syntax

properties: function()

Return

Object.

The properties.

state

splunkjs.Service.Resource.state

Retrieves the current full state (properties and metadata) of this resource.

Syntax

state: function()

Return

Object.

The current full state of this resource.

updated

splunkjs.Service.Collection.updated

Retrieves the updated time for this collection.

Syntax

updated: function()

Return

String.

The updated time.