Ujuzi Kilimo API Documentation
Welcome to the Ujuzi Kilimo API documentation. This comprehensive guide provides 3rd party developers with all the information needed to integrate with our agricultural data platform.
Access farmer data, soil test results, agricultural recommendations, market information, and more through our RESTful API endpoints.
Quick Start Guide
Base URL
https://farmsuitedev.ujuzikilimo.com/api
Authentication
Most endpoints require authentication. Use the login endpoint to obtain an access token:
POST https://farmsuitedev.ujuzikilimo.com/api/login
Content-Type: application/json
{
"email": "[email protected]",
"password": "your-password"
}
Response Format
All API responses are returned in JSON format:
{
"success": true,
"data": {
// Response data here
},
"message": "Success message"
}
Error Handling
Error responses include appropriate HTTP status codes and error messages:
{
"success": false,
"error": "Error description",
"code": 400
}
Mobile App Integration Guide
Step 1: Obtain Your Mobile API Key
Contact your system administrator to get a mobile API key. Mobile keys are identified by the prefix mobile_ and provide automatic free tier access.
Step 2: Generate Authentication Token
Use your mobile API key to generate an authentication token:
PHP Example
<?php
// Generate authentication token
$apiKey = 'mobile_your_api_key_here';
$baseUrl = 'https://farmsuitedev.ujuzikilimo.com/api/v1/auth';
$data = [
'api_key' => $apiKey,
'email' => '[email protected]',
'password' => 'userpassword',
'device_name' => 'My Mobile App',
'expires_in' => 3600 // 1 hour (optional)
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $baseUrl . '/generate-token');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Accept: application/json'
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode === 200) {
$result = json_decode($response, true);
$token = $result['data']['token'];
echo "Token: " . $token;
} else {
echo "Error: " . $response;
}
?>
Expected Response
{
"success": true,
"data": {
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...",
"token_type": "Bearer",
"expires_at": "2024-01-01T12:00:00.000000Z",
"api_key": "mobile_your_api_key_here"
},
"message": "Token generated successfully"
}
Step 3: Use Token for API Requests
Include the token in the Authorization header for all API requests:
PHP Example - Making API Calls
<?php
// Use token for API requests
$token = 'your_generated_token_here';
$baseUrl = 'https://farmsuitedev.ujuzikilimo.com/api';
function makeApiRequest($endpoint, $token, $method = 'GET', $data = null) {
global $baseUrl;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $baseUrl . $endpoint);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $token,
'Content-Type: application/json',
'Accept: application/json'
]);
if ($method === 'POST' && $data) {
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
}
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return [
'status_code' => $httpCode,
'response' => json_decode($response, true)
];
}
// Example: Get farmers list
$result = makeApiRequest('/farmers', $token);
if ($result['status_code'] === 200) {
$farmers = $result['response']['data'];
foreach ($farmers as $farmer) {
echo "Farmer: " . $farmer['name'] . "\n";
}
} else {
echo "Error: " . $result['response']['error'];
}
?>
Complete Integration Class
<?php
class UjuziKilimoAPI {
private $baseUrl;
private $apiKey;
private $token;
public function __construct($apiKey, $baseUrl = 'https://farmsuitedev.ujuzikilimo.com/api') {
$this->apiKey = $apiKey;
$this->baseUrl = $baseUrl;
}
public function generateToken($deviceName = 'Mobile App', $expiresIn = 3600) {
$data = [
'api_key' => $this->apiKey,
'device_name' => $deviceName,
'expires_in' => $expiresIn
];
$response = $this->makeRequest('/v1/auth/generate-token', 'POST', $data, false);
if ($response['status_code'] === 200) {
$this->token = $response['response']['data']['token'];
return $this->token;
}
throw new Exception('Failed to generate token: ' . $response['response']['error']);
}
public function getFarmers() {
return $this->makeRequest('/farmers');
}
public function getFarms($farmerId = null) {
$endpoint = $farmerId ? "/farmers/{$farmerId}/farms" : '/farms';
return $this->makeRequest($endpoint);
}
public function getSoilTests($farmId = null) {
$endpoint = $farmId ? "/farms/{$farmId}/soil-tests" : '/soil-tests';
return $this->makeRequest($endpoint);
}
private function makeRequest($endpoint, $method = 'GET', $data = null, $requiresAuth = true) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->baseUrl . $endpoint);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$headers = [
'Content-Type: application/json',
'Accept: application/json'
];
if ($requiresAuth && $this->token) {
$headers[] = 'Authorization: Bearer ' . $this->token;
}
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
if ($method === 'POST' && $data) {
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
}
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return [
'status_code' => $httpCode,
'response' => json_decode($response, true)
];
}
}
// Usage example
try {
$api = new UjuziKilimoAPI('mobile_your_api_key_here');
$token = $api->generateToken('My Mobile App');
$farmers = $api->getFarmers();
if ($farmers['status_code'] === 200) {
foreach ($farmers['response']['data'] as $farmer) {
echo "Farmer: " . $farmer['name'] . "\n";
}
}
} catch (Exception $e) {
echo "Error: " . $e->getMessage();
}
?>
Step 4: Token Management
Refresh Token
<?php
// Refresh existing token
$data = [
'api_key' => $apiKey,
'device_name' => 'My Mobile App',
'expires_in' => 7200 // 2 hours
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $baseUrl . '/v1/auth/refresh-token');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $currentToken,
'Content-Type: application/json'
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
?>
Revoke Token
<?php
// Revoke token when done
$data = ['revoke_all' => true]; // or specific token_id
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $baseUrl . '/v1/auth/revoke-token');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $token,
'Content-Type: application/json'
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
?>
Best Practices
- Token Storage: Store tokens securely and never expose them in client-side code
- Error Handling: Always check HTTP status codes and handle errors gracefully
- Token Expiry: Implement automatic token refresh before expiration
- Rate Limiting: Respect API rate limits to ensure consistent access
- Security: Use HTTPS for all API communications in production
Mobile Token Authentication
Complete mobile authentication system with API keys and access tokens
POST
/api/v1/auth/generate-token
Generate access token for mobile devices using API key
Parameters
| Parameter | Description |
|---|---|
api_key |
Mobile API key (obtained from admin) |
email |
User email address |
password |
User password |
device_name |
Name of the mobile device (optional) |
expires_in |
Token expiration in seconds (optional, default: 3600) |
Response
Returns access token and user information
Example Request
POST https://farmsuitedev.ujuzikilimo.com/api/v1/auth/generate-token
Content-Type: application/json
{
"api_key": "mobile_KmlVwF85BcojXYZ123...",
"email": "[email protected]",
"password": "userpassword",
"device_name": "iPhone 12",
"expires_in": 3600
}
Example Response
{
"success": true,
"message": "Token generated successfully",
"data": {
"token": "1|abcdef123456...",
"token_type": "Bearer",
"expires_at": "2024-01-01T12:00:00.000000Z",
"api_key": "mobile_KmlVwF85BcojXYZ123..."
}
}
POST
/api/v1/auth/revoke-token
Revoke access token (requires authentication)
Parameters
| Parameter | Description |
|---|---|
token_id |
Specific token ID to revoke (optional) |
device_name |
Device name to revoke tokens for (optional) |
revoke_all |
Boolean to revoke all user tokens (optional) |
Response
Returns revocation confirmation
Example Request
POST https://farmsuitedev.ujuzikilimo.com/api/v1/auth/revoke-token
Content-Type: application/json
{
"revoke_all": true
}
Example Response
{
"success": true,
"message": "Tokens revoked successfully",
"data": {
"revoked_count": 3
}
}
GET
/api/v1/auth/list-tokens
List all active tokens for authenticated user
Response
Returns list of active tokens
Example Response
{
"success": true,
"data": [
{
"id": 1,
"name": "iPhone 12",
"last_used_at": "2024-01-01T10:30:00.000000Z",
"created_at": "2024-01-01T09:00:00.000000Z"
}
]
}
POST
/api/v1/auth/refresh-token
Refresh access token (generates new token and revokes old one)
Parameters
| Parameter | Description |
|---|---|
api_key |
Mobile API key |
device_name |
Name of the mobile device (optional) |
expires_in |
Token expiration in seconds (optional) |
Response
Returns new access token
Example Request
POST https://farmsuitedev.ujuzikilimo.com/api/v1/auth/refresh-token
Content-Type: application/json
{
"api_key": "mobile_KmlVwF85BcojXYZ123...",
"device_name": "iPhone 12",
"expires_in": 7200
}
Example Response
{
"success": true,
"message": "Token refreshed successfully",
"data": {
"token": "2|newtoken123456...",
"token_type": "Bearer",
"expires_at": "2024-01-01T14:00:00.000000Z",
"api_key": "mobile_KmlVwF85BcojXYZ123..."
}
}
Legacy Authentication
Legacy authentication endpoints (deprecated for mobile use)
POST
/api/login
Authenticate user and get access token (legacy)
Parameters
| Parameter | Description |
|---|---|
email |
User email address |
password |
User password |
Response
Returns user data and authentication token
Farmer Management
Manage farmer data and profiles
GET
/api/farmers/{userId}
Get farmers data for a specific user
Parameters
| Parameter | Description |
|---|---|
userId |
User ID to fetch farmers for |
Response
Returns list of farmers associated with the user
GET
/api/farmers-profile/{userId}
Get farmer profile information
Parameters
| Parameter | Description |
|---|---|
userId |
User ID to fetch profile for |
Response
Returns detailed farmer profile data
POST
/api/create-farmer
Create a new farmer record
Parameters
| Parameter | Description |
|---|---|
name |
Farmer name |
phone |
Phone number |
location |
Farmer location |
other_fields |
Additional farmer data |
Response
Returns created farmer data
POST
/api/create-farmer-selfonboard
Self-onboard a new farmer
Parameters
| Parameter | Description |
|---|---|
farmer_data |
Complete farmer information for self-onboarding |
Response
Returns onboarded farmer data
Farm Management
Manage farm data and operations
GET
/api/farms/{userId}
Get farms for a specific farmer
Parameters
| Parameter | Description |
|---|---|
userId |
User ID to fetch farms for |
Response
Returns list of farms for the farmer
GET
/api/farm-details/{farmID}
Get detailed information about a specific farm
Parameters
| Parameter | Description |
|---|---|
farmID |
Farm ID to fetch details for |
Response
Returns detailed farm information
POST
/api/create-farm
Create a new farm record
Parameters
| Parameter | Description |
|---|---|
farm_name |
Name of the farm |
location |
Farm location |
size |
Farm size |
farmer_id |
Associated farmer ID |
Response
Returns created farm data
Soil Testing
Manage soil tests and results
GET
/api/v1/soil-tests/{user}
Get soil tests for a specific user
Parameters
| Parameter | Description |
|---|---|
user |
User ID to fetch soil tests for |
Response
Returns list of soil tests
GET
/api/soiltests/{userId}
Get farmer soil tests
Parameters
| Parameter | Description |
|---|---|
userId |
User ID to fetch soil tests for |
Response
Returns farmer soil test data
GET
/api/farm-soiltests/{farmId}
Get soil tests for a specific farm
Parameters
| Parameter | Description |
|---|---|
farmId |
Farm ID to fetch soil tests for |
Response
Returns soil tests for the specified farm
GET
/api/soiltests-details/{soiltestId}
Get detailed soil test results
Parameters
| Parameter | Description |
|---|---|
soiltestId |
Soil test ID to fetch details for |
Response
Returns detailed soil test results and recommendations
POST
/api/create-soil-test-samples
Create new soil test samples
Parameters
| Parameter | Description |
|---|---|
farm_id |
Farm ID for the soil test |
sample_data |
Soil sample information |
Response
Returns created soil test data
POST
/api/complete_soil_test
Complete and finalize soil test results
Parameters
| Parameter | Description |
|---|---|
soil_test_id |
Soil test ID to complete |
results |
Test results and recommendations |
Response
Returns completed soil test with recommendations
Agricultural Recommendations
Get crop recommendations and agricultural tips
GET
/api/agro-tips/{cropId}
Get agricultural recommendations for a specific crop
Parameters
| Parameter | Description |
|---|---|
cropId |
Crop ID to get recommendations for |
Response
Returns agricultural tips and recommendations
GET
/api/nutrition-data/{cropId}
Get nutrition data for a specific crop
Parameters
| Parameter | Description |
|---|---|
cropId |
Crop ID to get nutrition data for |
Response
Returns crop nutrition information
Market Data
Access market prices and crop information
GET
/api/market_data
Get current market data and prices
Response
Returns current market prices and trends
GET
/api/today_highlights
Get today's market highlights and featured crops
Response
Returns highlighted crops and market information
Agent Management
Manage agricultural agents and their data
GET
/api/agents/{userId}
Get agent data for a specific user
Parameters
| Parameter | Description |
|---|---|
userId |
User ID to fetch agent data for |
Response
Returns agent information and statistics
GET
/api/agent-role/{userId}
Get agent role information
Parameters
| Parameter | Description |
|---|---|
userId |
User ID to fetch role for |
Response
Returns agent role and permissions
Application Information
Get application version and status information
GET
/api/latest-version
Get the latest application version
Response
Returns current application version information
GET
/api/marketplace-status
Get marketplace status and availability
Response
Returns marketplace status information
Rate Limiting
API requests are rate limited to ensure fair usage:
- Authenticated requests: 1000 requests per hour
- Unauthenticated requests: 100 requests per hour
Rate limit headers are included in all responses to help you track your usage.
Support
Need help integrating with our API?
- Email: [email protected]
- Documentation: This page contains comprehensive API documentation
- Status Page: Check API status and uptime
We're here to help you succeed with your integration.
Ujuzi Kilimo API Documentation - Empowering Agricultural Innovation
Last updated: December 13, 2025