Passio Nutrition-AI
  • Nutrition-AI SDK Overview
  • Guides
    • Nutrition AI SDK
      • SDK Key and minimum requirements
      • Installation
      • Configure the SDK
      • Use Cases
        • Food recognition
        • Nutrition data
        • Barcode scanning
        • Nutrition Facts scanning
        • Search, Food Icons, RefCode
        • Speech recognition
        • Nutrition Advisor
        • Suggestions and Meal Plans
        • User created foods and reports
    • iOS SDK Docs
      • Before getting started
      • Getting the ml models to the device
      • Run the demos first
      • Adding Passio SDK into your project
      • Initialize and configure the SDK
      • Start/Stop food detection
      • Food Recognition Delegate
      • Migration from SDK 1.4.X to 2.x
      • SDK API
      • Quick Start Guide
        • Installation
        • Configure the SDK (UIKit)
        • Recognise food using image
        • Food Details
    • Android SDK Docs
      • Getting started
        • Include the library
        • Camera
        • SDK Initialization and Configuration
        • Food detection session
        • Visual, Barcode and Packaged Food detection
        • Nutritional Database
        • Sandbox app
      • Troubleshooting on Android
      • Migration from SDK version 1.4.x to 2.x
      • Quick Start Guide
        • Importing the Android SDK to a project
        • Configure SDK and handle the result
        • RecognizeImageRemote
        • Food Details
    • React Native SDK Docs
      • Getting Started
        • Installation
        • SDK Initialization and Configuration
      • API Reference
        • configure & requestCameraAuthorization
        • recognizeImageRemote
        • searchForFood & searchForFoodSemantic
        • startFoodDetection
          • FoodDetectionEvent
        • fetchFoodItemForProductCode
        • fetchFoodItemForRefCode
        • fetchFoodItemForDataInfo
        • startNutritionFactsDetection
        • fetchFoodItemForPassioID
        • recognizeSpeechRemote
        • Fetch Nutrients
        • onDowloadingPassioModelCallBacks
        • detectFoodFromImageURI
        • addToPersonalization
        • updateLanguage
        • fetchHiddenIngredients
        • fetchVisualAlternatives
        • fetchPossibleIngredients
      • Properties
        • PassioFoodItem
        • PassioFoodDataInfo
        • PassioFoodAmount
        • PassioIngredient
        • PassioNutrients
        • UnitMass
        • ServingUnit
        • ServingSize
        • PassioSearchResult
        • NutritionFacts
        • PassioNutritionPreview
        • PassioSpeechRecognitionModel
        • PassioLogAction
        • PassioAdvisorFoodInfo
        • FoodCandidates
        • FoodDetectionEvent
        • NutritionDetectionEvent
        • DetectedCandidate
        • BarcodeCandidate
        • PackagedFoodCode
        • AmountEstimate
        • ImagesInfo
        • PassioStatus
        • FoodDetectionEvent
        • NutritionFacts
        • PassioMealPlan
        • PassioMealPlanItem
      • Nutriton Advisor
        • initConversation
        • sendMessage
        • sendImage
        • Guide
          • useNutritionAdvisor
        • Properties
          • PassioAdvisorResponse
          • PassioAdvisorMessageResultStatus
          • PassioAdvisorResultStatus
      • Quick Start Guide
        • Installation
        • Configure the SDK
        • RecognizeImageRemote
        • Food Detail
      • Guide
        • Integrate SDK Setup
        • Integrate Quick Scan
        • Integrate Food Search
        • Integrate Food Editor with Recipe
        • Integrate MealPlan
        • Integrate Suggestions
        • Integrate recognizeImageRemote
      • Components
        • DetectionCameraView
        • PassioIconView
      • Changelog
      • More
        • Display Macro Chart
          • MockFood
          • Utils PassioNutrient
        • Display Micro Progress
        • Getting nutrition value for a FoodItem
        • Getting nutrition value for a Recipe
        • Recalculate the nutrition value based on serving size options.
      • Migrations
        • Migrating from SDK 2.X to version 3.X
        • Structure Migrations From SDK 3.X to SDK 2.X
        • [Deprecated] Migrating from SDK 1.X to version 2.X
        • [Deprecated] Getting Started (v1)
          • Installation
          • SDK Initialization and Configuration
          • Start food detection
          • FoodDetectionEvent
          • Nutritional Database
      • Troubleshooting on RN
      • V2
        • Getting Started
          • Installation
          • SDK Initialization and Configuration
          • Start food detection
          • FoodDetectionEvent
        • RN SDK API
          • Properties
            • PersonalizedAlternative
            • FoodSearchResult
            • PassioNutrient
            • FoodDetectionEvent
            • DownloadModelCallBack
            • UPCProduct
            • ServingUnit
            • PassioStatus
            • PassioIDAttributes
            • PassioIDEntityType
            • PassioFoodItem
            • PassioRecipe
            • ServingSize
            • Measurement
            • UnitMass
            • NutritionFacts
        • Food Image
        • Search Food Item
        • Quick Scan
        • Multi Scan
        • MealPlan
        • Recipe
      • How do I Integrate a Passio SDK in EXPO?
    • Flutter SDK Docs
      • Getting Started
    • Before You Continue
    • Setup For Android
    • Initialize and configure the SDK
  • Fundamentals
    • Nutrition-AI Developer FAQ
      • Nutrition Data
      • Supported Phones
      • Security
      • Testing Volume Estimation
      • Testing Nutrition-AI SDK
      • Nutrition-AI Test Methodology
    • Nutrition API - Mobile SDK interoperability
      • JSON Response parsing
  • Versions
    • 3.2.4
      • SDK Key and minimum requirements
      • Installation
      • Configure the SDK
      • Use Cases
        • Food recognition
        • Nutrition data
        • Barcode scanning
        • Nutrition Facts scanning
        • Search, Food Icons, RefCode
        • Speech recognition
        • Nutrition Advisor
        • Suggestions and Meal Plans
        • User created foods and reports
    • 3.2.2
      • SDK Key and minimum requirements
      • Installation
      • Configure the SDK
      • Use Cases
        • Food recognition
        • Nutrition data
        • Barcode scanning
        • Nutrition Facts scanning
        • Search, Food Icons, RefCode
        • Speech recognition
        • Nutrition Advisor
        • Suggestions and Meal Plans
        • User created foods and reports
    • 3.2.0
      • SDK Key and minimum requirements
      • Installation
      • Configure the SDK
      • Use Cases
        • Food recognition
        • Nutrition data
        • Barcode scanning
        • Nutrition Facts scanning
        • Search, Food Icons, RefCode
        • Speech recognition
        • Nutrition Advisor
        • Suggestions and Meal Plans
    • 3.1.4
      • SDK Key and minimum requirements
      • Installation
      • Configure the SDK
      • Use Cases
        • Food recognition
        • Nutrition data
        • Barcode scanning
        • Search, Food Icons, RefCode
        • Speech recognition
        • Nutrition Advisor
        • Suggestions and Meal Plans
