For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
Postman
PricingEnterprise
Contact SalesSign InSign Up for Free
HomeDocs
HomeDocs
      • Overview
        • Overview
        • Write pre-request scripts
        • Write tests
        • Script examples
        • Dynamic variables
          • Overview
          • pm variables methods
          • pm.vault
          • pm.cookies
          • pm.request
          • pm.response
          • pm.sendrequest
          • pm.visualizer
          • pm.test and pm.expect
          • pm.require
          • pm.execution
          • pm.message
          • pm.info
          • pm.mock
          • pm.datasets
          • pm.state
        • Troubleshoot test errors
Postman API Platform

Product

  • Postman Overview
  • Enterprise
  • Spec Hub
  • Flows
  • Agent Mode
  • API Catalog
  • Fern
  • Postman CLI
  • Integrations
  • Workspaces
  • Plans and pricing

API Network

  • App Security
  • Artificial Intelligence
  • Communication
  • Data Analytics
  • Database
  • Developer Productivity
  • DevOps
  • Ecommerce
  • eSignature
  • Financial Services
  • Payments
  • Travel

Resources

  • Postman Docs
  • Academy
  • Community
  • Templates
  • Intergalactic
  • Videos
  • MCP Servers

Legal and Security

  • Legal Terms Hub
  • Terms of Service
  • Postman Product Terms
  • Security
  • Website Terms of Use

Company

  • About
  • Careers and culture
  • Contact us
  • Partner program
  • Customer stories
  • Student programs
  • Press and media
Twitter iconLinkedIn iconGithub iconYouTube iconInstagram iconDiscord icon
Download Postman
Privacy Policy

© 2026 Postman, Inc.

On this page
  • pm.datasets
Tests and scriptsWrite scriptsPostman sandbox reference

Manage and use datasets in scripts

Beta
||View as Markdown|
Was this page helpful?
Previous

Reference requests and examples in local mock servers

Next

Persist state across requests in local mock servers

Built with

The pm.datasets function provides access to datasets from a script or local mock server. You can query datasets using SQL to retrieve data at runtime. This enables your scripts and mock servers to return dynamic, data-driven responses instead of static values. All methods are asynchronous and return Promises, so use await to access their results.

Learn more about testing with datasets.

The pm.datasets function is supported only in Local View in the Postman desktop app.

pm.datasets

The pm.datasets function provides access to datasets from a script or local mock server. You can load a dataset by its ID and then use various methods to manipulate and query the dataset.

pm.datasets(datasetId:String)

Loads a dataset and returns a handle you can use to interact with the dataset.

1const ds = pm.datasets('menu-id');

dataset.executeView(viewId:String, params:Object)

Runs a view that’s already defined in the dataset and returns the results.

1const ds = pm.datasets('menu-id');
2
3const result = await ds.executeView('view-id', { category: 'pizza' });
4
5return {
6 items: result.rows
7};

dataset.executeQuery(sql:String, params:Object)

Runs a custom SQL query against the dataset and returns the results.

1const ds = pm.datasets('menu-id');
2
3const result = await ds.executeQuery(
4 'SELECT * FROM menu WHERE category = ?',
5 ['pizza']
6);
7
8return {
9 items: result.rows
10};

dataset.addView(options:Object)

Creates a reusable SQL view on the dataset.

1const ds = pm.datasets('menu-id');
2
3await ds.addView({
4 name: 'expensive_items',
5 sql: 'SELECT * FROM menu WHERE price > 15'
6});

dataset.removeView(viewId:String)

Removes a view from the dataset.

1const ds = pm.datasets('menu-id');
2
3await ds.removeView('view-id');