Imports API
Retrieve and manage imported items from the VSCU system for customs compliance.
Overview
The Imports API provides four endpoints for complete import management:
| Endpoint | Method | Purpose |
|---|---|---|
/api/v1/imports/select-items | POST | Retrieve import items from customs/VSCU |
/api/v1/imports/items | GET | Get existing items for mapping |
/api/v1/imports/process | POST | Process import (map/create + update status + stock in) |
/api/v1/imports/update-items | POST | Update import status only (manual workflow) |
Recommended: Use the /process endpoint for complete import handling. It automatically handles item creation/mapping, KRA status updates, and stock movements in a single operation.
Select Import Items
Retrieve imported items from VSCU based on the last request date.
POST /api/v1/imports/select-itemsHeaders
Authorization: Bearer YOUR_API_KEY
X-Branch-ID: YOUR_BRANCH_ID
Content-Type: application/jsonRequest Body
{
"last_request_date": "20190524000000"
}Field Descriptions
| Field | Type | Required | Description |
|---|---|---|---|
last_request_date | string | Yes | Last request date in YYYYMMDDHHmmss format |
Response
Status: 200 OK
{
"status": "success",
"data": {
"items": [
{
"task_code": "2231943",
"declaration_date": "20191217",
"item_sequence": 1,
"declaration_number": "C123456",
"hs_code": "1231531231",
"item_name": "Imported Product",
"import_item_status_code": "1",
"origin_nation_code": "CN",
"export_nation_code": "CN",
"package": 10.5,
"package_unit_code": "CT",
"quantity": 100,
"quantity_unit_code": "U",
"gross_weight": 150.5,
"net_weight": 145.0,
"supplier_name": "ABC Imports Ltd",
"agent_name": "XYZ Customs Agent",
"invoice_foreign_currency_amount": 5000.00,
"invoice_foreign_currency": "USD",
"invoice_foreign_currency_exchange_rate": 1.25
}
],
"total_items": 1,
"result_code": "000",
"result_message": "Success",
"result_date": "20250107143000"
},
"meta": {
"timestamp": "2025-01-07T14:30:00Z",
"request_id": "req_123abc"
}
}Response Item Fields
| Field | Type | Description |
|---|---|---|
task_code | string | Customs task code |
declaration_date | string | Declaration date (YYYYMMDD) |
item_sequence | integer | Item sequence number |
declaration_number | string | Customs declaration number |
hs_code | string | Harmonized System code |
item_name | string | Item description |
import_item_status_code | string | Import status code |
origin_nation_code | string | Country of origin code |
export_nation_code | string | Country of export code |
package | number | Package quantity |
package_unit_code | string | Package unit code |
quantity | number | Item quantity |
quantity_unit_code | string | Quantity unit code |
gross_weight | number | Gross weight |
net_weight | number | Net weight |
supplier_name | string | Supplier name |
agent_name | string | Customs agent name |
invoice_foreign_currency_amount | number | Invoice amount in foreign currency |
invoice_foreign_currency | string | Foreign currency code |
invoice_foreign_currency_exchange_rate | number | Exchange rate |
Update Import Item Status
Update the status of an imported item in the VSCU system.
POST /api/v1/imports/update-itemsHeaders
Authorization: Bearer YOUR_API_KEY
X-Branch-ID: YOUR_BRANCH_ID
Content-Type: application/jsonRequest Body
{
"task_code": "2231943",
"declaration_date": "20191217",
"item_sequence": 1,
"hs_code": "1231531231",
"item_class_code": "5022110801",
"item_code": "KE1NTXU0000001",
"import_item_status_code": "1",
"remark": "Item cleared for release",
"modifier_name": "Admin",
"modifier_id": "Admin"
}Field Descriptions
| Field | Type | Required | Description |
|---|---|---|---|
task_code | string | Yes | Customs task code (max 50 chars) |
declaration_date | string | Yes | Declaration date in YYYYMMDD format (8 chars) |
item_sequence | integer | Yes | Item sequence number |
hs_code | string | Yes | Harmonized System code (max 17 chars) |
item_class_code | string | Yes | Item classification code (max 10 chars) |
item_code | string | Yes | Item code (max 20 chars) |
import_item_status_code | string | Yes | Import item status code (max 5 chars) |
remark | string | No | Optional remark (max 400 chars) |
modifier_name | string | Yes | Name of person updating (max 60 chars) |
modifier_id | string | Yes | ID of person updating (max 20 chars) |
Import Item Status Codes
Refer to the VSCU documentation section 4.18 for valid import item status codes.
Response
Status: 200 OK
{
"status": "success",
"message": "Import item status updated successfully",
"data": {
"result_code": "000",
"result_message": "Successful",
"result_date": "20250107143023"
},
"meta": {
"timestamp": "2025-01-07T14:30:23Z",
"request_id": "req_456def"
}
}Error Responses
422 Unprocessable Entity
Validation error:
{
"status": "error",
"message": "Invalid request data",
"errors": {
"task_code": [
"The task code field is required."
],
"declaration_date": [
"The declaration date must be 8 characters."
]
}
}400 Bad Request
VSCU error:
{
"status": "error",
"message": "VSCU processing failed",
"error": "Item not found in VSCU system"
}500 Internal Server Error
Server error:
{
"status": "error",
"message": "An error occurred while retrieving import items",
"error": "Internal server error"
}Complete Code Examples
PHP
// 1. Select import items
$data = [
'last_request_date' => date('YmdHis', strtotime('-30 days')),
];
$response = $client->post('/api/v1/imports/select-items', [
'json' => $data,
'headers' => [
'Authorization' => 'Bearer ' . $apiKey,
'X-Branch-ID' => '01',
],
]);
$items = $response->json()['data']['items'];
// 2. Get items for mapping
$itemsResponse = $client->get('/api/v1/imports/items', [
'headers' => [
'Authorization' => 'Bearer ' . $apiKey,
'X-Branch-ID' => '01',
],
]);
$existingItems = $itemsResponse->json()['data']['items'];
// 3. Process import - Map to existing item
$processMapData = [
'action' => 'map',
'existing_item_code' => 'CN3NTUN0000001',
'task_code' => '2231943',
'declaration_date' => '20191217',
'declaration_number' => 'C123456',
'item_sequence' => 1,
'hs_code' => '1231531231',
'import_item_name' => 'Imported Product',
'origin_nation_code' => 'CN',
'quantity' => 100,
'quantity_unit_code' => 'U',
'supplier_name' => 'ABC Imports Ltd',
'invoice_amount' => 5000.00,
'invoice_currency' => 'USD',
'exchange_rate' => 120.5,
];
$processResponse = $client->post('/api/v1/imports/process', [
'json' => $processMapData,
'headers' => [
'Authorization' => 'Bearer ' . $apiKey,
'X-Branch-ID' => '01',
],
]);
// 4. Process import - Create new item
$processCreateData = [
'action' => 'create',
'task_code' => '2231943',
'declaration_date' => '20191217',
'declaration_number' => 'C123456',
'item_sequence' => 1,
'hs_code' => '1231531231',
'import_item_name' => 'Imported Product',
'origin_nation_code' => 'CN',
'quantity' => 100,
'quantity_unit_code' => 'U',
'supplier_name' => 'ABC Imports Ltd',
'invoice_amount' => 5000.00,
'invoice_currency' => 'USD',
'exchange_rate' => 120.5,
'new_item' => [
'item_code' => 'CN3NTUN0000001',
'item_class_code' => '5022110801',
'item_name' => 'Imported Product',
'pkg_unit_code' => 'NT',
'qty_unit_code' => 'U',
'tax_type' => 'A',
'default_price' => 5000.00,
],
];
$processResponse = $client->post('/api/v1/imports/process', [
'json' => $processCreateData,
'headers' => [
'Authorization' => 'Bearer ' . $apiKey,
'X-Branch-ID' => '01',
],
]);
// 5. Update import item status
$updateData = [
'task_code' => '2231943',
'declaration_date' => '20191217',
'item_sequence' => 1,
'hs_code' => '1231531231',
'item_class_code' => '5022110801',
'item_code' => 'KE1NTXU0000001',
'import_item_status_code' => '1',
'remark' => 'Item cleared',
'modifier_name' => 'John Doe',
'modifier_id' => 'admin123',
];
$response = $client->post('/api/v1/imports/update-items', [
'json' => $updateData,
'headers' => [
'Authorization' => 'Bearer ' . $apiKey,
'X-Branch-ID' => '01',
],
]);JavaScript
// 1. Select import items
const lastRequestDate = moment().subtract(30, 'days').format('YYYYMMDDHHmmss');
const selectResponse = await axios.post('/api/v1/imports/select-items',
{ last_request_date: lastRequestDate },
{
headers: {
'Authorization': `Bearer ${apiKey}`,
'X-Branch-ID': '01'
}
}
);
const items = selectResponse.data.data.items;
// 2. Get items for mapping
const itemsResponse = await axios.get('/api/v1/imports/items', {
headers: {
'Authorization': `Bearer ${apiKey}`,
'X-Branch-ID': '01'
}
});
const existingItems = itemsResponse.data.data.items;
// 3. Process import - Map to existing item
const processMapData = {
action: 'map',
existing_item_code: 'CN3NTUN0000001',
task_code: '2231943',
declaration_date: '20191217',
declaration_number: 'C123456',
item_sequence: 1,
hs_code: '1231531231',
import_item_name: 'Imported Product',
origin_nation_code: 'CN',
quantity: 100,
quantity_unit_code: 'U',
supplier_name: 'ABC Imports Ltd',
invoice_amount: 5000.00,
invoice_currency: 'USD',
exchange_rate: 120.5
};
const processMapResponse = await axios.post('/api/v1/imports/process',
processMapData,
{
headers: {
'Authorization': `Bearer ${apiKey}`,
'X-Branch-ID': '01'
}
}
);
// 4. Process import - Create new item
const processCreateData = {
action: 'create',
task_code: '2231943',
declaration_date: '20191217',
declaration_number: 'C123456',
item_sequence: 1,
hs_code: '1231531231',
import_item_name: 'Imported Product',
origin_nation_code: 'CN',
quantity: 100,
quantity_unit_code: 'U',
supplier_name: 'ABC Imports Ltd',
invoice_amount: 5000.00,
invoice_currency: 'USD',
exchange_rate: 120.5,
new_item: {
item_code: 'CN3NTUN0000001',
item_class_code: '5022110801',
item_name: 'Imported Product',
pkg_unit_code: 'NT',
qty_unit_code: 'U',
tax_type: 'A',
default_price: 5000.00
}
};
const processCreateResponse = await axios.post('/api/v1/imports/process',
processCreateData,
{
headers: {
'Authorization': `Bearer ${apiKey}`,
'X-Branch-ID': '01'
}
}
);
// 5. Update import item status
const updateData = {
task_code: '2231943',
declaration_date: '20191217',
item_sequence: 1,
hs_code: '1231531231',
item_class_code: '5022110801',
item_code: 'KE1NTXU0000001',
import_item_status_code: '1',
remark: 'Item cleared',
modifier_name: 'John Doe',
modifier_id: 'admin123'
};
const updateResponse = await axios.post('/api/v1/imports/update-items',
updateData,
{
headers: {
'Authorization': `Bearer ${apiKey}`,
'X-Branch-ID': '01'
}
}
);cURL
# 1. Select import items
curl -X POST https://c-ushuru.com/api/v1/imports/select-items \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "X-Branch-ID: 01" \
-H "Content-Type: application/json" \
-d '{
"last_request_date": "20190524000000"
}'
# 2. Get items for mapping
curl -X GET https://c-ushuru.com/api/v1/imports/items \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "X-Branch-ID: 01"
# 3. Process import - Map to existing item
curl -X POST https://c-ushuru.com/api/v1/imports/process \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "X-Branch-ID: 01" \
-H "Content-Type: application/json" \
-d '{
"action": "map",
"existing_item_code": "CN3NTUN0000001",
"task_code": "2231943",
"declaration_date": "20191217",
"declaration_number": "C123456",
"item_sequence": 1,
"hs_code": "1231531231",
"import_item_name": "Imported Product",
"origin_nation_code": "CN",
"quantity": 100,
"quantity_unit_code": "U",
"supplier_name": "ABC Imports Ltd",
"invoice_amount": 5000.00,
"invoice_currency": "USD",
"exchange_rate": 120.5
}'
# 4. Process import - Create new item
curl -X POST https://c-ushuru.com/api/v1/imports/process \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "X-Branch-ID: 01" \
-H "Content-Type: application/json" \
-d '{
"action": "create",
"task_code": "2231943",
"declaration_date": "20191217",
"declaration_number": "C123456",
"item_sequence": 1,
"hs_code": "1231531231",
"import_item_name": "Imported Product",
"origin_nation_code": "CN",
"quantity": 100,
"quantity_unit_code": "U",
"supplier_name": "ABC Imports Ltd",
"invoice_amount": 5000.00,
"invoice_currency": "USD",
"exchange_rate": 120.5,
"new_item": {
"item_code": "CN3NTUN0000001",
"item_class_code": "5022110801",
"item_name": "Imported Product",
"pkg_unit_code": "NT",
"qty_unit_code": "U",
"tax_type": "A",
"default_price": 5000.00
}
}'
# 5. Update import item status
curl -X POST https://c-ushuru.com/api/v1/imports/update-items \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "X-Branch-ID: 01" \
-H "Content-Type: application/json" \
-d '{
"task_code": "2231943",
"declaration_date": "20191217",
"item_sequence": 1,
"hs_code": "1231531231",
"item_class_code": "5022110801",
"item_code": "KE1NTXU0000001",
"import_item_status_code": "1",
"remark": "Item cleared for release",
"modifier_name": "Admin",
"modifier_id": "Admin"
}'Best Practices
- Use Process Endpoint - Use
POST /imports/processfor complete import handling instead of manually coordinating multiple endpoints - Regular Synchronization - Retrieve import items regularly to stay up-to-date with customs data
- Store Last Request Date - Save the last successful request date for incremental updates
- Item Code Format - When creating items, follow KRA format:
CC(country) +T(type) +PP(pkg unit) +QQ(qty unit) +NNNNNNN(sequence) - Tax Calculation - Remember that import invoice amounts are tax-inclusive
- Error Handling - Implement proper error handling for VSCU connection issues
- Branch Context - Always specify the correct branch ID in headers
- Audit Trail - The system automatically records modifier information for compliance
- Item Matching - Use
GET /imports/itemsto retrieve existing items before deciding to map or create - Exchange Rates - Always provide accurate exchange rates for foreign currency imports
Use Cases
Complete Import Processing Workflow
- Retrieve Import Items: Call
POST /imports/select-itemsto get imports from customs - Get Existing Items (optional): Call
GET /imports/itemsto get items for mapping - Process Import: Call
POST /imports/processto either:- Map to existing item (
action: "map") - Create new item (
action: "create")
- Map to existing item (
- Automatic Actions: The process endpoint automatically:
- Registers new items with KRA (if creating)
- Updates import status in KRA (status code ‘3’)
- Creates stock movement transaction
- Updates local inventory quantities
Manual Status Update Workflow
If you need to update import status separately:
- Retrieve Pending Items: Call
POST /imports/select-itemsto get new imported items - Process Clearance: Review items and obtain customs clearance
- Update Status: Call
POST /imports/update-itemsto update item status in VSCU - Inventory Integration: Manage inventory separately
Periodic Synchronization
// Sync and process imports every hour
setInterval(async () => {
try {
// 1. Get last sync date
const lastSync = await getLastSyncDate();
// 2. Retrieve new imports
const selectResponse = await axios.post('/api/v1/imports/select-items', {
last_request_date: lastSync
}, {
headers: {
'Authorization': `Bearer ${apiKey}`,
'X-Branch-ID': branchId
}
});
const imports = selectResponse.data.data.items;
if (imports.length > 0) {
// 3. Get existing items for mapping
const itemsResponse = await axios.get('/api/v1/imports/items', {
headers: {
'Authorization': `Bearer ${apiKey}`,
'X-Branch-ID': branchId
}
});
const existingItems = itemsResponse.data.data.items;
// 4. Process each import
for (const importItem of imports) {
// Try to find matching item by name or HS code
const matchingItem = existingItems.find(item =>
item.item_name === importItem.item_name ||
item.hs_code === importItem.hs_code
);
if (matchingItem) {
// Map to existing item
await axios.post('/api/v1/imports/process', {
action: 'map',
existing_item_code: matchingItem.item_code,
...importItem
}, {
headers: {
'Authorization': `Bearer ${apiKey}`,
'X-Branch-ID': branchId
}
});
} else {
// Create new item
await axios.post('/api/v1/imports/process', {
action: 'create',
new_item: {
item_code: generateItemCode(importItem),
item_class_code: '5022110801',
item_name: importItem.item_name,
pkg_unit_code: importItem.package_unit_code,
qty_unit_code: importItem.quantity_unit_code,
tax_type: 'A',
default_price: calculatePrice(importItem)
},
...importItem
}, {
headers: {
'Authorization': `Bearer ${apiKey}`,
'X-Branch-ID': branchId
}
});
}
}
// 5. Save sync date
await saveLastSyncDate(selectResponse.data.data.result_date);
}
} catch (error) {
console.error('Import sync failed:', error);
}
}, 3600000); // 1 hourProcess Import
Process an import by either mapping to an existing item or creating a new item, updating the KRA status, and performing a stock in operation.
POST /api/v1/imports/processHeaders
Authorization: Bearer YOUR_API_KEY
X-Branch-ID: YOUR_BRANCH_ID
Content-Type: application/jsonRequest Body
{
"action": "create",
"task_code": "2231943",
"declaration_date": "20191217",
"declaration_number": "C123456",
"item_sequence": 1,
"hs_code": "1231531231",
"import_item_name": "Imported Product",
"origin_nation_code": "CN",
"quantity": 100,
"quantity_unit_code": "U",
"supplier_name": "ABC Imports Ltd",
"invoice_amount": 5000.00,
"invoice_currency": "USD",
"exchange_rate": 120.5,
"new_item": {
"item_code": "CN3NTUN0000001",
"item_class_code": "5022110801",
"item_name": "Imported Product",
"pkg_unit_code": "NT",
"qty_unit_code": "U",
"tax_type": "A",
"default_price": 5000.00
}
}Field Descriptions
| Field | Type | Required | Description |
|---|---|---|---|
action | string | Yes | Action type: “map” (use existing item) or “create” (create new item) |
task_code | string | Yes | Customs task code |
declaration_date | string | Yes | Declaration date (YYYYMMDD format) |
declaration_number | string | Yes | Customs declaration number |
item_sequence | integer | Yes | Item sequence number |
hs_code | string | Yes | Harmonized System code |
import_item_name | string | Yes | Item name from customs |
origin_nation_code | string | Yes | Country of origin code (2 chars) |
quantity | number | Yes | Item quantity (min: 0.01) |
quantity_unit_code | string | Yes | Quantity unit code |
supplier_name | string | No | Supplier/vendor name |
invoice_amount | number | Yes | Invoice amount in foreign currency (min: 0) |
invoice_currency | string | No | Foreign currency code (e.g., “USD”) |
exchange_rate | number | No | Exchange rate to KES (defaults to 1) |
existing_item_code | string | Conditional | Required if action is “map”. Item code to map to |
new_item | object | Conditional | Required if action is “create”. New item details |
new_item.item_code | string | Conditional | Item code (14 chars, format: CC+T+PP+QQ+NNNNNNN) |
new_item.item_class_code | string | Conditional | Item classification code (10 chars) |
new_item.item_name | string | Conditional | Item name |
new_item.pkg_unit_code | string | No | Package unit code (defaults to “NT”) |
new_item.qty_unit_code | string | No | Quantity unit code |
new_item.tax_type | string | No | Tax type code (A=16%, B/C/D/E=0%, defaults to “A”) |
new_item.default_price | number | No | Default unit price (calculated if not provided) |
Action Types
| Action | Description |
|---|---|
map | Map the import to an existing item in your inventory. Requires existing_item_code |
create | Create a new item and register it with KRA. Requires new_item object |
Import Status Codes
After processing, the import status is updated to:
- 3: Registered (linked to inventory item)
Response
Status: 200 OK
{
"status": "success",
"message": "Import processed successfully",
"data": {
"item_code": "CN3NTUN0000001",
"item_name": "Imported Product",
"qty_added": 100,
"previous_qty": 50,
"new_qty": 150,
"kra_status_updated": true,
"kra_stock_synced": true
},
"meta": {
"timestamp": "2025-01-07T14:30:00Z",
"request_id": "req_123abc"
}
}Response Fields
| Field | Type | Description |
|---|---|---|
item_code | string | Item code that was mapped or created |
item_name | string | Item name |
qty_added | number | Quantity added to inventory |
previous_qty | number | Quantity before this operation |
new_qty | number | Current quantity after stock in |
kra_status_updated | boolean | Whether KRA import status was successfully updated |
kra_stock_synced | boolean | Whether stock movement was successfully synced to KRA |
sync_error | string | Error message if KRA stock sync failed (only present if kra_stock_synced is false) |
Processing Flow
When you process an import, the following happens:
-
Item Handling:
- If
action=map: Lookup existing item byexisting_item_code - If
action=create: Register new item with KRA and save to local database
- If
-
KRA Status Update:
- Update import status in KRA to “3” (Registered)
- Link the import to the item code
-
Stock In:
- Calculate tax amounts (invoice is tax-inclusive)
- Create stock movement (sarTyCd=‘01’ for Import)
- Sync stock transaction to KRA
- Update local item quantity
Tax Calculation
Import prices are tax-inclusive. The system automatically calculates:
Taxable Amount = Total Amount ÷ (1 + Tax Rate ÷ 100)
Tax Amount = Total Amount - Taxable AmountTax Type Rates:
- A: 16% VAT
- B: 0% (Exempt)
- C: 0% (Zero-rated)
- D: 0% (Special)
- E: 0% (Duty-free)
Get Items for Mapping
Retrieve all active items for a branch to use when mapping imports to existing inventory.
GET /api/v1/imports/itemsHeaders
Authorization: Bearer YOUR_API_KEY
X-Branch-ID: YOUR_BRANCH_IDResponse
Status: 200 OK
{
"status": "success",
"data": {
"items": [
{
"id": 123,
"item_code": "CN3NTUN0000001",
"item_name": "Imported Product",
"item_class_code": "5022110801",
"current_qty": 50,
"default_price": 1500.00,
"tax_type_code": "A",
"pkg_unit_code": "NT",
"qty_unit_code": "U",
"origin_nation_code": "CN"
}
],
"total": 1
},
"meta": {
"timestamp": "2025-01-07T14:30:00Z",
"request_id": "req_456def"
}
}Response Item Fields
| Field | Type | Description |
|---|---|---|
id | integer | Internal item ID |
item_code | string | KRA item code |
item_name | string | Item name |
item_class_code | string | Item classification code |
current_qty | number | Current stock quantity |
default_price | number | Default unit price |
tax_type_code | string | Tax type (A=16%, B/C/D/E=0%) |
pkg_unit_code | string | Package unit code |
qty_unit_code | string | Quantity unit code |
origin_nation_code | string | Country of origin |
Related Endpoints
- Items API - Manage item master data
- Stock API - View stock movements and inventory
- Codes API - Get import item status codes
- Branches API - Manage branch information
VSCU Integration
These endpoints integrate with the VSCU (Virtual SDC Unit) system:
- Select Items Endpoint:
/imports/selectImportItems - Update Items Endpoint:
/imports/updateImportItems
All requests are forwarded to VSCU with proper authentication and branch context. Responses include VSCU result codes and messages for troubleshooting.
Notes
- Import items are managed at the branch level; ensure the correct branch ID is specified
- The
last_request_dateshould be stored and used for incremental synchronization - Import item status codes must match VSCU specifications (see section 4.18)
- All dates use YYYYMMDD format, and datetimes use YYYYMMDDHHmmss format
- Exchange rates and amounts are stored for audit and reporting purposes