Powered by GitBook
On this page
  • Food search
  • Image recognition
  • Speech recognition
  • RefCode result
  • Barcode result
Export as PDF
  1. Fundamentals

Nutrition API - Mobile SDK interoperability

PreviousNutrition-AI Test MethodologyNextJSON Response parsing

Last updated 3 months ago

Food search

Mobile SDK: searchForFoodSemantic

API: https://api.passiolife.com/v2/products/food/search/semantic?term=$query

or

Mobile SDK: searchForFood

API: https://api.passiolife.com/v2/products/food/search/advanced?term=$query

  • The SDK adds the Localization-ISO header to the request if the locale code was set using the function updateLanguage

  • The API response provides two JSON arrays: search responses and alternate names (suggestions)

  • The search responses JSON is mapped to a PassioFoodDataInfo object using mapping

Image recognition

MobileSDK: recognizeImageRemote

API: https://api.passiolife.com/v2/products/sdk/tools/vision/extractIngredients

  • The SDK actually executes several steps before sending the request to the aforementioned API, which include barcode scanning, and OCR for nutrition facts recognition

  • If the SDK did not detect a barcode or nutrition facts in the image, it will proceed with the preparation of the request

  • The body of the request will contain a base64 encoded string of the native image

  • The SDK adds the Localization-ISO header to the request if the locale code was set using the function updateLanguage

  • The successful response is mapped to a list of PassioAdvisorFoodInfo objects, using mapping

Speech recognition

MobileSDK: recognizeSpeechRemote

API: https://api.passiolife.com/v2/products/sdk/tools/extractMealLogAction

  • The body contains the plain text passed as an argument to the recognizeSpeechRemote function

  • The SDK adds the Localization-ISO header to the request if the locale code was set using the function updateLanguage

RefCode result

MobileSDK: fetchFoodItemForRefCode

API: https://api.passiolife.com/v2/products/food/search/result/refCode/$refCode

  • The response contains the same JSON as the Food searchresponse, but here the alternatives field is not parsed, and the response will only contain one result in the JSON array

  • The refCode is also parsed for extracting the boolean variable called shortName

val responseItem = response.results.first()
val shortName = DataUtils.metadataHasShortName(refCode)
val foodItem = PassioFoodItem.fromSearchResponse(responseItem, shortName)
callback(foodItem)

fun metadataHasShortName(encoded: String): Boolean {
    val decoded = Base64.decode(encoded, Base64.DEFAULT).toString(Charset.defaultCharset())
    val jsonObject = JSONObject(decoded).optJSONObject("metadata")
    return jsonObject?.optBoolean(SHORT_NAME) ?: false
}

Barcode result

MobileSDK: fetchFoodItemForProductCode

API: https://api.passiolife.com/v2/products/food/productCode/$upcCode?metadata=$encoded

private const val SHORT_NAME = "shortName"

fun encodeMetadata(shortName: Boolean): String {
    val metadata = """{"$SHORT_NAME": $shortName}"""
    return Base64.encodeToString(metadata.toByteArray(), Base64.NO_WRAP)
}
  • The SDK adds the Localization-ISO header to the request if the locale code was set using the function updateLanguage

The successful response is mapped to a list of PassioSpeechRecognitionModel objects, using mapping

That result is parsed as a PassioFoodItem object, using mapping

The SDK will add the encoded metadata into the url of the request. The metadata contains a boolean key called shortName, used in the

That result is parsed as a PassioFoodItem object, using mapping

PassioFoodDataInfo
PassioAdvisorFoodInfo
PassioSpeechRecognitionModel
Parsing from search routes
PassioFoodDataInfo
Parsing from packaged product routes