Programmatic Access to Session Data
While the Entrupy iOS SDK provides comprehensive UI components like the Detail View Controller for displaying item authentication status and details, there are scenarios where you might need to fetch and present this information within your application's custom interface.
This guide outlines how to programmatically access session details for an authenticated item.
Overview
The SDK allows you to query data for a specific item using its entrupy_id
. This typically includes:
- Current authentication status (e.g., Processing, Authentic, Unidentified).
- Estimated Time of Arrival (ETA) if results are pending.
- Key item metadata.
- Certificate information (if applicable).
- Associated Catalog Data.
The data retrieved programmatically generally mirrors what is displayed in the SDK's Detail View Controller. This approach is suitable for displaying specific pieces of information in a custom UI or for light, infrequent data retrieval.
For bulk data operations, reporting across multiple items, or extensive data analysis, it is strongly recommended to use the server-side Entrupy API rather than making numerous calls through the mobile SDK. The SDK's programmatic access is optimized for on-demand, single-item lookups.
Fetching Session Details
sdk-v1-legacy.md
does not explicitly define a dedicated SDK method to fetch all session details programmatically in a single structured object like the direct-access/session-details.md
stub suggests (e.g., EntrupySDK.shared.fetchSessionDetails
).
However, the core information can often be pieced together or is implicitly available through various delegate methods and properties after an authentication or search. For example:
-
After Capture: The
EntrupyCaptureDelegate
methoddidCaptureCompleteSuccessfully(_ result: [AnyHashable : Any], forItem item: [AnyHashable : Any])
provides an initialresult
dictionary. This dictionary (decodable withEntrupyCaptureResult
) contains the initial status, Entrupy ID, and other details.// Swift - From Capture Delegate (Illustrative)
func didCaptureCompleteSuccessfully(_ result: [AnyHashable : Any], forItem item: [AnyHashable : Any]) {
do {
let decoder = JSONDecoder()
let jsonData = try JSONSerialization.data(withJSONObject: result)
let parsedResult = try decoder.decode(EntrupyCaptureResult.self, from: jsonData) // Ensure EntrupyCaptureResult struct is defined as per SDK
let entrupyId = parsedResult.item.entrupyId
let initialStatus = parsedResult.status.result.display.header
let etaSeconds = parsedResult.status.result.eta // Assuming ETA is available here
// Update your custom UI with this initial data
print("Item \(entrupyId ?? "N/A") submitted. Status: \(initialStatus). ETA: \(etaSeconds ?? 0)s")
} catch {
print("Error decoding capture result: \(error)")
}
} -
After Search: The
EntrupySearchDelegate
methoddidSearchSubmissionsCompleteSuccessfully(_ result: [AnyHashable: Any])
provides aresult
dictionary containing a list of items (decodable withEntrupySearchResult
andEntrupySearchItem
). Each item in the search result will have its own details, includingentrupy_id
, status, brand, etc.// Swift - From Search Delegate (Illustrative)
func didSearchSubmissionsCompleteSuccessfully(_ result: [AnyHashable: Any]) {
do {
let jsonData = try JSONSerialization.data(withJSONObject: result)
let decoder = JSONDecoder()
let searchResult = try decoder.decode(EntrupySearchResult.self, from: jsonData) // Ensure EntrupySearchResult struct is defined
for searchItem in searchResult.items {
let entrupyId = searchItem.item.entrupyId
let status = searchItem.status.result.display.header
// Access other fields like searchItem.properties.brand.name etc.
print("Found item: \(entrupyId ?? "N/A") - Status: \(status)")
// You can use this data to populate a list in your custom UI
// Selecting an item could then trigger a more detailed fetch if needed/available
}
} catch {
print("Error decoding search result: \(error)")
}
}
Conceptual Direct Fetch (If SDK supports a dedicated method):
If the SDK were to offer a direct fetch method as suggested in the site/docs/mobile-sdks/ios-old/direct-access/session-details.md
stub, it might look like this. Note: This is a conceptual example; verify against actual SDK capabilities.
// Swift - Conceptual Direct Fetch (Verify Actual SDK Method)
/*
func fetchAndDisplayItemDetails(entrupyId: String) {
EntrupySDK.shared.fetchSessionDetails(entrupyId: entrupyId) { result in // Fictional method
DispatchQueue.main.async {
switch result {
case .success(let details):
// Assuming 'details' is a struct containing all necessary info:
// let statusText = details.status.result.display.header
// let etaMinutes = (details.status.result.eta ?? 0) / 60
// let certificateURL = details.certificate?.url
// let brandName = details.properties.brand.name
// ... and so on for catalog data, flags, etc.
// Update your custom UI elements
// self.statusLabel.text = "Status: \(statusText) - ETA: \(etaMinutes)m"
// self.brandLabel.text = "Brand: \(brandName)"
print("Successfully fetched details for \(entrupyId)")
case .failure(let error):
// Handle the error (e.g., item not found, network issue)
// self.statusLabel.text = "Unable to load status for \(entrupyId)"
print("Error fetching details for \(entrupyId): \(error.localizedDescription)")
}
}
}
}
*/
Available Data Points
When accessing session data programmatically (either from delegate callbacks or a direct fetch method if available), you can typically expect to retrieve information such as:
entrupy_id
: The unique Entrupy identifier for the authentication session.- Status Information: Current processing state, final result (Authentic, Unidentified, etc.), result display strings.
- ETA: Estimated Time of Arrival for results (often in seconds or as a timestamp).
- Item Properties: Brand, style name, customer item ID, and other metadata initially provided.
- Flag Details: Information on any flags applied to the result (see also Programmatic Customer Support for flag interactions).
- Certificate Details (for authentic items): Certificate ID, shareable URL.
- Catalog Data: Rich product information, condition assessment, etc. (see Understanding Catalog Data in SDK).
- Timestamps: Submission date, completion date, etc.
The exact structure and availability of these data points will be defined by the data models used by the SDK (e.g., EntrupyCaptureResult
, EntrupySearchItem
, or a dedicated EntrupySessionDetails
struct if a direct fetch method exists).
Use Cases
- Displaying a concise summary of an item's status in a list view within your app.
- Integrating specific data points (e.g., final result, certificate link) into a custom item detail screen that combines Entrupy data with your own application's information.
- Triggering application-specific workflows based on the authentication status or result.
Best Practices
- Asynchronous Operations: Data fetching should be asynchronous to avoid blocking the main thread. Update your UI on the main thread upon completion.
- Error Handling: Implement robust error handling for network issues, invalid IDs, or other potential problems.
- Data Consistency: If you are displaying data in a custom UI and also allowing users to access the SDK's Detail View Controller, ensure data consistency or provide clear context if there are differences in presentation.
- Respect Rate Limits: If making direct calls (should they exist), be mindful of API rate limits.
- Prioritize SDK UI: For a full, interactive experience (retakes, support chat), guiding the user to the SDK's Detail View Controller is often the best approach.
By using programmatic access to session data thoughtfully, you can enhance your application's UI while still benefiting from the comprehensive information managed by the Entrupy SDK.
Next Steps
- Learn about Programmatic Customer Support for interacting with flags and support messages.
- Review how to use the Search Authentications feature (from
sdk-v1-legacy.md
, Section 12) to get lists of items that can then be queried for details. - Explore the Understanding Catalog Data in SDK guide.