Skip to Content
C-Ushuru v1.0 is now available
API ReferenceImports API

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:

EndpointMethodPurpose
/api/v1/imports/select-itemsPOSTRetrieve import items from customs/VSCU
/api/v1/imports/itemsGETGet existing items for mapping
/api/v1/imports/processPOSTProcess import (map/create + update status + stock in)
/api/v1/imports/update-itemsPOSTUpdate 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-items

Headers

Authorization: Bearer YOUR_API_KEY X-Branch-ID: YOUR_BRANCH_ID Content-Type: application/json

Request Body

{ "last_request_date": "20190524000000" }

Field Descriptions

FieldTypeRequiredDescription
last_request_datestringYesLast 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

FieldTypeDescription
task_codestringCustoms task code
declaration_datestringDeclaration date (YYYYMMDD)
item_sequenceintegerItem sequence number
declaration_numberstringCustoms declaration number
hs_codestringHarmonized System code
item_namestringItem description
import_item_status_codestringImport status code
origin_nation_codestringCountry of origin code
export_nation_codestringCountry of export code
packagenumberPackage quantity
package_unit_codestringPackage unit code
quantitynumberItem quantity
quantity_unit_codestringQuantity unit code
gross_weightnumberGross weight
net_weightnumberNet weight
supplier_namestringSupplier name
agent_namestringCustoms agent name
invoice_foreign_currency_amountnumberInvoice amount in foreign currency
invoice_foreign_currencystringForeign currency code
invoice_foreign_currency_exchange_ratenumberExchange rate

Update Import Item Status

Update the status of an imported item in the VSCU system.

POST /api/v1/imports/update-items

Headers

Authorization: Bearer YOUR_API_KEY X-Branch-ID: YOUR_BRANCH_ID Content-Type: application/json

Request 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

FieldTypeRequiredDescription
task_codestringYesCustoms task code (max 50 chars)
declaration_datestringYesDeclaration date in YYYYMMDD format (8 chars)
item_sequenceintegerYesItem sequence number
hs_codestringYesHarmonized System code (max 17 chars)
item_class_codestringYesItem classification code (max 10 chars)
item_codestringYesItem code (max 20 chars)
import_item_status_codestringYesImport item status code (max 5 chars)
remarkstringNoOptional remark (max 400 chars)
modifier_namestringYesName of person updating (max 60 chars)
modifier_idstringYesID 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

  1. Use Process Endpoint - Use POST /imports/process for complete import handling instead of manually coordinating multiple endpoints
  2. Regular Synchronization - Retrieve import items regularly to stay up-to-date with customs data
  3. Store Last Request Date - Save the last successful request date for incremental updates
  4. Item Code Format - When creating items, follow KRA format: CC (country) + T (type) + PP (pkg unit) + QQ (qty unit) + NNNNNNN (sequence)
  5. Tax Calculation - Remember that import invoice amounts are tax-inclusive
  6. Error Handling - Implement proper error handling for VSCU connection issues
  7. Branch Context - Always specify the correct branch ID in headers
  8. Audit Trail - The system automatically records modifier information for compliance
  9. Item Matching - Use GET /imports/items to retrieve existing items before deciding to map or create
  10. Exchange Rates - Always provide accurate exchange rates for foreign currency imports

Use Cases

Complete Import Processing Workflow

  1. Retrieve Import Items: Call POST /imports/select-items to get imports from customs
  2. Get Existing Items (optional): Call GET /imports/items to get items for mapping
  3. Process Import: Call POST /imports/process to either:
    • Map to existing item (action: "map")
    • Create new item (action: "create")
  4. 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:

  1. Retrieve Pending Items: Call POST /imports/select-items to get new imported items
  2. Process Clearance: Review items and obtain customs clearance
  3. Update Status: Call POST /imports/update-items to update item status in VSCU
  4. 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 hour

Process 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/process

Headers

Authorization: Bearer YOUR_API_KEY X-Branch-ID: YOUR_BRANCH_ID Content-Type: application/json

Request 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

FieldTypeRequiredDescription
actionstringYesAction type: “map” (use existing item) or “create” (create new item)
task_codestringYesCustoms task code
declaration_datestringYesDeclaration date (YYYYMMDD format)
declaration_numberstringYesCustoms declaration number
item_sequenceintegerYesItem sequence number
hs_codestringYesHarmonized System code
import_item_namestringYesItem name from customs
origin_nation_codestringYesCountry of origin code (2 chars)
quantitynumberYesItem quantity (min: 0.01)
quantity_unit_codestringYesQuantity unit code
supplier_namestringNoSupplier/vendor name
invoice_amountnumberYesInvoice amount in foreign currency (min: 0)
invoice_currencystringNoForeign currency code (e.g., “USD”)
exchange_ratenumberNoExchange rate to KES (defaults to 1)
existing_item_codestringConditionalRequired if action is “map”. Item code to map to
new_itemobjectConditionalRequired if action is “create”. New item details
new_item.item_codestringConditionalItem code (14 chars, format: CC+T+PP+QQ+NNNNNNN)
new_item.item_class_codestringConditionalItem classification code (10 chars)
new_item.item_namestringConditionalItem name
new_item.pkg_unit_codestringNoPackage unit code (defaults to “NT”)
new_item.qty_unit_codestringNoQuantity unit code
new_item.tax_typestringNoTax type code (A=16%, B/C/D/E=0%, defaults to “A”)
new_item.default_pricenumberNoDefault unit price (calculated if not provided)

Action Types

ActionDescription
mapMap the import to an existing item in your inventory. Requires existing_item_code
createCreate 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

FieldTypeDescription
item_codestringItem code that was mapped or created
item_namestringItem name
qty_addednumberQuantity added to inventory
previous_qtynumberQuantity before this operation
new_qtynumberCurrent quantity after stock in
kra_status_updatedbooleanWhether KRA import status was successfully updated
kra_stock_syncedbooleanWhether stock movement was successfully synced to KRA
sync_errorstringError message if KRA stock sync failed (only present if kra_stock_synced is false)

Processing Flow

When you process an import, the following happens:

  1. Item Handling:

    • If action=map: Lookup existing item by existing_item_code
    • If action=create: Register new item with KRA and save to local database
  2. KRA Status Update:

    • Update import status in KRA to “3” (Registered)
    • Link the import to the item code
  3. 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 Amount

Tax 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/items

Headers

Authorization: Bearer YOUR_API_KEY X-Branch-ID: YOUR_BRANCH_ID

Response

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

FieldTypeDescription
idintegerInternal item ID
item_codestringKRA item code
item_namestringItem name
item_class_codestringItem classification code
current_qtynumberCurrent stock quantity
default_pricenumberDefault unit price
tax_type_codestringTax type (A=16%, B/C/D/E=0%)
pkg_unit_codestringPackage unit code
qty_unit_codestringQuantity unit code
origin_nation_codestringCountry of origin

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_date should 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
Last updated on