Receiving API (Mobile)
How to receive and handle the Onairos API response in mobile apps.
Updated 27 December 2024
mobileapifluttercallback
Receiving the Inference API
Once the user has connected their Onairos account and authorized data access, you'll receive the API URL and access token via the onResolved callback.
Callback Signature
Future<void> onResolved(String apiUrl, String accessToken) async {
// apiUrl: The endpoint to call for user data
// accessToken: Short-lived JWT token (1 hour validity)
}
Token Expiration
The access token is short-lived and valid for 1 hour from issue. Only valid on your registered domain.
Making the API Call
Flutter Example
Future<void> onResolved(String apiUrl, String accessToken) async {
try {
final response = await http.post(
Uri.parse(apiUrl),
headers: {
"Authorization": "Bearer $accessToken",
"Content-Type": "application/json",
},
body: jsonEncode(inferenceData),
);
if (response.statusCode == 200) {
final Map<String, dynamic> data = jsonDecode(response.body);
// Process Onairos user data
print("User data: $data");
} else {
print("Error: ${response.statusCode}");
}
} catch (e) {
print("Exception: $e");
}
}
Input Format
Send your inference data as an array of objects:
{
"Input": {
"input1": {
"text": "Product description or content",
"category": "fashion",
"img_url": "https://example.com/product.jpg"
},
"input2": {
"text": "Another item to analyze",
"category": "lifestyle"
}
}
}
| Field | Type | Required | Description |
|---|---|---|---|
text | String | ✅ | Text content for inference |
category | String | ✅ | Category of the content |
img_url | String | ❌ | Optional image URL |