Barnes & Noble lists books, eBooks, audiobooks, vinyl, toys, and more, each with prices, formats, badges, and a sales rank. The Barnes & Noble API from SerpApi turns a Barnes & Noble search into structured data, so you can compare editions, track prices, or build a reading-list tool without parsing a web page yourself.

In this tutorial, we'll look at what the API returns, try it in the Playground, and call it with a plain GET request, cURL, Python, and JavaScript. Then we'll cover sorting, filtering, pagination, and saving results to CSV. We'll use the search the book title dune throughout.

What can you scrape from Barnes & Noble?

A search returns its products in organic_results. Each result can include:

  • Product basics: title, link, thumbnail, and description
  • Identifiers: ean (the ISBN-13 for books) and work_id, which is shared across formats of the same work
  • Contributors: a contributors array with each person's name, role (for example Author, Illustrator, or Narrated by), and link
  • Format details: format (such as Paperback, Hardcover, eBook, Audiobook, or Vinyl LP), edition, series, and series_number
  • Pricing: price and old_price, both in USD
  • Promotions and stock: badges (for example Bestseller or Signed Edition) and out_of_stock
  • Popularity and dates: sales_rank, where a lower number means a better-selling product, and publication_time_iso8601

Not every field appears on every result. old_price and badges show up on discounted or promoted products, and edition and series show up when they apply.

Beyond the products, the response also includes:

  • search_information: total_results, query_displayed, spelling_fix, and organic_results_state
  • filters: the filter options Barnes & Noble offers for your search, each with a parameter name you can send back in your next request
  • serpapi_pagination: current, next_page_token, and next

Getting started with SerpApi

The fastest way to try the API is the Barnes & Noble Playground. Type dune as the search query and run it to see the JSON before writing any code.

To call the API from your own code, you need an API key. Sign up for a SerpApi account, then sign in to your dashboard to find your key. Treat it like a password and keep it out of your code and repositories.

Store it in an environment variable so the examples below can read it:

export SERPAPI_API_KEY="YOUR_SERPAPI_API_KEY"

Replace YOUR_SERPAPI_API_KEY with your own key. In a terminal, this lasts only for the current session.

How to scrape Barnes & Noble search results

The Barnes & Noble API uses engine=barnes_and_noble. These are the parameters we'll use most:

  • engine (required): Set to barnes_and_noble
  • q (required): Your search text (A title, author, keyword, or ISBN all work.)
  • api_key (required): Your SerpApi private API key
  • sort_by (optional): Defaults to Top Matches, other values include bestsellers, newest, oldest, price_low_to_high, price_high_to_low, and title
  • product_format (optional): Filters by format, such as Hardcover or Paperback
  • next_page_token (optional): Leave it out for page 1. Use the token from the previous response to get the next page.

GET request

The basic request is a GET to https://serpapi.com/search.json. JSON is the default output.

Here is an example call:

https://serpapi.com/search.json?engine=barnes_and_noble&q=dune&api_key=YOUR_SERPAPI_API_KEY

This is the shape of the response with values left out. Your real response will have actual data.

{
  "search_metadata": {
    "id": "...",
    "status": "Success"
  },
  "search_information": {
    "total_results": 0,
    "query_displayed": "...",
    "organic_results_state": "..."
  },
  "organic_results": [
    {
      "position": 1,
      "title": "...",
      "link": "...",
      "ean": "...",
      "work_id": "...",
      "contributors": [
        {
          "name": "...",
          "role": "Author",
          "link": "..."
        }
      ],
      "format": "...",
      "publication_time_iso8601": "...",
      "price": 0.0,
      "sales_rank": 0,
      "thumbnail": "...",
      "description": "..."
    }
  ],
  "filters": [
    {
      "title": "...",
      "parameter": "...",
      "options": [
        {
          "text": "...",
          "value": "...",
          "count": 0,
          "serpapi_link": "..."
        }
      ]
    }
  ],
  "serpapi_pagination": {
    "current": 1,
    "next_page_token": "...",
    "next": "..."
  }
}

A few things to keep in mind:

  • search_metadata.status moves from Processing to Success or Error. If a search fails, search_metadata.error holds the message. See status and error codes for more.
  • publication_time_iso8601 is midnight Eastern Time on the publication date, expressed in UTC. A book published on a given day can look like the evening before if you only read the UTC date.
  • If Barnes & Noble corrected a misspelled query, search_information.spelling_fix holds the query it searched instead, and organic_results_state explains what happened. For example, it can say "Showing results for fixed spelling" or "Fully empty".

Markdown output

If you want results that are easy to read, or you're sending them to an LLM, add output=md:

https://serpapi.com/search?engine=barnes_and_noble&q=dune&output=md&api_key=YOUR_SERPAPI_API_KEY

