# @instana/synthetic-api-script

> Command script-cli to run/debug synthetic api script

Latest version **1.1.8** (published 2026-06-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install @instana/synthetic-api-script
pnpm add @instana/synthetic-api-script
yarn add @instana/synthetic-api-script
bun add @instana/synthetic-api-script
```

Provides the command `script-cli`.

## Health

**Score 45/100 (D)** — status: active.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

## Facts

| | |
|---|---|
| Version | 1.1.8 |
| Published | 2026-06-08 |
| First published | 2023-04-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 57 |
| Unpacked size | 24.7 KB |
| Known vulnerabilities | 0 (+17 in 3 direct dependencies) |
| Install scripts | yes |
| GitHub stars | 7 |
| Author | Instana Inc |
| Maintainers | instana_tracers, navaminarendralal, swethalohith, anirudhanp55 |
| Keywords | synthetic |

## Links

- npm: https://www.npmjs.com/package/@instana/synthetic-api-script
- Repository: https://github.com/instana/synthetic-api-script
- Homepage: https://github.com/instana/synthetic-api-script#readme
- Issues: https://github.com/instana/synthetic-api-script/issues
- npm.io page: https://npm.io/package/@instana/synthetic-api-script

## Dependencies (57)

- [q](https://npm.io/package/q.md) ^1.5.1
- [ws](https://npm.io/package/ws.md) ^7.4.3
- [got](https://npm.io/package/got.md) ^11.8.6
- [joi](https://npm.io/package/joi.md) ^17.4.0
- [sip](https://npm.io/package/sip.md) ^0.0.6
- [vm2](https://npm.io/package/vm2.md) ^3.9.17
- [atob](https://npm.io/package/atob.md) ^2.1.2
- [btoa](https://npm.io/package/btoa.md) ^1.2.1
- [uuid](https://npm.io/package/uuid.md) ^14.0.0
- [clone](https://npm.io/package/clone.md) ^0.1.18
- [debug](https://npm.io/package/debug.md) ^2.1.2
- [faker](https://npm.io/package/faker.md) ^5.4.0
- [mssql](https://npm.io/package/mssql.md) ^11.0.1
- [sshpk](https://npm.io/package/sshpk.md) ^1.16.1
- [yargs](https://npm.io/package/yargs.md) ^17.7.2
- [colors](https://npm.io/package/colors.md) ^1.4.0
- [extend](https://npm.io/package/extend.md) ^3.0.2
- [jsprim](https://npm.io/package/jsprim.md) ^1.2.2
- [lodash](https://npm.io/package/lodash.md) ^4.17.21
- [moment](https://npm.io/package/moment.md) ^2.29.4
- [should](https://npm.io/package/should.md) ^13.2.3
- [thrift](https://npm.io/package/thrift.md) ^0.14.2
- [urllib](https://npm.io/package/urllib.md) ^2.43.0
- [xml2js](https://npm.io/package/xml2js.md) ^0.5.0
- [adm-zip](https://npm.io/package/adm-zip.md) ^0.5.10
- [js-yaml](https://npm.io/package/js-yaml.md) ^4.1.1
- [kafkajs](https://npm.io/package/kafkajs.md) ^2.2.4
- [mongodb](https://npm.io/package/mongodb.md) ^6.5.0
- [net-snmp](https://npm.io/package/net-snmp.md) ^3.5.1
- [unzipper](https://npm.io/package/unzipper.md) ^0.10.9
- [basic-ftp](https://npm.io/package/basic-ftp.md) ^4.6.3
- [crypto-js](https://npm.io/package/crypto-js.md) ^4.2.0
- [url-parse](https://npm.io/package/url-parse.md) ^1.5.10
- [validator](https://npm.io/package/validator.md) ^13.7.0
- [babel-core](https://npm.io/package/babel-core.md) ^7.0.0-beta.3
- [underscore](https://npm.io/package/underscore.md) ^1.12.0
- [@babel/core](https://npm.io/package/@babel/core.md) ^7.23.3
- [assert-plus](https://npm.io/package/assert-plus.md) ^1.0.0
- [body-parser](https://npm.io/package/body-parser.md) ^1.19.0
- [prom-client](https://npm.io/package/prom-client.md) ^14.2.0
- [ssl-checker](https://npm.io/package/ssl-checker.md) ^2.0.10
- [tough-cookie](https://npm.io/package/tough-cookie.md) ^4.1.3
- [ldapauth-fork](https://npm.io/package/ldapauth-fork.md) ^5.0.1
- [patch-package](https://npm.io/package/patch-package.md) ^8.0.0
- [telnet-client](https://npm.io/package/telnet-client.md) ^2.2.1
- [text-encoding](https://npm.io/package/text-encoding.md) ^0.7.0
- [swagger-parser](https://npm.io/package/swagger-parser.md) ^10.0.3
- [akamai-edgegrid](https://npm.io/package/akamai-edgegrid.md) ^3.4.5
- [consoleplusplus](https://npm.io/package/consoleplusplus.md) ^1.4.4
- [node-stream-zip](https://npm.io/package/node-stream-zip.md) ^1.13.6
- [@cypress/request](https://npm.io/package/@cypress/request.md) ^3.0.1
- [protocol-buffers](https://npm.io/package/protocol-buffers.md) ^4.2.0
- [ssh2-sftp-client](https://npm.io/package/ssh2-sftp-client.md) ^7.1.0
- [@aws-sdk/client-s3](https://npm.io/package/@aws-sdk/client-s3.md) ^3.992.0
- [@aws-sdk/client-sts](https://npm.io/package/@aws-sdk/client-sts.md) ^3.978.0
- [@aws-sdk/client-cloudwatch](https://npm.io/package/@aws-sdk/client-cloudwatch.md) ^3.1012.0
- [@aws-sdk/client-secrets-manager](https://npm.io/package/@aws-sdk/client-secrets-manager.md) ^3.978.0

## Recent versions

- 1.1.8 (latest) — 2026-06-08
- 1.1.7 — 2026-02-10
- 1.1.6 — 2026-01-12
- 1.1.5 — 2024-08-20
- 1.1.4 — 2024-08-06
- 1.1.3 — 2024-07-10
- 1.1.2 — 2024-06-07
- 1.1.1 — 2024-03-19
- 1.1.0 — 2024-03-05
- 1.0.14 — 2024-01-30
- 1.0.13 — 2024-01-25
- 1.0.12 — 2024-01-24
- 1.0.11 — 2024-01-23
- 1.0.10 — 2024-01-10
- 1.0.9 — 2023-10-13
- … 9 more at https://npm.io/package/@instana/synthetic-api-script/versions

## README

# synthetic-api-script <a href="https://www.npmjs.com/package/@instana/synthetic-api-script"><img alt="npm (scoped)" src="https://img.shields.io/npm/v/@instana/synthetic-api-script?color=0db4b33"></a>

---
Run and debug Instana synthetic api script in local, see [Instana API Script reference](https://www.ibm.com/docs/en/instana-observability/current?topic=beta-using-api-scripts) for script syntax.

## Table of Contents

- [Installation](#installation)
- [Usage](#usage)
- [Using script-cli](#using-script-cli)
  - [Get examples](#get-examples)
  - [Run a single script](#run-a-single-script)
  - [Run bundle script](#run-bundle-script)
  - [Convert a script to string](#convert-a-script-to-string)
  - [Zip and convert bundle scripts to string encoded with base64](#zip-and-convert-bundle-scripts-to-string-encoded-with-base64)
- [Run script with VSCode](#run-script-with-vscode)
  - [Download code](#download-code)
  - [Install required modules](#install-required-modules)
  - [Select a script to run](#select-a-script-to-run)
  - [Specify Credential file](#specify-credential-file)
  - [Run and debug](#run-and-debug)


## Installation
Using npm:
- install the package in global mode 
```
npm install -g @instana/synthetic-api-script
```

- or install the package locally
```
cd test/
npm install @instana/synthetic-api-script
```
Then run script-cli using `npx script-cli` to run script.

Using yarn:
```
yarn add @instana/synthetic-api-script
```

Update to latest version:
```
npm update -g @instana/synthetic-api-script
```

## Usage
```
Usage:
  Run synthetic api script in local

Commands
  script-cli [options] <script-file>

Options
  -d <directory> directory for bundle scripts
  -s convert script to string
  -z <bundle-script-folder> <entry-script> zip the bundle scripts folder and convert to string encoded with base64
  -c secure.json specify credentials in API script
  -h, --help show help
  -v, --version show version
```

## Using script-cli

### Get examples
```
git clone https://github.com/instana/synthetic-api-script.git
cd synthetic-api-script
```

### Run a single script
Syntax
```shell
script-cli <script_name>
```
Example 1, run a single script
```shell
script-cli examples/got-example1.js
```

Example 2, run a single API script with credentials
```shell
script-cli -c creds.json got-credentials-test.js
```
**NOTE:** use `script-cli` if it is installed globally, use `npx script-cli` if it is installed locallly.

### Run bundle script

Specify script folder and entry file.
```shell
script-cli -d <dir> <script-entry-file>
```

Example
```shell
script-cli -d examples/got-bundle-example1 index.js

# specify credentials using -c cred.json
script-cli -c cred.json -d examples/got-bundle-example1 index.js
```

### Convert a script to string

The converted string can be used in HTTPScript test [payload](https://instana.github.io/openapi/#section/Synthetic-Test-Properties:)

```shell
script-cli -s <script-file-path>
```

Example
```shell
script-cli -s examples/got-get.js
```

Result example
```json
{
  "syntheticType":"HTTPScript",
  "script":"var assert = require('assert');\n\n(async function() {\n  var options = {\n    url: 'https://httpbin.org/get',\n    https:{\n      rejectUnauthorized: false\n    }\n  };\n\n  let response = await $got.get(options);\n  assert.equal(response.statusCode, 200, 'Expected a 200 OK response');\n  console.log('Request URL %s, statusCode: %d', response.url, response.statusCode);\n})();\n"
}
```

### Zip and convert bundle scripts to string encoded with base64

The converted string can be used in HTTPScript test [payload](https://instana.github.io/openapi/#section/Synthetic-Test-Properties:).  

```shell
script-cli -z <bundle-script-folder> <entry-script>
```

**Note:** `bundle-script-folder` can not include its parent folder, do not use `examples/got-bundle-example1`, use `got-bundle-example1` instead.


If all test files are inside a folder, such as `got-bundle-example1`, its entry file should be relative path from the folder, it is `got-bundle-example1/index.js`. Its directory tree is as below:

```
got-bundle-example1
├── index.js
└── lib
    ├── request1.js
    └── request2.js

# convert it to base64
cd examples
script-cli -z got-bundle-example1 got-bundle-example1/index.js
```

Result is
``` json
{
  "syntheticType": "HTTPScript",
  "scripts": {
    "scriptFile": "got-bundle-example1/index.js",
    "bundle": "UEsDBBQAAAgAAHKG61YAAAAAAAAAAAAAAAAUAAAAZ290LWJ1bmRsZS1leGFtcGxlMS9QSwMEFAAACAgAQXbrVgqQVDa5AAAAdgEAABwAAABnb3QtYnVuZGxlLWV4YW1wbGUxL2luZGV4Lmpzfc5LCsIwEADQfU6RRSEpSIpdKiLiShC78QJpnNJATLCZWkW8u0mx+EE7q8zkzUc565E2cGrB45Qu+qdugDORGV1mww9L50S92/yvzaMlXPqrVbRqrULtLE9vhIYY5vFgYi47qV8zY/We8pSQRCI2umwRvPCAnNVgjGMTyjrXmEO/It7jDAhtK8eZkSWYAJKwF2tArZ4nj5Gl6GtLYeURfntqHVK4aI+z0davXrDnTy+2xXq13xS7YB9QSwMEFAAACAAAQXbrVgAAAAAAAAAAAAAAABgAAABnb3QtYnVuZGxlLWV4YW1wbGUxL2xpYi9QSwMEFAAACAgAiYTrVlJas+srAQAAJQIAACMAAABnb3QtYnVuZGxlLWV4YW1wbGUxL2xpYi9yZXF1ZXN0MS5qc21SzW7CMAy+9yksBEoqlRR2LNpp2mmHPUNIDBSFpoudFWni3ZeUMgRaTpH9+ftxYnxHDJoIA8MrBPyKbUAprhVRborCj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AQAAIwAAAAAAAAAAAAAApIHHAgAAZ290LWJ1bmRsZS1leGFtcGxlMS9saWIvcmVxdWVzdDIuanNQSwUGAAAAAAUABQB0AQAA1wMAAAAA"
  }
}
```


If all files are not within a folder, change directory to `got-bundle-example1`, its directory tree is as below:
```
├── index.js
└── lib
    ├── request1.js
    └── request2.js

# convert to base64
cd got-bundle-example1
script-cli -z . index.js
```

Result is:
``` json
{
  "syntheticType": "HTTPScript",
  "scripts": {
    "scriptFile": "index.js",
    "bundle": "UEsDBBQAAAgIAEF261YKkFQ2uQAAAHYBAAAIAAAAaW5kZXguanN9zksKwjAQANB9TpFFISlIil0qIuJKELvxAmmc0kBMsJlaRby7SbH4QTurzOTNRznrkTZwasHjlC76p26AM5EZXWbDD0vnRL3b/K/NoyVc+qtVtGqtQu0sT2+Ehhjm8WBiLjupXzNj9Z7ylJBEIja6bBG88ICc1WCMYxPKOteYQ78i3uMMCG0rx5mRJZgAkrAXa0CtniePkaXoa0th5RF+e2odUrhoj7PR1q9esOdPL7bFerXfFLtgH1BLAwQUAAAIAABBdutWAAAAAAAAAAAAAAAABAAAAGxpYi9QSwMEFAAACAgAiYTrVlJas+srAQAAJQIAAA8AAABsaWIvcmVxdWVzdDEuanNtUs1uwjAMvvcpLARKKpUUdizaadpphz1DSAwUhaaLnRVp4t2XlDIEWk6R/fn7cWJ8RwyaCAPDKwT8im1AKa4VUW6KwoyQGNw6AcSBuaemrodhUFvd2qiMP9Ui4XaxM9z6biRB4rUs4acAmO89qz2yzBRlKig+YCdvcBmQ+iSBZQYDZDnvULXdzksxcWX5ZkEVEGuO9OYtNrAgUY2+KrhxqHs/WYfxXKOoRKSd/AdYwctqVYF4P/doGC3oXIDPjz/WcQ1XsroG9kCIYAJa7LjVLtmKhEAmtD0vjWthacY2qSOlfSilpunHbHNCEwOqPjkcfLBNivNcK++6DzmecRXMvrWLuJ6l23MT6OCjs7BFGKdzhAmd+S9lcSmKk7cxWcNz7wPT9BfyM26KX1BLAwQUAAAICABBdutW9lkDkc8AAAA+AQAADwAAAGxpYi9yZXF1ZXN0Mi5qc22QsW7DMAxEd30FhxZSAEEJPMboVGTK0G9QZSYVYIuuSMEpiv57JCdIlo48Ht7xGCixgGfGLPAGGb9LzGj0TdGbXqmwWkoeu2rQXyIz77fbZVlc/JxcoEn3yvNPCnAqKUiktGKQpTMb+FUAI0qVeK4grAy/+CjwciZxZxTTyDUHoAXRiC6mExl9Z7TgPbyyBRYvhd9pwDoP2q4n2QfYPfcr7dbAVYofzT8mC91uZ0EfLjMGwQF8E+Dj+CC29n9KTTSUehVeZsrC9ye1dr26AlBLAQIUAxQAAAgIAEF261YKkFQ2uQAAAHYBAAAIAAAAAAAAAAAAAACkgQAAAABpbmRleC5qc1BLAQIUAxQAAAgAAEF261YAAAAAAAAAAAAAAAAEAAAAAAAAAAAAEADtQd8AAABsaWIvUEsBAhQDFAAACAgAiYTrVlJas+srAQAAJQIAAA8AAAAAAAAAAAAAAKSBAQEAAGxpYi9yZXF1ZXN0MS5qc1BLAQIUAxQAAAgIAEF261b2WQORzwAAAD4BAAAPAAAAAAAAAAAAAACkgVkCAABsaWIvcmVxdWVzdDIuanNQSwUGAAAAAAQABADiAAAAVQMAAAAA"
  }
}
```

# Run script with VSCode

### Download code
```shell
git clone https://github.com/instana/synthetic-api-script.git
```

### Install required modules
```shell
cd synthetic-api-script
npm install
```

### Select a script to run
Edit file `lib/runInVscode.js` and modify variable `scriptPath` to run your script, e.g, run `got-get.js` script, scriptPath is as below:
```
const scriptPath = `${__dirname}/../examples/got-get.js`;
```

### Specify Credential file
Edit file `lib/runInVscode.js` and modify variable `credFile` as below to specify the credential json path.
```
const credFile = ${__dirname}/../examples/creds.json;
```
### Run and debug
Go to Run and Debug view, then click button `Run Synthetic Script` to run and debug the selected script.  
You can also set breakpoints and debug your script step by step.

---
_Source: https://npm.io/package/@instana/synthetic-api-script · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
