This tutorial assumes you have completed Write Your First NQL Query and have a basic understanding of NQL.
Prerequisites
- Node.js 18 or later
- A Narrative I/O account
- An API key with appropriate permissions (see API Keys)
What you’ll learn
- How to install and configure the SDK
- How to execute an NQL query programmatically
- How to work with query results
Install the SDK
1
Initialize your project
Create a new directory and initialize a Node.js project:
2
Install the SDK
Install the Narrative TypeScript SDK:
- npm
- yarn
- bun
3
Configure TypeScript (optional)
If you’re using TypeScript, install the necessary dependencies:
Initialize the SDK
Create a new file calledindex.ts (or index.js if using JavaScript):
Execute your first query
Add the following code to execute an NQL query:- TypeScript
- JavaScript
Work with datasets
You can also use the SDK to manage datasets:Validate a query before execution
Use thecompileNql method to validate and see the transpiled SQL without executing:
Next steps
Now that you’ve executed your first SDK query, explore these resources to learn more:Authentication Guide
Configure API keys and environments
Executing Queries
Advanced query patterns and options
Managing Datasets
Create, update, and manage datasets
SDK Reference
Complete API reference documentation

