Integration Guides

Documentation

Everything you need to add food search, barcode lookup, and AI photo scanning to your application โ€” in minutes.

Choose your platform

Production-ready SDKs with type safety, error handling, and built-in barcode scanning.

SDK Integration Guide

Quick start examples for each official SDK. All SDKs support food search, barcode lookup, AI photo scanning, and scan history.

PHP SDK

composer require grubscan/grubscan-php

PHP 8.1+

Installation

# Via Composer
composer require grubscan/grubscan-php

Quick Start

use Grubscan\GrubscanClient;

$client = new GrubscanClient([
    'api_key' => 'gs_your_api_key_here',
]);

// Search for foods
$results = $client->searchFoods('chicken breast', 10);
foreach ($results->data as $food) {
    echo "{$food->description}: {$food->calories} cal\n";
}

// Lookup barcode
$product = $client->lookupBarcode('074807750100');
echo $product->brandOwner;

AI Photo Scan

// Upload a food photo for AI analysis
$result = $client->scanFood('/path/to/food.jpg');

echo $result->detectedFood;           // "Grilled Chicken Salad"
echo $result->confidenceScore;      // 0.92
echo $result->estimatedNutrition->calories;

Error Handling

use Grubscan\Exceptions\{AuthenticationException, NotFoundException, RateLimitException};

try {
    $product = $client->lookupBarcode('123456789');
} catch (AuthenticationException $e) {
    // 401 - Invalid API key
} catch (NotFoundException $e) {
    // 404 - Product not found
} catch (RateLimitException $e) {
    // 429 - Monthly limit reached
    if ($e->isUpgradeRequired()) {
        echo "Please upgrade your plan\n";
    }
}

Direct API Integration

No SDK for your language? Use the REST API directly. All endpoints return JSON and use standard HTTP status codes.

Base URL

https://grubscan.io/api/v1

Authentication

All API requests require a Bearer token in the Authorization header. Generate API keys from your dashboard (Pro/Scale plans).

Authorization: Bearer gs_your_api_key_here
GET /foods

Food Search

Search the USDA FoodData Central database by food name. Returns matching foods with per-100g macros.

# Query parameters:
?query=chicken  (required)
&limit=20      (max 100)
&offset=0     (pagination)
GET /foods/{fdcId}

Food Detail

Retrieve full nutritional data for a specific USDA food by its FDC ID.

# Example:
GET /api/v1/foods/171477
GET /barcode/{barcode}

Barcode Lookup

Look up a product by GTIN/UPC/EAN. Falls back to Open Food Facts when USDA has no match.

# Example:
GET /api/v1/barcode/074807750100
POST /scans

AI Photo Scan

Upload a food image (multipart/form-data). Returns detected food name, confidence score, and nutritional breakdown.

# Form data:
image: <binary file>  (required, max 10MB)
GET /scans

List Scan History

Get paginated list of all AI photo scans for the authenticated tenant.

# Query parameters:
?page=1  (pagination)
GET /scans/{id}

Get Scan Details

Retrieve details of a specific scan by its ID.

# Example:
GET /api/v1/scans/01jqxxxxxx
Example Response: POST /scans
{
  "data": {
    "scan_id": 42,
    "detected_food": "Grilled Chicken Salad",
    "confidence_score": 0.92,
    "all_predictions": [
      { "name": "Grilled Chicken Salad", "confidence": 0.92 },
      { "name": "Caesar Salad", "confidence": 0.65 }
    ],
    "estimated_nutrition": {
      "calories": 350,
      "protein": 32.0,
      "fat": 14.0,
      "carbs": 18.0,
      "fibre": 4.5,
      "serving_size": "1 bowl (approx 350g)"
    },
    "usda_enhanced": false
  }
}

HTTP Status Codes

200 Success
201 Created (scan submitted)
400 Bad Request
401 Unauthorized - Invalid API key
403 Forbidden - Account suspended
404 Not Found
422 Validation Error
429 Rate Limit - Upgrade required
500 Server Error

Rate Limits

Each plan has a monthly API quota. When exceeded, the API returns:

{
  "error": "Rate limit exceeded",
  "upgrade_required": true,
  "retry_after": 3600
}

Your first API call

Generate an API key from the API Keys page (Pro/Scale plans), then authenticate every request with a Bearer token.

curl -X POST https://grubscan.io/api/v1/scans \
  -H "Authorization: Bearer gs_YOUR_API_KEY" \
  -F "image=@/path/to/meal.jpg"

More Languages

Need support for another language? Reach out for custom integration help or request an official SDK.

Integration Support

Need GrubScan in another language? Contact us for support with your technical integration.

Request an SDK

We are constantly expanding our library of official SDKs. If we don't currently support the language or framework you need, please reach out and let us know.

Ready to integrate?

Sign up for free, generate your first API key, and make your first request in under two minutes.