Code Examples
Code examples for the the Toast API endpoint calls that are used in stock checker service.
Authentication
Toast API Authentication Endpoint
async def get_toast_access_token() -> Optional[str]:
"""
get_toast_access_token() -> Optional[str]
Authenticates with Toast API and returns an access token.
"""
if not CLIENT_ID or not CLIENT_SECRET:
logger.error("CLIENT_ID or CLIENT_SECRET not configured")
return None
url = "https://ws-api.toasttab.com/authentication/v1/authentication/login"
payload = {
"clientId": CLIENT_ID,
"clientSecret": CLIENT_SECRET,
"userAccessType": "TOAST_MACHINE_CLIENT"
}
headers = {"Content-Type": "application/json"}
Check Store Stock
async def check_store_stock(store_name: str, restaurant_external_id: str, access_token: str) -> Dict:
"""
check_store_stock(store_name: str, restaurant_external_id: str, access_token: str) -> Dict
Checks stock status for all tracked items in a specific store.
Returns OUT_OF_STOCK and QUANTITY items.
"""
# Log tracking mode for this check
if USE_GUID_TRACKING:
logger.debug(f"Tracking {len(TRACKED_ITEM_GUIDS)} items by GUID for {store_name}")
else:
logger.debug(f"Tracking items by name for {store_name}")
url = "https://ws-api.toasttab.com/stock/v1/inventory"
params = {"status": "OUT_OF_STOCK"}
headers = {
"Authorization": f"Bearer {access_token}",
"Toast-Restaurant-External-ID": restaurant_external_id,
"Content-Type": "application/json"
}