Markdown trims some data to stay compact, such as tracking fields, redirect URLs, nested details, and filter sections. When you need exact field access, like reading contributors[].name or the pagination token in code, use JSON. All of the code below uses JSON.

cURL

This cURL command is another way to request thisendpoint and parameters. --get with --data-urlencode takes care of URL encoding:

curl --get "https://serpapi.com/search.json" \
  --data-urlencode "engine=barnes_and_noble" \
  --data-urlencode "q=dune" \
  --data-urlencode "api_key=$SERPAPI_API_KEY"

Results should look like:

The cURL call results for the Barnes and Noble API

Python

SerpApi also has an official Python library. See the Python integration page for more. Install it with:

pip install serpapi

Create a file named main.py, and add the code below:

import os
import serpapi

client = serpapi.Client(api_key=os.environ["SERPAPI_API_KEY"], timeout=60)

results = client.search({
    "engine": "barnes_and_noble",
    "q": "dune",
})

if "error" in results:
    raise SystemExit("The search failed. Check your API key and parameters.")

products = results.get("organic_results", [])
if not products:
    print("No products found.")

for product in products:
    authors = ", ".join(
        c["name"] for c in product.get("contributors", []) if c.get("role") == "Author"
    )
    price = product.get("price")
    print(f'{product["position"]}. {product["title"]} ({product.get("format", "n/a")})')
    print(f'   Author: {authors or "Unknown"} | Price: {f"${price:.2f}" if price is not None else "n/a"}')
    print(f'   {product["link"]}')

Run it with:

python main.py

A few notes on the code:

  • os.environ["SERPAPI_API_KEY"] raises an error if the variable isn't set, so you'll know right away if the key is missing.
  • A request can succeed over HTTP and still return an error field in the body, so the code checks for it before reading results.
  • It prints only a few fields per product. The response has more, so print or save whatever your project needs.

Results should look like:

The B&N Python Results

For production code, you may want to catch the library's documented exceptions, including serpapi.HTTPError, serpapi.HTTPConnectionError, and serpapi.TimeoutError.

JavaScript

SerpApi also has an official JavaScript library. Install it with:

npm install serpapi

Create a file named main.js and add in this code below:

async function main() {
  const { getJson } = await import("serpapi");

  const apiKey = process.env.SERPAPI_API_KEY;
  if (!apiKey) {
    console.error("Set the SERPAPI_API_KEY environment variable first.");
    process.exit(1);
  }

  try {
    const results = await getJson({
      engine: "barnes_and_noble",
      api_key: apiKey,
      q: "dune",
    });

    if (results.error) {
      console.error("The search failed. Check your API key and parameters.");
      process.exit(1);
    }

    const products = results.organic_results ?? [];
    if (products.length === 0) {
      console.log("No products found.");
      return;
    }

    for (const product of products) {
      const authors =
        (product.contributors ?? [])
          .filter((c) => c.role === "Author")
          .map((c) => c.name)
          .join(", ") || "Unknown";
      const price =
        product.price != null ? `$${product.price.toFixed(2)}` : "n/a";
      console.log(`${product.position}. ${product.title} (${product.format ?? "n/a"})`);
      console.log(`   Author: ${authors} | Price: ${price}`);
      console.log(`   ${product.link}`);
    }
  } catch (error) {
    console.error(`Request failed: ${error.message}`);
    process.exit(1);
  }
}

main();

Run it with:

node main.js

The results should look like:

The B&N JavaScript Results

Other languages and no-code tools

SerpApi has libraries for other languages too, including Ruby, Go, PHP, Java, Rust, and .NET. Check the integrations page for the full list.

For no-code tools, SerpApi has an app for Make and a verified node for n8n. Check each announcement for which APIs its native modules cover.

How to sort results

By default, results come back as Top Matches. Use sort_by to change the order:

  • bestsellers
  • newest
  • oldest
  • price_low_to_high
  • price_high_to_low
  • title

This request returns the best-selling dune results first:

https://serpapi.com/search.json?engine=barnes_and_noble&q=dune&sort_by=bestsellers&api_key=YOUR_SERPAPI_API_KEY

In Python, reuse the client and add the parameter:

results = client.search({
    "engine": "barnes_and_noble",
    "q": "dune",
    "sort_by": "bestsellers",
})

Each product also has a sales_rank, so you can see the ranking for yourself. For more on sorting, see the Barnes & Noble sorting documentation.

How to filter results

The filters array in the response tells you what you can filter by for your search. Each entry has a title, the request parameter name, and a list of options, and each option has a text, a value, a count, and a ready-made serpapi_link.

You can list them in Python:

results = client.search({
    "engine": "barnes_and_noble",
    "q": "dune",
})

