Mobile App Integration
Connect your iOS and Android applications to the Selfimart platform using our plug & play API credentials system. Generate credentials, configure your app, and start making API calls in minutes.
Quick Start Guide
Access Integration Dashboard
Log in to your dashboard and navigate to Integration > Mobile Apps. Here you will manage all your mobile app credentials.
Generate Credentials
Click "Generate New Credentials" to create a new API key/secret pair. Select your platform (iOS, Android, or All Platforms) and environment (Production, Staging, Development).
Configure Your Mobile App
Copy the API Key and API Secret to your mobile app configuration file. The Base URL should point to the API endpoint.
Initialize the SDK
Use the credentials to initialize the Selfimart SDK in your mobile app. The SDK handles authentication, token refresh, and API communication automatically.
Test the Connection
Make a test API call to verify the connection is working correctly. Check the Usage page in the dashboard to confirm requests are being logged.
// Initialize the Selfimart client
import SelfimartClient from '@selfimart/api-client';
const client = new SelfimartClient({
apiKey: 'mobile_your_api_key_here',
apiSecret: 'your_api_secret_here',
baseUrl: 'https://selfimart.com/api/v1'
});
// User authentication
const login = async (email, password) => {
const response = await client.login(email, password, 'mobile-app');
// Token is automatically stored and used for subsequent requests
return response;
};
// Browse products
const getProducts = async (categoryId) => {
const response = await client.getProducts({
category_id: categoryId,
per_page: 20
});
return response.data;
};
// Add to cart
const addToCart = async (productId, quantity = 1) => {
return await client.addToCart(productId, quantity);
};
// Place order
const placeOrder = async (orderData) => {
return await client.createOrder({
shipping_address_id: orderData.addressId,
shipping_method: orderData.shippingMethod,
payment_method: orderData.paymentMethod,
notes: orderData.notes
});
};
import Foundation
class SelfimartClient {
private let baseUrl = "https://selfimart.com/api/v1"
private let apiKey: String
private let apiSecret: String
private var token: String?
init(apiKey: String, apiSecret: String) {
self.apiKey = apiKey
self.apiSecret = apiSecret
}
// Authenticate user
func login(email: String, password: String) async throws -> AuthResponse {
var request = URLRequest(url: URL(string: "\(baseUrl)/auth/login")!)
request.httpMethod = "POST"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.setValue(apiKey, forHTTPHeaderField: "X-API-Key")
let body: [String: Any] = [
"email": email,
"password": password,
"device_name": "ios-app"
]
request.httpBody = try JSONSerialization.data(withJSONObject: body)
let (data, _) = try await URLSession.shared.data(for: request)
let response = try JSONDecoder().decode(AuthResponse.self, from: data)
self.token = response.token
return response
}
// Get products
func getProducts(categoryId: Int? = nil) async throws -> [Product] {
var urlComponents = URLComponents(string: "\(baseUrl)/products")!
if let categoryId = categoryId {
urlComponents.queryItems = [URLQueryItem(name: "category_id", value: "\(categoryId)")]
}
var request = URLRequest(url: urlComponents.url!)
request.setValue("Bearer \(token ?? "")", forHTTPHeaderField: "Authorization")
request.setValue(apiKey, forHTTPHeaderField: "X-API-Key")
let (data, _) = try await URLSession.shared.data(for: request)
return try JSONDecoder().decode([Product].self, from: data)
}
}
class SelfimartClient(
private val apiKey: String,
private val apiSecret: String,
private val baseUrl: String = "https://selfimart.com/api/v1"
) {
private val client = OkHttpClient()
private var token: String? = null
// Authenticate user
suspend fun login(email: String, password: String): AuthResponse {
val requestBody = JSONObject().apply {
put("email", email)
put("password", password)
put("device_name", "android-app")
}.toString().toRequestBody("application/json".toMediaType())
val request = Request.Builder()
.url("$baseUrl/auth/login")
.post(requestBody)
.addHeader("X-API-Key", apiKey)
.addHeader("Content-Type", "application/json")
.build()
client.newCall(request).execute().use { response ->
val body = response.body?.string() ?: throw IOException("Empty response")
val json = JSONObject(body)
token = json.optString("token")
return AuthResponse(
token = token!!,
user = json.getJSONObject("user").let { userJson ->
User(
id = userJson.getInt("id"),
name = userJson.getString("name"),
email = userJson.getString("email")
)
}
)
}
}
// Get products
suspend fun getProducts(categoryId: Int? = null): List<Product> {
val urlBuilder = "$baseUrl/products".toHttpUrlOrNull()?.newBuilder()
categoryId?.let { urlBuilder?.addQueryParameter("category_id", it.toString()) }
val request = Request.Builder()
.url(urlBuilder?.build()!!)
.addHeader("Authorization", "Bearer $token")
.addHeader("X-API-Key", apiKey)
.build()
client.newCall(request).execute().use { response ->
val body = response.body?.string() ?: throw IOException("Empty response")
// Parse and return products
return parseProducts(body)
}
}
}
Sync Configuration
Offline Mode Support
The mobile SDK supports offline mode with automatic synchronization when connectivity is restored.
{
"enable_offline_cache": true,
"cache_expiry_hours": 24,
"sync_on_reconnect": true,
"conflict_resolution": "server_wins"
}
Push Notifications
Register for push notifications to receive order updates and promotional messages.
{
"register_device_token": "\/api\/v1\/user\/device-token",
"topics": [
"orders",
"promotions",
"general"
]
}
Data Synchronization
Configure how data is synchronized between the mobile app and server.
{
"sync_interval_seconds": 300,
"sync_on_app_open": true,
"sync_products": true,
"sync_categories": true,
"sync_user_data": true
}
Available API Endpoints
Products
Read/api/v1/products
/api/v1/products/{id}
/api/v1/products/search
Cart
Read/Write/api/v1/cart
/api/v1/cart/items
/api/v1/cart/items/{id}
Orders
Read/Write/api/v1/orders
/api/v1/orders/{id}
/api/v1/orders
Authentication
Auth/api/v1/auth/login
/api/v1/auth/logout
/api/v1/auth/refresh
Ready to connect your mobile app?
Generate your API credentials and start integrating today.