Get the nutrition goal
Read the nutrition goal Tamr keeps for the signed-in diner: cutting, maintain or bulking, per meal.
GET
/api/v1/goalClient APIThe goal Tamr keeps for the session's diner across visits, per meal. canSet is false for a guest's session or a test key's.
canSet is false for a guest's session or a test key's: Tamr keeps no goal for it, and PUT answers identity_required.
Authentication
Client API. Send your publishable key in x-tamr-key and the diner's session in x-tamr-session, from Start a session. For a guest's session, also send its device id in x-tamr-device. A browser may call it only from an origin listed on the key.
Headers
| Name | Type | Required | Description |
|---|---|---|---|
x-tamr-device | string | No | Guest sessions only: the device id the session was exchanged with. Matches ^[A-Za-z0-9_-]{8,128}$. |
x-tamr-app | string | No | Native apps only: the app's iOS bundle id or Android package name. A key used from an app it doesn't list is logged, never refused. Matches ^[A-Za-z][A-Za-z0-9_-]*(\.[A-Za-z0-9_-]+)+$. |
Response
| Field | Type | Description |
|---|---|---|
goal | object or null | |
goal.mode | string | One of cutting, maintain, bulking, other. An open list: read a value you don't know as other. |
goal.kcal | integer | May be absent. Calories for one meal: a ceiling when cutting or maintaining, a floor when bulking. 100 to 3,000. |
goal.proteinGrams | integer | May be absent. Grams of protein for one meal, always a floor. 5 to 300. |
canSet | boolean |
Example
curl https://tamr.link/api/v1/goal \
-H "x-tamr-key: $TAMR_APP_KEY" \
-H "x-tamr-session: $TAMR_SESSION"import { createClient } from "@tamr/api";
const tamr = createClient({ appKey: process.env.TAMR_APP_KEY });
// Sign the diner in first, with a token your backend signed (or a launch code).
await tamr.startSession({ token: dinerToken });
const result = await tamr.goalGet();
console.log(result);import os
import requests
API = "https://tamr.link/api/v1"
headers = {
"x-tamr-key": os.environ["TAMR_APP_KEY"],
"x-tamr-session": os.environ["TAMR_SESSION"], # from POST /api/v1/sdk/session
}
response = requests.get(
f"{API}/goal",
headers=headers,
timeout=30,
)
response.raise_for_status()
print(response.json())Example response
{
"goal": {
"mode": "cutting",
"kcal": 600
},
"canSet": true
}Errors
Every error has the same body; switch on data.code. See Errors and rate limits.
data.code | Status | What to do |
|---|---|---|
app_key_invalid | 401 | The key is wrong, revoked or of another kind. Check it in the dashboard. |
sdk_disabled | 403 | The SDK isn't switched on for this restaurant. Ask Tamr. |
origin_not_allowed | 403 | A browser called from an origin the key doesn't list. Add the origin to the key. |
session_expired | 401 | Start a new session with a fresh token or code, then send the call again once. |
invalid_request | 400 | A field doesn't match the spec. The message says which. |
rate_limited | 429 | Wait retryAfter seconds (also in the Retry-After header), then try again. |