Fetch MarketEdge for Item
The Entrupy iOS SDK provides a fetchMarketEdgeForItem(withEntrupyID:) API that enables programmatic fetching of MarketEdge data for an authentication result. This guide covers prerequisites, the delegate-based flow, response structure, and how to decode and use the data in your own UI or business logic.
Overview
For displaying MarketEdge (grade, value, match, region), prefer MarketEdge View UI using displayMarketEdgeViewForItem(withEntrupyID:withConfiguration:). Use fetchMarketEdgeForItem(withEntrupyID:) when you need the data in your own UI or business logic.
The fetchMarketEdgeForItem API provides:
- MarketEdge data - MarketGrade, MarketValue, MarketMatch and disclaimer.
- Delegate based flow - Set the
marketEdgeDelegateand handle success and failure via delegate callbacks, data is delivered through these callbacks.
Prerequisites
- User must be authorized:
entrupyApp.isAuthorizationValid() == true - Set
entrupyApp.marketEdgeDelegateto an object conforming toEntrupyMarketEdgeDelegatebefore calling
Method Signature
func fetchMarketEdgeForItem(withEntrupyID entrupyID: String)
Usage Examples
// 1. Set delegate
entrupyApp.marketEdgeDelegate = self
// 2. Call API (e.g. after user provides entrupyId)
entrupyApp.fetchMarketEdgeForItem(withEntrupyID: entrupyId)
Handling Success and Decoding
The success callback receives a response dictionary that can be decoded into the SDK-provided model EntrupyMarketEdge.
func didFetchMarketEdgeCompleteSuccessfully(_ response: [AnyHashable : Any], forEntrupyID entrupyID: String) {
do {
let data = try JSONSerialization.data(withJSONObject: response, options: [])
let marketEdge = try JSONDecoder().decode(EntrupyMarketEdge.self, from: data)
// Check for MarketEdge level error
if let error = marketEdge.error {
// Handle MarketEdge error
return
}
// Access MarketEdge properties
let identifier = marketEdge.identifier
let marketGrade = marketEdge.market_grade
let marketValue = marketEdge.market_value
let marketMatch = marketEdge.market_match
let disclaimer = marketEdge.disclaimer
// Use the parsed data to populate UI or business logic
} catch {
// Handle decoding errors
}
}
Handling Failure
func didFetchMarketEdgeFailWithError(_ errorCode: EntrupyErrorCode, description: String, localizedDescription: String, forEntrupyID entrupyID: String) {
DispatchQueue.main.async {
// Get the error code and localizedDescription when fetchMarketEdgeForItem fails
}
}
Response Structure
The success callback's response dictionary can be decoded into the SDK-provided model EntrupyMarketEdge (e.g. via JSONSerialization and JSONDecoder).
Model Property
| Field | Description |
|---|---|
identifier | Authentication identifiers for the item. |
market_grade | Condition rating based on submitted images, includes rating, item report details, and region-level descriptions. Typed as EntrupyMarketGrade. |
market_value | Best estimate of the item's value based on recent market data; includes price and currency. Typed as EntrupyMarketValue. |
market_match | Recent marketplace listings similar to the submitted item (e.g. brand, style, price). Typed as EntrupyMarketMatch. |
disclaimer | Disclaimer text for MarketGrade and MarketValue. |
error | Error information when MarketEdge data is unavailable or failed. |
Error Handling
Use the localizedDescription parameter in the failure callback to display user-friendly error messages. For detailed information about specific error codes and handling strategies, see the Error Code Reference.
Next Steps
- Review Understanding MarketEdge in the SDK for the full MarketEdge data structure and field meanings.
- Learn about MarketEdge View UI for presenting the SDK's built-in MarketEdge screen (
displayMarketEdgeViewForItem(withEntrupyID:withConfiguration:)). - Review Programmatic Access to Session Data for fetching individual item details and building custom item detail UIs.