Integrate accurate tariff calculations into your applications with our comprehensive API.
Getting Started
Our API provides programmatic access to:
- Real-time tariff rate calculations
- HTS code search and validation
- Batch processing for multiple products
- Country comparison analysis
- Export functionality for reports
Authentication
Currently, our API is open and does not require authentication. Rate limiting is applied to prevent abuse.
Rate Limits: 100 requests per minute per IP address
API Endpoints
POST /api/calculate
Calculate tariff impact for a single product
Request Body:
{
"productValue": 1000,
"productType": "electronics",
"country": "china",
"quantity": 100,
"htsCode": "8471.30.01" // optional
}Response:
{
"originalPrice": 1000,
"tariffRate": 0.25,
"tariffAmount": 250,
"totalCost": 1250,
"consumerPrice": 1462.5,
"priceIncrease": 462.5,
"percentIncrease": 46.25,
"effectiveDate": "2019-05-10",
"notes": ["Section 301 tariff applied"]
}POST /api/batch
Process multiple products in a single request
Request Body:
{
"products": [
{
"name": "Laptop",
"value": 800,
"type": "electronics",
"country": "china",
"quantity": 50
},
{
"name": "T-Shirt",
"value": 15,
"type": "clothing",
"country": "vietnam",
"quantity": 1000
}
]
}Response:
{
"results": [...],
"summary": {
"totalProducts": 2,
"totalOriginalValue": 15800,
"totalTariffs": 2012.5,
"averageTariffRate": 0.127
}
}GET /api/hts-search
Search for HTS codes by keyword
Query Parameters:
q- Search query (required)limit- Maximum results (default: 10)
Example:
GET /api/hts-search?q=laptop&limit=5
Response:
{
"results": [
{
"code": "8471.30.01",
"description": "Portable automatic data processing machines",
"duty_rate": "Free"
}
]
}POST /api/compare
Compare tariff impact across multiple countries
Request Body:
{
"productValue": 1000,
"productType": "electronics",
"countries": ["china", "mexico", "vietnam"]
}POST /api/export
Export calculation results in various formats
Request Body:
{
"format": "csv", // or "pdf", "excel"
"data": { /* calculation results */ }
}Error Handling
All errors follow a consistent format:
{
"error": "Error message",
"code": "ERROR_CODE",
"details": {} // Additional context
}Common Error Codes:
INVALID_REQUEST- Missing or invalid parametersRATE_LIMITED- Too many requestsINVALID_HTS_CODE- HTS code format errorSERVER_ERROR- Internal server error
Code Examples
JavaScript/Node.js
const response = await fetch('https://tariffimpactcalculator.com/api/calculate', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
productValue: 1000,
productType: 'electronics',
country: 'china'
})
});
const result = await response.json();
console.log(`Tariff amount: $${result.tariffAmount}`);Python
import requests
response = requests.post(
'https://tariffimpactcalculator.com/api/calculate',
json={
'productValue': 1000,
'productType': 'electronics',
'country': 'china'
}
)
result = response.json()
print(f"Tariff amount: {result['tariffAmount']{'}'}")Support
Need help with the API? We're here to assist:
- Email: api@tariffimpactcalculator.com
- Response time: Within 24 hours
- Include your use case and any error messages