Need to validate UPC barcode numbers in your application? This guide covers everything you need to know about UPC validation via API, including UPC-A and UPC-E formats, checksum calculation, and implementation examples in multiple languages.
What is a UPC?
A UPC (Universal Product Code) is a barcode symbology widely used in North America, UK, Australia, and other countries for tracking trade items in stores. UPC is a subset of GTIN (Global Trade Item Number) and is compatible with the EAN system.
A typical UPC-A looks like this: 042100005264
UPC Formats Explained
There are two main UPC formats:
UPC-A
The standard 12-digit format containing a number system digit, manufacturer code, product code, and check digit. Most commonly used on retail products in North America.
UPC-E
A compressed 8-digit format (including check digit) used for small packages. It's a zero-suppressed version of UPC-A where certain zeros are removed.
Using the UPC Validator API
TinyFn provides a simple endpoint to validate UPCs:
GET https://api.tinyfn.io/v1/validate/upc?upc=042100005264
Headers: X-API-Key: your-api-key
{
"valid": true,
"upc": "042100005264",
"format": "UPC-A",
"number_system": "0",
"manufacturer_code": "42100",
"product_code": "00526",
"check_digit": "4",
"ean13_equivalent": "0042100005264"
}
Parameters
| Parameter | Type | Description |
|---|---|---|
upc |
string | UPC to validate (required) |
Code Examples
JavaScript / Node.js
const response = await fetch(
'https://api.tinyfn.io/v1/validate/upc?upc=042100005264',
{ headers: { 'X-API-Key': 'your-api-key' } }
);
const result = await response.json();
console.log(result.valid); // true
console.log(result.format); // "UPC-A"
Python
import requests
response = requests.get(
'https://api.tinyfn.io/v1/validate/upc',
params={'upc': '042100005264'},
headers={'X-API-Key': 'your-api-key'}
)
result = response.json()
print(result['valid']) # True
print(result['format']) # "UPC-A"
cURL
curl "https://api.tinyfn.io/v1/validate/upc?upc=042100005264" \
-H "X-API-Key: your-api-key"
Common Use Cases
- Retail POS: Validate product barcodes at checkout
- Inventory: Verify product codes during stock management
- E-commerce: Validate product listings and imports
- Data Entry: Check manually entered product codes
- Product Database: Ensure data integrity in product catalogs
Best Practices
- Validate check digit: Always verify the UPC checksum
- Support both formats: Handle UPC-A and UPC-E inputs
- EAN compatibility: Store as EAN-13 for international compatibility
- Leading zeros: Preserve leading zeros when storing UPCs
Use via MCP
Your AI agent can call this tool directly via Model Context Protocol — no HTTP code needed. Add TinyFn to Claude Desktop, Cursor, or any MCP client:
{
"mcpServers": {
"tinyfn-validate": {
"url": "https://api.tinyfn.io/mcp/validate/",
"headers": {
"X-API-Key": "your-api-key"
}
}
}
}
See all validation tools available via MCP in our Validation MCP Tools for AI Agents guide.
Try the UPC Validator API
Get your free API key and start validating UPC codes in seconds.
Get Free API Key