Overview
The Labels Cheap API v2 provides comprehensive shipping and tracking services for e-commerce businesses. Our API allows you to:
Track Packages
Real-time tracking information for USPS packages with detailed delivery status.
Generate Barcodes
Create barcodes for shipping labels and inventory management.
PDF Labels
Generate printable shipping labels in PDF format.
Balance Management
Check account balance and usage statistics.
Base URL
https://developers.labelscheap.com/API/v2/
Authentication
All API requests require authentication using Bearer token authentication. Include your API key in the Authorization header.
curl -X POST https://developers.labelscheap.com/API/v2/balance.php \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "X-Requested-With: XMLHttpRequest"
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://developers.labelscheap.com/API/v2/balance.php');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Authorization: Bearer YOUR_API_KEY',
'X-Requested-With: XMLHttpRequest'
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, '{}');
$response = curl_exec($ch);
curl_close($ch);
import requests
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_API_KEY',
'X-Requested-With': 'XMLHttpRequest'
}
response = requests.post(
'https://developers.labelscheap.com/API/v2/balance.php',
headers=headers,
json={}
)
fetch('https://developers.labelscheap.com/API/v2/balance.php', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_API_KEY',
'X-Requested-With': 'XMLHttpRequest'
},
body: JSON.stringify({})
})
.then(response => response.json())
.then(data => console.log(data));
Rate Limits
To ensure fair usage and system stability, the following rate limits apply:
| Endpoint | Rate Limit | Window | Cost |
|---|---|---|---|
| Balance | 60 requests | 60 seconds | Free |
| Track Package | 60 requests | 60 seconds | $0.01 |
| Generate Barcode | 60 requests | 60 seconds | $0.001 |
| PDF Label | 60 requests | 60 seconds | As per vendors price in your profile |
Response Format
All API responses follow a consistent JSON format:
Success Response
{
"STATUS": "success",
"MESSAGE": "Operation completed successfully",
"CODE": "200",
"DATA": {
// Response data here
},
"TIMESTAMP": "2024-01-15 10:30:00"
}
Error Response
{
"STATUS": "error",
"MESSAGE": "Error description",
"CODE": "1001",
"HTTP_STATUS": 401,
"DATA": {},
"TIMESTAMP": "2024-01-15 10:30:00"
}
API Endpoints
Code Examples
Here are examples of how to integrate with our API in different programming languages:
<?php
class LabelsCheapAPI {
private $apiKey;
private $baseUrl = 'https://developers.labelscheap.com/API/v2/';
public function __construct($apiKey) {
$this->apiKey = $apiKey;
}
public function getBalance() {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->baseUrl . 'balance.php');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Authorization: Bearer ' . $this->apiKey,
'X-Requested-With: XMLHttpRequest'
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, '{}');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
public function trackPackage($trackingNumber) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->baseUrl . 'track.php');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Authorization: Bearer ' . $this->apiKey,
'X-Requested-With: XMLHttpRequest'
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
'tracking' => $trackingNumber
]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
}
// Usage
$api = new LabelsCheapAPI('YOUR_API_KEY');
$balance = $api->getBalance();
$tracking = $api->trackPackage('9400176825477902024731');
?>
import requests
import json
class LabelsCheapAPI:
def __init__(self, api_key):
self.api_key = api_key
self.base_url = 'https://developers.labelscheap.com/API/v2/'
self.headers = {
'Content-Type': 'application/json',
'Authorization': f'Bearer {api_key}',
'X-Requested-With': 'XMLHttpRequest'
}
def get_balance(self):
response = requests.post(
f'{self.base_url}balance.php',
headers=self.headers,
json={}
)
return response.json()
def track_package(self, tracking_number):
response = requests.post(
f'{self.base_url}track.php',
headers=self.headers,
json={'tracking': tracking_number}
)
return response.json()
def generate_barcode(self, barcode_data, format='CODE128'):
response = requests.post(
f'{self.base_url}barcode.php',
headers=self.headers,
json={
'barcode': barcode_data,
'format': format
}
)
return response.json()
# Usage
api = LabelsCheapAPI('YOUR_API_KEY')
balance = api.get_balance()
tracking = api.track_package('9400176825477902024731')
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
public class LabelsCheapAPI
{
private readonly string _apiKey;
private readonly string _baseUrl = "https://developers.labelscheap.com/API/v2/";
private readonly HttpClient _httpClient;
public LabelsCheapAPI(string apiKey)
{
_apiKey = apiKey;
_httpClient = new HttpClient();
_httpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {apiKey}");
_httpClient.DefaultRequestHeaders.Add("X-Requested-With", "XMLHttpRequest");
}
public async Task<dynamic> GetBalanceAsync()
{
var content = new StringContent("{}", Encoding.UTF8, "application/json");
var response = await _httpClient.PostAsync($"{_baseUrl}balance.php", content);
var responseContent = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject(responseContent);
}
public async Task<dynamic> TrackPackageAsync(string trackingNumber)
{
var requestData = new { tracking = trackingNumber };
var json = JsonConvert.SerializeObject(requestData);
var content = new StringContent(json, Encoding.UTF8, "application/json");
var response = await _httpClient.PostAsync($"{_baseUrl}track.php", content);
var responseContent = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject(responseContent);
}
}
// Usage
var api = new LabelsCheapAPI("YOUR_API_KEY");
var balance = await api.GetBalanceAsync();
var tracking = await api.TrackPackageAsync("9400176825477902024731");
class LabelsCheapAPI {
constructor(apiKey) {
this.apiKey = apiKey;
this.baseUrl = 'https://developers.labelscheap.com/API/v2/';
this.headers = {
'Content-Type': 'application/json',
'Authorization': `Bearer ${apiKey}`,
'X-Requested-With': 'XMLHttpRequest'
};
}
async getBalance() {
const response = await fetch(`${this.baseUrl}balance.php`, {
method: 'POST',
headers: this.headers,
body: JSON.stringify({})
});
return await response.json();
}
async trackPackage(trackingNumber) {
const response = await fetch(`${this.baseUrl}track.php`, {
method: 'POST',
headers: this.headers,
body: JSON.stringify({
tracking: trackingNumber
})
});
return await response.json();
}
async generateBarcode(barcodeData, format = 'CODE128') {
const response = await fetch(`${this.baseUrl}barcode.php`, {
method: 'POST',
headers: this.headers,
body: JSON.stringify({
barcode: barcodeData,
format: format
})
});
return await response.json();
}
}
// Usage
const api = new LabelsCheapAPI('YOUR_API_KEY');
api.getBalance().then(balance => console.log(balance));
api.trackPackage('9400176825477902024731').then(tracking => console.log(tracking));
Changelog
Version 2.0.0 - January 15, 2024
- Complete API redesign with improved response format
- Enhanced error handling with detailed error codes
- Added comprehensive rate limiting
- Improved authentication system
- Added new endpoints for barcode generation and PDF labels
- Enhanced tracking capabilities with detailed delivery information
Version 1.5.0 - December 1, 2023
- Added service mapping endpoint
- Improved balance endpoint with usage statistics
- Enhanced tracking response format