@sharpapi/sharpapi-node-product-categories 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +282 -0
- package/package.json +40 -0
- package/src/SharpApiProductCategoriesService.js +32 -0
- package/src/index.js +6 -0
package/README.md
ADDED
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+

|
|
2
|
+
|
|
3
|
+
# Product Categorization API for Node.js
|
|
4
|
+
|
|
5
|
+
## 🏪 Automatically categorize products with AI — powered by SharpAPI.
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/@sharpapi/sharpapi-node-product-categories)
|
|
8
|
+
[](https://github.com/sharpapi/sharpapi-node-client/blob/master/LICENSE.md)
|
|
9
|
+
|
|
10
|
+
**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.
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## 📋 Table of Contents
|
|
15
|
+
|
|
16
|
+
1. [Requirements](#requirements)
|
|
17
|
+
2. [Installation](#installation)
|
|
18
|
+
3. [Usage](#usage)
|
|
19
|
+
4. [API Documentation](#api-documentation)
|
|
20
|
+
5. [Examples](#examples)
|
|
21
|
+
6. [License](#license)
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## Requirements
|
|
26
|
+
|
|
27
|
+
- Node.js >= 16.x
|
|
28
|
+
- npm or yarn
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## Installation
|
|
33
|
+
|
|
34
|
+
### Step 1. Install the package via npm:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
npm install @sharpapi/sharpapi-node-product-categories
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Step 2. Get your API key
|
|
41
|
+
|
|
42
|
+
Visit [SharpAPI.com](https://sharpapi.com/) to get your API key.
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## Usage
|
|
47
|
+
|
|
48
|
+
```javascript
|
|
49
|
+
const { SharpApiProductCategoriesService } = require('@sharpapi/sharpapi-node-product-categories');
|
|
50
|
+
|
|
51
|
+
const apiKey = process.env.SHARP_API_KEY; // Store your API key in environment variables
|
|
52
|
+
const service = new SharpApiProductCategoriesService(apiKey);
|
|
53
|
+
|
|
54
|
+
const productName = 'Wireless Bluetooth Headphones with Noise Cancellation';
|
|
55
|
+
|
|
56
|
+
async function categorizeProduct() {
|
|
57
|
+
try {
|
|
58
|
+
// Submit categorization job
|
|
59
|
+
const statusUrl = await service.categorizeProduct(productName);
|
|
60
|
+
console.log('Job submitted. Status URL:', statusUrl);
|
|
61
|
+
|
|
62
|
+
// Fetch results (polls automatically until complete)
|
|
63
|
+
const result = await service.fetchResults(statusUrl);
|
|
64
|
+
const categories = result.getResultJson();
|
|
65
|
+
|
|
66
|
+
console.log('Suggested categories:', categories);
|
|
67
|
+
} catch (error) {
|
|
68
|
+
console.error('Error:', error.message);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
categorizeProduct();
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## API Documentation
|
|
78
|
+
|
|
79
|
+
### Methods
|
|
80
|
+
|
|
81
|
+
#### `categorizeProduct(productName: string, maxCategories?: number): Promise<string>`
|
|
82
|
+
|
|
83
|
+
Assigns categories to a product based on its name and description.
|
|
84
|
+
|
|
85
|
+
**Parameters:**
|
|
86
|
+
- `productName` (string, required): The product name or description to categorize
|
|
87
|
+
- `maxCategories` (number, optional): Maximum number of categories to return (default: 5)
|
|
88
|
+
|
|
89
|
+
**Returns:**
|
|
90
|
+
- Promise<string>: Status URL for polling the job result
|
|
91
|
+
|
|
92
|
+
**Example:**
|
|
93
|
+
```javascript
|
|
94
|
+
const statusUrl = await service.categorizeProduct(
|
|
95
|
+
'Organic Green Tea 100 Bags Premium Quality',
|
|
96
|
+
3
|
|
97
|
+
);
|
|
98
|
+
const result = await service.fetchResults(statusUrl);
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Response Format
|
|
102
|
+
|
|
103
|
+
The API returns categories with confidence scores:
|
|
104
|
+
|
|
105
|
+
```json
|
|
106
|
+
{
|
|
107
|
+
"categories": [
|
|
108
|
+
{
|
|
109
|
+
"name": "Electronics > Audio > Headphones",
|
|
110
|
+
"weight": 10,
|
|
111
|
+
"subcategories": ["Wireless Headphones", "Noise-Canceling Headphones", "Bluetooth Audio"]
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
"name": "Electronics > Consumer Electronics",
|
|
115
|
+
"weight": 8,
|
|
116
|
+
"subcategories": ["Audio Devices", "Wireless Technology"]
|
|
117
|
+
}
|
|
118
|
+
]
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
## Examples
|
|
125
|
+
|
|
126
|
+
### Basic Product Categorization
|
|
127
|
+
|
|
128
|
+
```javascript
|
|
129
|
+
const { SharpApiProductCategoriesService } = require('@sharpapi/sharpapi-node-product-categories');
|
|
130
|
+
|
|
131
|
+
const service = new SharpApiProductCategoriesService(process.env.SHARP_API_KEY);
|
|
132
|
+
|
|
133
|
+
const product = 'Professional DSLR Camera with 24MP Sensor';
|
|
134
|
+
|
|
135
|
+
service.categorizeProduct(product)
|
|
136
|
+
.then(statusUrl => service.fetchResults(statusUrl))
|
|
137
|
+
.then(result => {
|
|
138
|
+
const categories = result.getResultJson();
|
|
139
|
+
console.log('📂 Product Categories:');
|
|
140
|
+
categories.forEach((cat, index) => {
|
|
141
|
+
console.log(`${index + 1}. ${cat.name} (weight: ${cat.weight})`);
|
|
142
|
+
if (cat.subcategories) {
|
|
143
|
+
console.log(` Subcategories: ${cat.subcategories.join(', ')}`);
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
})
|
|
147
|
+
.catch(error => console.error('Categorization failed:', error));
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### Batch Product Categorization
|
|
151
|
+
|
|
152
|
+
```javascript
|
|
153
|
+
const service = new SharpApiProductCategoriesService(process.env.SHARP_API_KEY);
|
|
154
|
+
|
|
155
|
+
const products = [
|
|
156
|
+
'Organic Cotton T-Shirt Men\'s Size L',
|
|
157
|
+
'Stainless Steel Water Bottle 750ml',
|
|
158
|
+
'Yoga Mat with Carrying Strap',
|
|
159
|
+
'Wireless Gaming Mouse RGB LED'
|
|
160
|
+
];
|
|
161
|
+
|
|
162
|
+
const categorized = await Promise.all(
|
|
163
|
+
products.map(async (product) => {
|
|
164
|
+
const statusUrl = await service.categorizeProduct(product, 3);
|
|
165
|
+
const result = await service.fetchResults(statusUrl);
|
|
166
|
+
const categories = result.getResultJson();
|
|
167
|
+
|
|
168
|
+
return {
|
|
169
|
+
product,
|
|
170
|
+
primary_category: categories[0]?.name,
|
|
171
|
+
all_categories: categories.map(c => c.name)
|
|
172
|
+
};
|
|
173
|
+
})
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
console.log('Categorized products:', categorized);
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
### E-commerce Integration
|
|
180
|
+
|
|
181
|
+
```javascript
|
|
182
|
+
const service = new SharpApiProductCategoriesService(process.env.SHARP_API_KEY);
|
|
183
|
+
|
|
184
|
+
async function processNewProduct(productData) {
|
|
185
|
+
const productDescription = `${productData.name} ${productData.description}`;
|
|
186
|
+
|
|
187
|
+
const statusUrl = await service.categorizeProduct(productDescription);
|
|
188
|
+
const result = await service.fetchResults(statusUrl);
|
|
189
|
+
const categories = result.getResultJson();
|
|
190
|
+
|
|
191
|
+
// Get primary category (highest weight)
|
|
192
|
+
const primaryCategory = categories.sort((a, b) => b.weight - a.weight)[0];
|
|
193
|
+
|
|
194
|
+
return {
|
|
195
|
+
...productData,
|
|
196
|
+
category: primaryCategory.name,
|
|
197
|
+
subcategories: primaryCategory.subcategories,
|
|
198
|
+
all_categories: categories.map(c => c.name),
|
|
199
|
+
categorization_confidence: primaryCategory.weight
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const newProduct = {
|
|
204
|
+
id: 12345,
|
|
205
|
+
name: 'Smart Fitness Tracker Watch',
|
|
206
|
+
description: 'Heart rate monitor, GPS, waterproof'
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
const enrichedProduct = await processNewProduct(newProduct);
|
|
210
|
+
console.log('Product with categories:', enrichedProduct);
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
---
|
|
214
|
+
|
|
215
|
+
## Use Cases
|
|
216
|
+
|
|
217
|
+
- **E-commerce Platforms**: Automatically categorize new product listings
|
|
218
|
+
- **Inventory Management**: Organize products into logical categories
|
|
219
|
+
- **Search Optimization**: Improve product discoverability with accurate categories
|
|
220
|
+
- **Product Feeds**: Generate properly categorized product feeds for marketplaces
|
|
221
|
+
- **Data Migration**: Recategorize products during platform migrations
|
|
222
|
+
- **Marketplace Integration**: Map products to marketplace-specific categories
|
|
223
|
+
- **Product Recommendations**: Enable category-based product recommendations
|
|
224
|
+
|
|
225
|
+
---
|
|
226
|
+
|
|
227
|
+
## Category Structure
|
|
228
|
+
|
|
229
|
+
The system recognizes hierarchical categories:
|
|
230
|
+
|
|
231
|
+
**Top-Level Categories:**
|
|
232
|
+
- Electronics
|
|
233
|
+
- Clothing & Fashion
|
|
234
|
+
- Home & Garden
|
|
235
|
+
- Sports & Outdoors
|
|
236
|
+
- Health & Beauty
|
|
237
|
+
- Books & Media
|
|
238
|
+
- Food & Beverages
|
|
239
|
+
- Toys & Games
|
|
240
|
+
- And many more...
|
|
241
|
+
|
|
242
|
+
**Subcategories:**
|
|
243
|
+
- Each top-level category has multiple subcategories
|
|
244
|
+
- Subcategories can have further sub-levels
|
|
245
|
+
- Weight scores indicate confidence (0-10)
|
|
246
|
+
|
|
247
|
+
---
|
|
248
|
+
|
|
249
|
+
## API Endpoint
|
|
250
|
+
|
|
251
|
+
**POST** `/ecommerce/product_categories`
|
|
252
|
+
|
|
253
|
+
For detailed API specifications, refer to:
|
|
254
|
+
- [Postman Documentation](https://documenter.getpostman.com/view/31106842/2sBXVeGsVq)
|
|
255
|
+
- [Product Page](https://sharpapi.com/en/catalog/ai/e-commerce/product-categorization)
|
|
256
|
+
|
|
257
|
+
---
|
|
258
|
+
|
|
259
|
+
## Related Packages
|
|
260
|
+
|
|
261
|
+
- [@sharpapi/sharpapi-node-product-intro](https://www.npmjs.com/package/@sharpapi/sharpapi-node-product-intro) - Product introductions
|
|
262
|
+
- [@sharpapi/sharpapi-node-product-description](https://www.npmjs.com/package/@sharpapi/sharpapi-node-product-description) - Product descriptions
|
|
263
|
+
- [@sharpapi/sharpapi-node-generate-keywords](https://www.npmjs.com/package/@sharpapi/sharpapi-node-generate-keywords) - Keyword generation
|
|
264
|
+
- [@sharpapi/sharpapi-node-client](https://www.npmjs.com/package/@sharpapi/sharpapi-node-client) - Full SharpAPI SDK
|
|
265
|
+
|
|
266
|
+
---
|
|
267
|
+
|
|
268
|
+
## License
|
|
269
|
+
|
|
270
|
+
This project is licensed under the MIT License. See the [LICENSE.md](LICENSE.md) file for details.
|
|
271
|
+
|
|
272
|
+
---
|
|
273
|
+
|
|
274
|
+
## Support
|
|
275
|
+
|
|
276
|
+
- **Documentation**: [SharpAPI.com Documentation](https://sharpapi.com/documentation)
|
|
277
|
+
- **Issues**: [GitHub Issues](https://github.com/sharpapi/sharpapi-node-client/issues)
|
|
278
|
+
- **Email**: contact@sharpapi.com
|
|
279
|
+
|
|
280
|
+
---
|
|
281
|
+
|
|
282
|
+
**Powered by [SharpAPI](https://sharpapi.com/) - AI-Powered API Workflow Automation**
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sharpapi/sharpapi-node-product-categories",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "SharpAPI.com Node.js SDK for generating product categories",
|
|
5
|
+
"main": "src/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "jest"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [
|
|
10
|
+
"sharpapi",
|
|
11
|
+
"ai-powered",
|
|
12
|
+
"ai capabilities",
|
|
13
|
+
"api",
|
|
14
|
+
"ai api",
|
|
15
|
+
"api integration",
|
|
16
|
+
"artificial intelligence",
|
|
17
|
+
"natural language processing",
|
|
18
|
+
"restful api",
|
|
19
|
+
"nodejs",
|
|
20
|
+
"software development",
|
|
21
|
+
"e-commerce",
|
|
22
|
+
"product categories",
|
|
23
|
+
"categorization"
|
|
24
|
+
],
|
|
25
|
+
"author": "Dawid Makowski <contact@sharpapi.com>",
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@sharpapi/sharpapi-node-core": "file:../sharpapi-node-core"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"jest": "^29.7.0"
|
|
32
|
+
},
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public"
|
|
35
|
+
},
|
|
36
|
+
"repository": {
|
|
37
|
+
"type": "git",
|
|
38
|
+
"url": "https://github.com/sharpapi/sharpapi-node-product-categories.git"
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const { SharpApiCoreService, SharpApiJobTypeEnum } = require('@sharpapi/sharpapi-node-core');
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Service for generating product categories using SharpAPI.com
|
|
5
|
+
*/
|
|
6
|
+
class SharpApiProductCategoriesService extends SharpApiCoreService {
|
|
7
|
+
/**
|
|
8
|
+
* Generates a list of suitable categories for the product with relevance weights as a float value (1.0-10.0)
|
|
9
|
+
* where 10 equals 100%, the highest relevance score. Provide the product name and its parameters
|
|
10
|
+
* to get the best category matches possible. Comes in handy with populating
|
|
11
|
+
* product catalogue data and bulk products' processing.
|
|
12
|
+
*
|
|
13
|
+
* @param {string} productName
|
|
14
|
+
* @param {string|null} language
|
|
15
|
+
* @param {number|null} maxQuantity
|
|
16
|
+
* @param {string|null} voiceTone
|
|
17
|
+
* @param {string|null} context
|
|
18
|
+
* @returns {Promise<string>} - The status URL.
|
|
19
|
+
*/
|
|
20
|
+
async productCategories(productName, language = null, maxQuantity = null, voiceTone = null, context = null) {
|
|
21
|
+
const data = { content: productName };
|
|
22
|
+
if (language) data.language = language;
|
|
23
|
+
if (maxQuantity) data.max_quantity = maxQuantity;
|
|
24
|
+
if (voiceTone) data.voice_tone = voiceTone;
|
|
25
|
+
if (context) data.context = context;
|
|
26
|
+
|
|
27
|
+
const response = await this.makeRequest('POST', SharpApiJobTypeEnum.ECOMMERCE_PRODUCT_CATEGORIES.url, data);
|
|
28
|
+
return this.parseStatusUrl(response);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
module.exports = { SharpApiProductCategoriesService };
|