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

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

init

splunkjs.Service.Endpoint.init

Constructor for splunkjs.Service.Endpoint.

Syntax

init: function(service, qualifiedPath)

Parameters

Name Type Description
service splunkjs.Service

A Service instance.

qualifiedPath String

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

Return

splunkjs.Service.Endpoint.

A new splunkjs.Service.Endpoint instance.

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