{"id":13696731,"url":"https://github.com/splunk/splunk-sdk-javascript","last_synced_at":"2025-05-15T04:05:03.591Z","repository":{"id":1507520,"uuid":"1763691","full_name":"splunk/splunk-sdk-javascript","owner":"splunk","description":"Splunk Software Development Kit for JavaScript","archived":false,"fork":false,"pushed_at":"2025-03-28T09:57:50.000Z","size":50935,"stargazers_count":191,"open_issues_count":8,"forks_count":93,"subscribers_count":50,"default_branch":"master","last_synced_at":"2025-04-14T22:14:48.164Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://dev.splunk.com/javascript","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/splunk.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2011-05-18T00:31:30.000Z","updated_at":"2025-04-04T02:19:31.000Z","dependencies_parsed_at":"2025-04-14T20:45:56.309Z","dependency_job_id":"bc772869-510c-452b-aef8-a340a5ad776e","html_url":"https://github.com/splunk/splunk-sdk-javascript","commit_stats":{"total_commits":1628,"total_committers":35,"mean_commits":46.51428571428571,"dds":0.6296068796068797,"last_synced_commit":"46ef1127eb01a61628e71de7d99d42eecb93ef6c"},"previous_names":[],"tags_count":31,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/splunk%2Fsplunk-sdk-javascript","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/splunk%2Fsplunk-sdk-javascript/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/splunk%2Fsplunk-sdk-javascript/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/splunk%2Fsplunk-sdk-javascript/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/splunk","download_url":"https://codeload.github.com/splunk/splunk-sdk-javascript/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254270642,"owners_count":22042859,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T18:00:45.805Z","updated_at":"2025-05-15T04:04:58.574Z","avatar_url":"https://github.com/splunk.png","language":"JavaScript","readme":"[![Build Status](https://travis-ci.org/splunk/splunk-sdk-javascript.svg?branch=master)](https://travis-ci.org/splunk/splunk-sdk-javascript)\n# The Splunk Enterprise Software Development Kit for JavaScript\n\n#### Version 2.0.2\n\nThe Splunk Enterprise Software Development Kit (SDK) for JavaScript contains library code and examples designed to enable developers to build applications using the Splunk platform and JavaScript. This SDK supports server-side and client-side JavaScript.\n\nFor more information, see [Splunk Enterprise SDK for JavaScript](https://dev.splunk.com/enterprise/docs/devtools/javascript/sdk-javascript/) on the Splunk Developer Portal.\n\n## Requirements\n\n* Node.js v 8.17.0, or v14 or later\n\n    The Splunk Enterprise SDK for JavaScript was tested with Node.js v8.17.0, v14. \n\n* Splunk Enterprise 9.0 or 8.2, or Splunk Cloud\n\n    The Splunk Enterprise SDK for JavaScript was tested with Splunk Enterprise 9.0 or 8.2, or Splunk Cloud. \n\n*  Splunk Enterprise SDK for JavaScript\n\n    Download the SDK as a [ZIP file](https://github.com/splunk/splunk-sdk-javascript/zipball/master) or clone the repository:\n\n        git clone https://github.com/splunk/splunk-sdk-javascript.git\n\n\n## Installation\n\nThis section describes the basic steps for installing the Splunk Enterprise SDK for JavaScript.\n\n\n### Use the Splunk Enterprise SDK for JavaScript components on your web page\n\nTo use the components from the Splunk Enterprise SDK for JavaScript on your web page, copy the **/splunk-sdk-javascript/client** directory to your web server.\nThen, include the **splunk.js** or **splunk.min.js** file from this directory in your code.\n\nFor example, include one of the following tags in your code:\n\n    \u003cscript type=\"text/javascript\" src=\"/yourpath/splunk.js\"\u003e\u003c/script\u003e\n\nOr:\n\n    \u003cscript type=\"text/javascript\" src=\"/yourpath/splunk.min.js\"\u003e\u003c/script\u003e\n\nYou can also include the UI components, such as the Timeline and Charting controls. These UI component files (**splunk.ui.timeline** and **splunk.ui.charting**) are also in the **/splunk-sdk-javascript/client** directory.\n\n### Install Node.js in your project\n\nTo use the Splunk Enterprise SDK for JavaScript with your Node.js programs, install the SDK by running `npm` in *your* project's directory as follows:\n\n    npm install splunk-sdk\n\nThen, to include the Splunk Enterprise SDK for JavaScript, use the `require` function in your code:\n\n    let splunkjs = require('splunk-sdk');\n\n## Usage\n\nThe following examples show you how to list search jobs using client-side and server-side code.\n\n### Migrate from Callbacks(v1.x) to Promise/async-await(v2.x)\n\nPrevious Callback Approach:\n```javascript\nlet appName = \"\u003capp-name\u003e\";\n\nservice.apps().fetch(function (err, apps) {\n    if (err) {\n        done(err);\n    }\n    let appList = apps.list();\n    // other code\n    done();\n});\n```\n\nFrom v2.x, Splunk Enterprise SDK for JavaScript methods are updated to return Promises, which will enable users to utilize Async/await feature of JS.\n\nPromise Approach:\n```javascript\nlet appName = \"\u003capp-name\u003e\";  \ntry {\n    let apps = await service.apps().fetch();\n    let appList = apps.list();\n    // other code\n} catch (err) {\n    console.log(\"There was an error retrieving the list of applications:\", err);\n}\n```\n\n\u003e**Note**: `abort()` method has been replaced with 'response_timeout' parameter which enables user to specify the timeout for a particular API call.\n\n### Client-side code example\n\nThis HTML example uses the Splunk Enterprise SDK for JavaScript to list all jobs:\n```javascript\n    \u003cscript type=\"text/javascript\" src=\"splunk.js\"\u003e\u003c/script\u003e\n    \u003cscript type=\"text/javascript\" src=\"jquery.min.js\"\u003e\u003c/script\u003e\n\n    \u003cscript type=\"text/javascript\" charset=\"utf-8\"\u003e\n        try {\n            let service = new splunkjs.Service({username: \"admin\", password: \"changed!\"});\n            await service.login();\n            console.log(\"Login was successful\");\n            let jobs = await service.jobs().fetch();    \n            let jobList = jobs.list();\n            for(let i = 0; i \u003c jobList.length; i++) {\n                console.log(\"Job \" + i + \": \" + jobList[i].sid);\n            }\n        } catch(err) {\n            console.log(err);\n        }\n    \u003c/script\u003e\n```\n\n### Node.js code example\n\nThis example shows how to use the Splunk Enterprise SDK for JavaScript and Node.js to list all jobs:\n\n##### Login with username and password\n\n```javascript\n    let splunkjs = require('splunk-sdk');\n\n    let service = new splunkjs.Service({username: \"admin\", password: \"changed!\"});\n    try {\n        await service.login();\n        console.log(\"Login was successful: \" + success);\n        let jobs = await jobs.fetch();\n        let jobList = jobs.list();\n        for(let i = 0; i \u003c jobList.length; i++) {\n            console.log(\"Job \" + i + \": \" + jobList[i].sid);\n        }\n    } catch(err) {\n        console.log(err);\n    }  \n    \n```\n##### Login with sessionKey\n\n```shell\n# Create a sessionKey\ncurl -k -u \u003cusername\u003e:\u003cpassword\u003e  \u003cscheme\u003e://\u003chost\u003e:\u003cport\u003e/services/auth/login -d username=\u003cusername\u003e -d password=\u003cpassword\u003e\n```\n\n```javascript\nlet serviceWithSessionKey = new splunkjs.Service({\n    // Replace the host if you are accessing remote host\n    scheme: 'https',\n    host: 'localhost',\n    port: '8089',\n    sessionKey: SESSION_KEY, // Add your sessionKey here\n    version: '9.0',\n});\ntry {\n    let jobs = await serviceWithSessionKey.jobs({ count: 1 });\n    console.log(\"Login successful with sessionKey\");\n} catch(err) {\n    console.log(err);\n}\n\n##### Login with token\n\n```shell\n#### From shell ####\n# Enable token authetication\ncurl -k -u \u003cusername\u003e:\u003cpassword\u003e -X POST \u003cscheme\u003e://\u003chost\u003e:\u003cport\u003e/services/admin/token-auth/tokens_auth -d disabled=false\n\n# Create a token\ncurl -k -u \u003cusername\u003e:\u003cpassword\u003e -X POST \u003cscheme\u003e://\u003chost\u003e:\u003cport\u003e/services/authorization/tokens?output_mode=json --data name=\u003cusername\u003e --data audience=Users --data-urlencode expires_on=+30d\n```\n\n```shell\n#### From web ####\n# Enable token authentication\nGo to settings \u003e Tokens and click on 'Enable Token Authentication'\n\n# Create a token\n1. Go to settings \u003e Token and click on 'New Token'\n2. Enter the relevant information\n3. Copy the created token and save it somewhere safe.\n```\n\n```javascript\nlet serviceWithBearerToken = new splunkjs.Service({\n    // Replace the host if you are accessing remote host\n    scheme: 'https',\n    host: 'localhost',\n    port: '8089',\n    sessionKey: TOKEN, // Add your token here\n    version: '8',\n});\ntry {\n    let res  = await serviceWithBearerToken.jobs({ count: 2 });\n    console.log(\"Login successful with bearer token\");\n} catch(err) {\n    console.log(err);\n}\n\n```\n\n### Modular inputs examples\nSupport for modular inputs is removed from Splunk Enterprise SDK for JavaScript and we recommand to use [Splunk Enterprise SDK for Python](https://github.com/splunk/splunk-sdk-python) for the modular inputs. See the [Python SDK modular inputs example](https://github.com/splunk/splunk-app-examples/tree/master/modularinputs/python) and [PythonSDK modular inputs docs](https://dev.splunk.com/enterprise/docs/devtools/python/sdk-python/howtousesplunkpython/howtocreatemodpy) for reference.\n\n## SDK examples\n\nThe Splunk Enterprise SDK for JavaScript contains several server- and client-based examples, which are located in the [Splunk App Example repo](https://github.com/splunk/splunk-app-examples).\nFor details, see the [Splunk Enterprise SDK for JavaScript Examples](https://dev.splunk.com/enterprise/docs/devtools/javascript/sdk-javascript/sdkjavascriptexamples) on the Splunk Developer Portal.\n\n## Create a .splunkrc convenience file\n\nTo connect to Splunk Enterprise, many of the SDK unit tests take command-line arguments that specify values for the host, port, and login credentials for Splunk Enterprise. For convenience during development, you can store these arguments as key-value pairs in a text file named **.splunkrc**. Then, the SDK unit tests use the values from the **.splunkrc** file when you don't specify them.\n\n\u003e**Note**: Storing login credentials in the **.splunkrc** file is only for convenience during development. This file isn't part of the Splunk platform and shouldn't be used for storing user credentials for production. And, if you're at all concerned about the security of your credentials, enter them at the command line rather than saving them in this file.\n\nTo use this convenience file, create a text file with the following format:\n\n    # Splunk Enterprise host (default: localhost)\n    host=localhost\n    # Splunk Enterprise admin port (default: 8089)\n    port=8089\n    # Splunk Enterprise username\n    username=admin\n    # Splunk Enterprise password\n    password=changed!\n    # Access scheme (default: https)\n    scheme=https\n    # Your version of Splunk Enterprise\n    version=9.0\n\nSave the file as **.splunkrc** in the current user's home directory.\n\n*   For example on OS X, save the file as:\n\n        ~/.splunkrc\n\n*   On Windows, save the file as:\n\n        C:\\Users\\currentusername\\.splunkrc\n\n    You might get errors in Windows when you try to name the file because \".splunkrc\" appears to be a nameless file with an extension. You can use the command line to create this file by going to the **C:\\Users\\\\\u0026lt;currentusername\u0026gt;** directory and entering the following command:\n\n        Notepad.exe .splunkrc\n\n    Click **Yes**, then continue creating the file.\n\n### Create/Update a .conf file\n```javascript\n    let configs = svc.configurations(namespace);\n    configs = await configs.fetch();\n    // Create a key-value map to store under a stanza\n    const filename = \"app.conf\";\n    const stanzaName = \"install\";\n    let keyValueMap = {};\n    keyValueMap[\"state\"] = \"enabled\";\n    keyValueMap[\"python.version\"] = \"python3\";  \n\n    // If file/stanza doesn't exist, it will be created \n    // else it will be updated.\n    await configs.createAsync(filename, stanzaName, keyValueMap);\n```\n\n## Development\n\nThe Splunk Enterprise SDK for JavaScript infrastructure relies on Node.js to build files, run examples, run tests, and generate documentation. \n\nAll development activities are managed by a helper script called `sdkdo`. For a list of possible commands and options, open a command prompt in the **splunk-sdk-javascript** directory and enter:\n\n    node sdkdo --help\n\n### Compile the browser files\n\nTo rebuild and minify the browser files, open a command prompt in the **splunk-sdk-javascript** directory and enter:\nNote:- If any TypeError is encountered, please run \"npm install\" before running the below command.\n\n    node sdkdo compile\n\n### Run unit tests\n\nThe Splunk Enterprise SDK for JavaScript includes several unit tests for each component. You can run individual test modules or run all tests. Some searches need to be running in your Splunk Enterprise instance before you run these tests. You can start some searches by logging into Splunk Web and opening the Search app, which runs a few searches to populate the dashboard.\n\n\u003e**Note**: The [SDK App Collection](https://github.com/splunk/sdk-app-collection) app is required for running unit tests.\n\nTo run the unit tests, open a command prompt in the **splunk-sdk-javascript** directory, then run the following commands. \n\nTo run all tests, enter:\n\n    node sdkdo tests\n\nTo run the HTTP and the utils tests, enter:\n\n    node sdkdo tests http,utils\n\nTo run tests containing a particular string, enter:\n\n    node sdkdo tests --grep \"While success\"\n\nTo run the browser tests, enter:\n\n    node sdkdo tests-browser\n\nTo run all unit tests without log messages, enter:\n\n    node sdkdo tests --quiet\n\nTo run all the tests and generate test report in **splunk-sdk-javascript/mochawesome-report/mochawesome.html**, enter:\n\n    node sdkdo tests --reporter mochawesome\n\nTo get more info to run tests, enter:\n\n    make test_specific\n\n## Repository\n\n| Directory     | Description                                                |\n|:------------- |:---------------------------------------------------------- |\n| /bin          | Executable files (such as sdkdo)                           |\n| /client       | Pre-built files for the browser                            |\n| /contrib      | Packaged third-party dependencies (such as test runners)   |\n| /docs         | API reference documentation                                |\n| /lib          | The SDK code files                                         |\n| /licenses     | License information for packaged third-party dependencies  |\n| /node_modules | JavaScript modules used by Node.js                         |\n| /tests        | Unit tests                                                 |\n\n### Changelog\n\nThe [CHANGELOG](CHANGELOG.md) contains a description of changes for each version of the SDK. For the latest version, see the [CHANGELOG.md](https://github.com/splunk/splunk-sdk-javascript/blob/master/CHANGELOG.md) on GitHub.\n\n### Branches\n\nThe **master** branch represents a stable and released version of the SDK.\nTo learn about our branching model, see [Branching Model](https://github.com/splunk/splunk-sdk-javascript/wiki/Branching-Model) on GitHub.\n\n## Documentation and resources\n\n| Resource                | Description |\n|:----------------------- |:----------- |\n| [Splunk Developer Portal](http://dev.splunk.com) | General developer documentation, tools, and examples |\n| [Integrate the Splunk platform using development tools for JavaScript](https://dev.splunk.com/enterprise/docs/devtools/javascript)| Documentation for JavaScript development |\n| [Splunk Enterprise SDK for JavaScript Reference](http://docs.splunk.com/Documentation/JavaScriptSDK) | SDK API reference documentation |\n| [REST API Reference Manual](https://docs.splunk.com/Documentation/Splunk/latest/RESTREF/RESTprolog) | Splunk REST API reference documentation |\n| [Splunk\u003eDocs](https://docs.splunk.com/Documentation) | General documentation for the Splunk platform |\n| [GitHub Wiki](https://github.com/splunk/splunk-sdk-javascript/wiki/) | Documentation for this SDK's repository on GitHub |\n| [Splunk JavaScript SDK Examples](https://github.com/splunk/splunk-app-examples) | server- and client-based examples for the Splunk JavaScript SDK |\n\n\n## Community\n\nStay connected with other developers building on the Splunk platform.\n\n* [Email](mailto:devinfo@splunk.com)\n* [Issues and pull requests](https://github.com/splunk/splunk-sdk-javascript/issues/)\n* [Community Slack](https://splunk-usergroups.slack.com/app_redirect?channel=appdev)\n* [Splunk Answers](https://community.splunk.com/t5/Splunk-Development/ct-p/developer-tools)\n* [Splunk Blogs](https://www.splunk.com/blog)\n* [Twitter](https://twitter.com/splunkdev)\n\n### Contributions\n\nIf you would like to contribute to the SDK, see [Contributing to Splunk](https://www.splunk.com/en_us/form/contributions.html). For additional guidelines, see [CONTRIBUTING](CONTRIBUTING.md). \n\n### Support\n\n*  You will be granted support if you or your company are already covered under an existing maintenance/support agreement. Submit a new case in the [Support Portal](https://www.splunk.com/en_us/support-and-services.html) and include \"Splunk Enterprise SDK for JavaScript\" in the subject line.\n\n   If you are not covered under an existing maintenance/support agreement, you can find help through the broader community at [Splunk Answers](https://community.splunk.com/t5/Splunk-Development/ct-p/developer-tools).\n\n*  Splunk will NOT provide support for SDKs if the core library (the code in the **/splunklib** directory) has been modified. If you modify an SDK and want support, you can find help through the broader community and [Splunk Answers](https://community.splunk.com/t5/Splunk-Development/ct-p/developer-tools). \n\n   We would also like to know why you modified the core library, so please send feedback to _devinfo@splunk.com_.\n\n*  File any issues on [GitHub](https://github.com/splunk/splunk-sdk-javascript/issues).\n\n\n### Contact us\n\nYou can reach the Splunk Developer Platform team at _devinfo@splunk.com_.\n\n## License\n\nThe Splunk Enterprise Software Development Kit for JavaScript is licensed under the Apache License 2.0. See [LICENSE](LICENSE) for details.\n","funding_links":[],"categories":["Node JS"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsplunk%2Fsplunk-sdk-javascript","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsplunk%2Fsplunk-sdk-javascript","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsplunk%2Fsplunk-sdk-javascript/lists"}