Skip to content

Markets

API Type

eCommerce API - Uses API key in request body. See Authentication.

Fetch available markets and get suggested markets based on user location.

Get Markets

Retrieve a list of available markets and optionally get a suggested market based on geographic coordinates.

Endpoint

POST https://{ecomm}.photobook.ai/api/v2/misc/get-market.php

Replace {ecomm} with your assigned client identifier.

Example: https://yourclient.photobook.ai/api/v2/misc/get-market.php

Authentication

See Authentication - eCommerce

Request Parameters

json
{
  "env": "dev",
  "key": "your-api-key",
  "language": "en",
  "latitude": 1.3521,
  "longitude": 103.8198
}
ParameterTypeRequiredDescription
envstringYesTarget environment: dev or prod
keystringYesYour programmatic access key
languagestringNoFirst 2 characters of language code (e.g., en for en-US). Defaults to en
latitudefloatNoUser's latitude. If provided with longitude, returns a suggested market
longitudefloatNoUser's longitude. If provided with latitude, returns a suggested market

Response

json
{
  "results": [
    {
      "marketId": 0,
      "storeName": "Global Store",
      "isoCode2": "US",
      "currency": "USD",
      "shipsWithin": [
        {
          "isoCode2": "US",
          "name": "United States"
        },
        {
          "isoCode2": "CA",
          "name": "Canada"
        }
      ]
    }
  ],
  "suggested": {
    "marketId": 0,
    "storeName": "Global Store",
    "isoCode2": "US",
    "currency": "USD",
    "shipsWithin": [
      {
        "isoCode2": "US",
        "name": "United States"
      }
    ]
  }
}

Response Fields

results (array)

List of all available markets.

FieldTypeDescription
marketIdintegerUnique market identifier
storeNamestringDisplay name of the market
isoCode2stringISO 3166-1 alpha-2 country code
currencystringCurrency code (e.g., USD, EUR)
shipsWithinarrayList of countries/regions this market ships to

shipsWithin (array)

FieldTypeDescription
isoCode2stringISO code of country or area (continent)
namestringDisplay name of country or area

suggested (object)

Only returned if latitude and longitude were provided. Contains the same fields as objects in results.

Store the Selected Market

The marketId should be stored and used for subsequent API calls (products, projects, orders).

Auto-Select Based on Location

If you can retrieve the user's latitude and longitude:

  1. Call this API with location parameters
  2. Auto-select the suggested market
  3. Still allow users to change their market via UI

This saves users the hassle of manually selecting a market.

Handle No Location Data

If latitude/longitude is not available:

Option 1: Prompt user to select market first

  • Store the selection for future sessions
  • Load products only after market is selected

Option 2: Load with default market

  • Use marketId: 0 initially
  • Let users change market via dropdown in your UI

Refresh Products on Market Change

When a user changes their selected market, refetch the products as pricing and availability may differ.

Example Implementation

javascript
async function getMarkets(latitude, longitude) {
  const response = await fetch('https://{ecomm}.photobook.ai/api/v2/misc/get-market.php', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      env: 'dev',
      key: 'your-api-key',
      language: 'en',
      latitude: latitude,
      longitude: longitude
    })
  });
  
  const data = await response.json();
  
  // Auto-select suggested market if available
  const selectedMarket = data.suggested || data.results[0];
  
  // Store marketId for future API calls
  localStorage.setItem('marketId', selectedMarket.marketId);
  
  return data;
}

photobook.ai Developer Documentation