npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@sharpapi/sharpapi-node-product-categories

v1.0.1

Published

SharpAPI.com Node.js SDK for generating product categories

Readme

SharpAPI GitHub cover

Product Categorization API for Node.js

🏪 Automatically categorize products with AI — powered by SharpAPI.

npm version License

SharpAPI Product Categorization uses advanced AI to automatically assign accurate categories and subcategories to products based on their names and descriptions. Perfect for e-commerce, inventory management, and product organization.


📋 Table of Contents

  1. Requirements
  2. Installation
  3. Usage
  4. API Documentation
  5. Examples
  6. License

Requirements

  • Node.js >= 16.x
  • npm or yarn

Installation

Step 1. Install the package via npm:

npm install @sharpapi/sharpapi-node-product-categories

Step 2. Get your API key

Visit SharpAPI.com to get your API key.


Usage

const { SharpApiProductCategoriesService } = require('@sharpapi/sharpapi-node-product-categories');

const apiKey = process.env.SHARP_API_KEY; // Store your API key in environment variables
const service = new SharpApiProductCategoriesService(apiKey);

const productName = 'Wireless Bluetooth Headphones with Noise Cancellation';

async function categorizeProduct() {
  try {
    // Submit categorization job
    const statusUrl = await service.categorizeProduct(productName);
    console.log('Job submitted. Status URL:', statusUrl);

    // Fetch results (polls automatically until complete)
    const result = await service.fetchResults(statusUrl);
    const categories = result.getResultJson();

    console.log('Suggested categories:', categories);
  } catch (error) {
    console.error('Error:', error.message);
  }
}

categorizeProduct();

API Documentation

Methods

categorizeProduct(productName: string, maxCategories?: number): Promise<string>

Assigns categories to a product based on its name and description.

Parameters:

  • productName (string, required): The product name or description to categorize
  • maxCategories (number, optional): Maximum number of categories to return (default: 5)

Returns:

  • Promise: Status URL for polling the job result

Example:

const statusUrl = await service.categorizeProduct(
  'Organic Green Tea 100 Bags Premium Quality',
  3
);
const result = await service.fetchResults(statusUrl);

Response Format

The API returns categories with confidence scores:

{
  "categories": [
    {
      "name": "Electronics > Audio > Headphones",
      "weight": 10,
      "subcategories": ["Wireless Headphones", "Noise-Canceling Headphones", "Bluetooth Audio"]
    },
    {
      "name": "Electronics > Consumer Electronics",
      "weight": 8,
      "subcategories": ["Audio Devices", "Wireless Technology"]
    }
  ]
}

Examples

Basic Product Categorization

const { SharpApiProductCategoriesService } = require('@sharpapi/sharpapi-node-product-categories');

const service = new SharpApiProductCategoriesService(process.env.SHARP_API_KEY);

const product = 'Professional DSLR Camera with 24MP Sensor';

service.categorizeProduct(product)
  .then(statusUrl => service.fetchResults(statusUrl))
  .then(result => {
    const categories = result.getResultJson();
    console.log('📂 Product Categories:');
    categories.forEach((cat, index) => {
      console.log(`${index + 1}. ${cat.name} (weight: ${cat.weight})`);
      if (cat.subcategories) {
        console.log(`   Subcategories: ${cat.subcategories.join(', ')}`);
      }
    });
  })
  .catch(error => console.error('Categorization failed:', error));

Batch Product Categorization

const service = new SharpApiProductCategoriesService(process.env.SHARP_API_KEY);

const products = [
  'Organic Cotton T-Shirt Men\'s Size L',
  'Stainless Steel Water Bottle 750ml',
  'Yoga Mat with Carrying Strap',
  'Wireless Gaming Mouse RGB LED'
];

const categorized = await Promise.all(
  products.map(async (product) => {
    const statusUrl = await service.categorizeProduct(product, 3);
    const result = await service.fetchResults(statusUrl);
    const categories = result.getResultJson();

    return {
      product,
      primary_category: categories[0]?.name,
      all_categories: categories.map(c => c.name)
    };
  })
);

console.log('Categorized products:', categorized);

E-commerce Integration

const service = new SharpApiProductCategoriesService(process.env.SHARP_API_KEY);

async function processNewProduct(productData) {
  const productDescription = `${productData.name} ${productData.description}`;

  const statusUrl = await service.categorizeProduct(productDescription);
  const result = await service.fetchResults(statusUrl);
  const categories = result.getResultJson();

  // Get primary category (highest weight)
  const primaryCategory = categories.sort((a, b) => b.weight - a.weight)[0];

  return {
    ...productData,
    category: primaryCategory.name,
    subcategories: primaryCategory.subcategories,
    all_categories: categories.map(c => c.name),
    categorization_confidence: primaryCategory.weight
  };
}

const newProduct = {
  id: 12345,
  name: 'Smart Fitness Tracker Watch',
  description: 'Heart rate monitor, GPS, waterproof'
};

const enrichedProduct = await processNewProduct(newProduct);
console.log('Product with categories:', enrichedProduct);

Use Cases

  • E-commerce Platforms: Automatically categorize new product listings
  • Inventory Management: Organize products into logical categories
  • Search Optimization: Improve product discoverability with accurate categories
  • Product Feeds: Generate properly categorized product feeds for marketplaces
  • Data Migration: Recategorize products during platform migrations
  • Marketplace Integration: Map products to marketplace-specific categories
  • Product Recommendations: Enable category-based product recommendations

Category Structure

The system recognizes hierarchical categories:

Top-Level Categories:

  • Electronics
  • Clothing & Fashion
  • Home & Garden
  • Sports & Outdoors
  • Health & Beauty
  • Books & Media
  • Food & Beverages
  • Toys & Games
  • And many more...

Subcategories:

  • Each top-level category has multiple subcategories
  • Subcategories can have further sub-levels
  • Weight scores indicate confidence (0-10)

API Endpoint

POST /ecommerce/product_categories

For detailed API specifications, refer to:


Related Packages


License

This project is licensed under the MIT License. See the LICENSE.md file for details.


Support


Powered by SharpAPI - AI-Powered API Workflow Automation