for group in results.get("filters", []):
    print(group["title"], f'(parameter: {group["parameter"]})')
    for option in group.get("options", []):
        print(f'   {option["text"]} ({option["count"]})')

The available request filters include:

  • availability: in_stock or pre_order.
  • department, subject, product_format, age, price, language, and color: the values come from the filters in the response.
  • rating: a minimum average rating, from 1 to 5.

To pass more than one value to a filter, separate them with ||. This request searches dune, sorted by bestsellers, and keeps only hardcovers and paperbacks. The || is URL-encoded as %7C%7C:

https://serpapi.com/search.json?engine=barnes_and_noble&q=dune&sort_by=bestsellers&product_format=Hardcover%7C%7CPaperback&api_key=YOUR_SERPAPI_API_KEY

In Python, write the value with || and the library handles the encoding:

results = client.search({
    "engine": "barnes_and_noble",
    "q": "dune",
    "sort_by": "bestsellers",
    "product_format": "Hardcover||Paperback",
})

Filter values come from the response, so copy them from filters instead of guessing. Filtering a search is also a good way to narrow down results by price, format, or rating before you read them in code. For more detail, see the Barnes & Noble filtering documentation.

How to paginate

The API returns up to 24 results per page. It uses a token instead of a page number. Leave next_page_token out for page 1. The response then gives you the token for the next page at serpapi_pagination.next_page_token, and you send it back with the same parameters as the original search.

https://serpapi.com/search.json?engine=barnes_and_noble&q=dune&next_page_token=YOUR_NEXT_PAGE_TOKEN&api_key=YOUR_SERPAPI_API_KEY

In Python, reuse the client and the parameters, and add the token on each turn:

params = {
    "engine": "barnes_and_noble",
    "q": "dune",
}

for _ in range(3):
    page = client.search(params)

    if "error" in page:
        raise SystemExit("The search failed. Check your API key and parameters.")

    for product in page.get("organic_results", []):
        print(product["title"])

    token = page.get("serpapi_pagination", {}).get("next_page_token")
    if not token:
        break

    params["next_page_token"] = token

This fetches up to three pages. A few important points to consider:

  • The token expires 15 minutes after the original search.
  • Expired tokens still work up to page 5, but more slowly.
  • For pages beyond 5 after the token expires, run the search again from page 1 with no_cache set to true.

The JavaScript library says built-in pagination isn't supported, so in JavaScript you'd do the same by hand: await getJson for each page and pass the token from the previous response. See the Barnes & Noble pagination documentation for more.

How to save results to CSV

Products are repeated records with the same fields, so they fit nicely into CSV rows. This script uses Python's standard library and writes UTF-8. It flattens contributors into one cell, written as Name (Role) and joined with ; :

import csv
import os
import serpapi

client = serpapi.Client(api_key=os.environ["SERPAPI_API_KEY"], timeout=60)

results = client.search({
    "engine": "barnes_and_noble",
    "q": "dune",
    "sort_by": "bestsellers",
})

if "error" in results:
    raise SystemExit("The search failed. Check your API key and parameters.")

fields = ["position", "title", "contributors", "format", "price", "ean", "link"]

with open("products.csv", "w", newline="", encoding="utf-8") as file:
    writer = csv.DictWriter(file, fieldnames=fields)
    writer.writeheader()

    for product in results.get("organic_results", []):
        writer.writerow({
            "position": product.get("position"),
            "title": product.get("title"),
            "contributors": "; ".join(
                f'{c["name"]} ({c.get("role", "n/a")})'
                for c in product.get("contributors", [])
            ),
            "format": product.get("format"),
            "price": product.get("price"),
            "ean": product.get("ean"),
            "link": product.get("link"),
        })

print("Saved products.csv")

Save ean as text. Spreadsheet programs can turn a long ISBN into a number and drop leading zeros or switch to scientific notation, so format that column as text when you open the file.

Conclusion

The Barnes & Noble API gives you product search results with prices, formats, contributors, and sales rank as structured data. You've seen how to call it with GET, cURL, Python, and JavaScript, and how to sort, filter with the filters the response returns, and page through results with next_page_token.

For the full parameter list and response details, see the Barnes & Noble API documentation. You can also read the release notes and try your own searches in the Playground.

If you're working with book data, these are separate SerpApi APIs, each with its own parameters and response:

Here are other relevant tutorials for above:

How to Scrape Google Books Results
The Google Books API from SerpApi returns search results as structured data, so you can work with titles, authors, publication dates, preview links, and matching snippets in your code.
How to scrape book results from the Google Play Store
Search for books, check top lists, and fetch book home pages on the Google Play Store using SerpApi, with results in simple JSON format.