# sn-jsonv2

> Wrapper for the ServiceNow JSONv2 API

Latest version **1.0.10** (published 2017-06-02) · ISC license · 0 weekly downloads

## Install

```sh
npm install sn-jsonv2
pnpm add sn-jsonv2
yarn add sn-jsonv2
bun add sn-jsonv2
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.10 |
| Published | 2017-06-02 |
| First published | 2017-05-18 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 6 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | benthomasknight |
| Maintainers | benthomasknight |
| Keywords | servicenow, service, now, json, jsonv2 |

## Links

- npm: https://www.npmjs.com/package/sn-jsonv2
- Repository: https://github.com/benthomasknight/sn-jsonv2
- Homepage: https://github.com/benthomasknight/sn-jsonv2#readme
- Issues: https://github.com/benthomasknight/sn-jsonv2/issues
- npm.io page: https://npm.io/package/sn-jsonv2

## Dependencies (6)

- [debug](https://npm.io/package/debug.md) ^2.6.6
- [request](https://npm.io/package/request.md) ^2.81.0
- [@types/debug](https://npm.io/package/@types/debug.md) 0.0.29
- [@types/request](https://npm.io/package/@types/request.md) 0.0.43
- [request-promise-native](https://npm.io/package/request-promise-native.md) ^1.0.4
- [@types/request-promise-native](https://npm.io/package/@types/request-promise-native.md) ^1.0.5

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.0.10 (latest) — 2017-06-02
- 1.0.9 — 2017-05-19
- 1.0.8 — 2017-05-19
- 1.0.7 — 2017-05-19
- 1.0.6 — 2017-05-19
- 1.0.5 — 2017-05-19
- 1.0.4 — 2017-05-18
- 1.0.3 — 2017-05-18
- 1.0.2 — 2017-05-18
- 1.0.1 — 2017-05-18
- 1.0.0 — 2017-05-18

## README

# Module for the JsonV2 API in ServiceNow

Docs for the API available from the [ServiceNow Website](https://docs.servicenow.com/bundle/istanbul-servicenow-platform/page/integrate/inbound-other-web-services/concept/c_JSONv2WebService.html).

Current Support

- Encoded Queries
- Sys Id Queries

## Format of Data

Data returned as an object as specified in the [docs](https://docs.servicenow.com/bundle/istanbul-servicenow-platform/page/integrate/inbound-other-web-services/concept/c_JSONObjectFormat.html)

## Usage

For more information on the various parameters and what they do, go to the [docs here.](https://docs.servicenow.com/bundle/istanbul-servicenow-platform/page/integrate/inbound-other-web-services/concept/c_ActionParameters.html)

### Query design

There are two constructors for creating a query. You can pass an object containing the parameters or pass each parameter individually. The below two constructors will return the same result.

```#Javascript
var SNQuery = require('sn-jsonv2').SNQuery;
var GetActions = require('sn-jsonv2').GetActions;

var options = {
  table:'sys_user',
  sysparm_action:GetActions.getRecords,
  sysparm_view:null,
  sysparm_query:'active=true',
  sysparm_sys_id:null,
  sysparm_record_count:10,
  displayvalue:false,
  displayvariables:false
};
var query = new SNQuery(options);

var query2 = new SNQuery('sys_user', GetActions.getRecords, null, 'active=true', null, 10, false, false);
```

### Running a Query

To run a query you you need to have an SNJsonV2 object with instance information, then pass the query (options, or a query object as specified above) to its run function. It will return a promise of results.

```#Javascript
var SNJsonV2 = require('sn-jsonv2').SNJsonV2;
var GetActions = require('sn-jsonv2').GetActions;

var instance = new SNJsonV2('instanceName', 'username', 'password');

var options = {
  table:'sys_user',
  sysparm_action:GetActions.getRecords,
  sysparm_view:null,
  sysparm_query:'active=true',
  sysparm_sys_id:null,
  sysparm_record_count:10,
  displayvalue:false,
  displayvariables:false
};

var results = instance.run(options);
```

### Posting

This API supports sending data to the instance, as described [here](https://docs.servicenow.com/bundle/istanbul-servicenow-platform/page/integrate/inbound-other-web-services/concept/c_DataModificationAPI.html). To post to the server, add what you want to send to the 'data' variable on the query options object. Each key on the object should be a column name on the provided table.

```#Javascript
var PostActions = require('sn-jsonv2').PostActions;

var options = {
  table:'sys_user',
  sys_parm_action:PostActions.insert,
  data:{
    user_name:'ben.knight',
    first_name:'Ben',
    last_name:'Knight',
    ...
  }
}
```

## Bugs and/or Feature Requests

Create an issue [here](https://github.com/benthomasknight/sn-jsonv2/issues).

## Contributing

1. Fork it!
1. Create a feature branch (git checkout -b cool-new-feature)
1. Commit and push
1. Create new Pull Request

---
_Source: https://npm.io/package/sn-jsonv2 · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
