How to start categorizing texts/websites in 2 minutes


Step 1: Purchase Plan and obtain API key

After purchasing the plan and logging in, you can use dashboard for categorizations. However, if you need to categorize a large number of texts/websites then we advise you to use our API endpoints. You will see your API key in the dashboard, like this:

Your API key: $2y$10$CbkLX8Ba5n5nD0wSEiuYJ.l3N6K.Ivp4E39eB

Step 2: Prepare list of texts or URLs/domains you want to classify

Next step is to prepare a list of texts or URLs/domains that you want to classify. You can store them in a file named texts.csv with each text/URL in a new line, like this:

universal baby stroller organizer
forever necklace
happyflute 100% biodegradable flushable diaper liners
victoria long sleeve mesh blouse brown
under sea bralette skirt
cotton rug rust dot various sizes
oversize futuristic ppe mask visor face shield sunglasses
drive steerable knee walker
women’s litewave flow lace ii sneakers
soft cat collar tag cat dog collars
austin loft design modern solid wood slab dining table
eliana classic wall mirror
olivia modular system wood storage shelves


Step 3: Run the script for classification

First, you need to decide on which Tier you want to use. For example, if you want to use our most advanced classifier with 5590 distinct categories, then you should use the following API endpoint:
"https://www.productcategorization.com/api/gpt/gpt_category4.php".

For more information on on available API endpoints please see this page.

After storing the texts/URLs, you should create a python script with the following content (replace the API endpoint with the one which is most suitable for your use case):

import requests
import json

# your API key (available in dashboard, after login)
api_key = 'b4dcde2ce5fb2d0b887b5eb6'

# set this to correct API endpoint, for more information on available API endpoints please see https://www.productcategorization.com/product_categorization_api.php
url_api = "https://www.productcategorization.com/api/ecommerce/ecommerce_category6_get.php?"

# name of file where categorizations of URLs will be stored
f_write = open('results.csv','w')

with open('texts.csv','r') as f:
    texts = f.readlines()
    for text in texts:
       text = text.replace('\n','')
       url=url_api+'query='+text+'&api_key='+api_key

       response = requests.request("POST", url)
       print(response.text)
       data = json.loads(response.text)
       try:
          category = data['classification'][0]['category']
       except:
          category = 'url could not be loaded'
       print(category)
       f_write.write(text+','+category+'\n')
       f_write.flush()

f_write.close()
and run it from command line with (assuming you stored it under name classification.py):

python3 classification.py
The results of classifications will then be written out in file results.csv, in the format URL, Category. Example output:


universal baby stroller organizer,Baby Stroller Accessories
forever necklace,Necklaces
happyflute 100% biodegradable flushable diaper liners,Diaper Liners
victoria long sleeve mesh blouse brown,Shirts & Tops
under sea bralette skirt,Skirts
cotton rug rust dot various sizes,Bath Mats & Rugs
oversize futuristic ppe mask visor face shield sunglasses,Sunglasses
drive steerable knee walker,Supports & Braces
women’s litewave flow lace ii sneakers,Shoes
soft cat collar tag cat dog collars,Pet ID Tags
austin loft design modern solid wood slab dining table,Table Tops
eliana classic wall mirror,Mirrors
olivia modular system wood storage shelves,Industrial Shelving


These results were obtained by calling the API Endpoint for GPT Tier 3 classification (using gpt_category3.php in code above).

If you need other types of classifications, you need to replace the corresponding line in python code above, using the definitions from our API documentation..

If you need help on this, please send us an email and we will be happy to help you.