Technical Docs
  • Introduction
  • Guides
    • Getting Started
    • Attribution Guidelines
    • Core Concepts
      • Adherence Score
      • Programs, Diets, and Rulesets
      • User Profile
      • Datasets
    • Tutorials and Walkthroughs
      • Creating a Meal Plan
      • Food Log Guide
      • Pagination
      • Executing Multiple Mutations
  • Knowledge Base
    • How-to guides
      • How to add desserts to your meal plan
      • How to log your custom recipe
      • How to generate a Meal Plan based on a template
    • Common errors
      • Meal Plan generation
    • FAQs
      • Getting Started on Suggestic
      • API and Authentication
      • Device Compatibility
      • Meal Plan
      • Nutrition
      • Programs
      • Recipes
  • HELPFUL RESOURCES
    • Deprecated Features
    • Glossary
    • Integrations
      • Building a No-code Meal Planning Application
        • Step 1: Creating the Integromat Scenario and Google Forms Connection
        • Step 2: Creating a User, Generating a Meal Plan, and Retrieving It
        • Step 3: Crafting Our PDF and Connecting PDFMonkey
        • Step 4: Sending The Document to Our User
  • Packages and SDKs
    • Node Package (NPM)
  • GraphQL
    • GraphQL Overview
    • Authentication
    • Calling GraphQL
    • GraphQL Playground
  • Changelog
    • 2025
      • March
      • April
  • Suggestic API Reference
    • Search
      • Food Log
        • Branded Foods Search
        • Common Foods Search
        • My Branded Food Search
        • My Common Foods Search
        • Food Search
        • Legacy
          • Autocomplete
          • Barcode Search
      • Recipe Search
        • Recipe Search
        • Recipe Search by Name or Ingredients
        • Recipe Search by Ingredients
      • Meal Plan Template Search
      • Profile Search
      • Restaurant Search
        • Restaurant Search by Location
        • Restaurant Search
    • Queries
      • Appointments
        • Upcoming Appointments
        • Past Appointments
        • Appointments Types
      • Assessments
        • Assessment Answers
        • Display Assessments
        • Supplement Recommendations
        • User Assessments
      • Content
        • Content Library
        • Content Categories
        • Content Tags
        • Journey
      • Food Log
        • Frequently Logged
        • Food Log Entries
        • Macros Aggregation
        • Micronutrients Aggregation
        • Macro Goals
        • Recently Logged
        • User's Foods and Recipes
          • User's Recipes
        • Legacy
          • Food Log Entries (Legacy)
          • Own Food Items
          • Own Food Item
          • Own Food Item by Id
          • Own Items
          • Own Recipe
          • Own Recipes
      • Lab Tests
        • Biomarker Categories
        • Biomarker Units
        • Biomarker Catalog
        • Biomarkers
        • Biomarker Results
        • Historical Biomarker Results
        • Historical Results by Biomarker
        • Lab Test Reports
        • Recommended Supplements
        • Recommended Articles
      • Meal Plan
        • Meal Plan
        • Custom Meal Plan
        • Simplified Meal Tracking
          • Meal Tracker
        • Meal Plan Config
        • Meal Planner (deprecated)
      • Program
        • All Programs
        • Program Details
      • Recipes
        • Equivalent Recipes (Macros)
        • Equivalent Recipes (Calories)
        • Recipe by Id
        • Recipes By MealTime
        • Recipes By Tag
        • Recipe Swap Options
        • Popular Recipes
        • Favorite Recipes
        • Premium Program Recipes
      • Restaurants
        • Restaurant By Id
        • Menu Items
        • Menu Item By Id
        • Menu Item by Program
        • Recommend Menu Items
      • Restrictions
        • Restrictions
        • Restriction by ID
      • Shopping List
        • Shopping List by Aisle
        • Shopping List by Recipes
      • Subscriptions
        • Subscription List
      • Supplement Plans
        • Supplement plan list
        • Supplement list
      • Tracking
        • Activity and Exercise
        • Checklists
          • Intake Checklist
        • Daily Recap
          • Get Daily Recap
          • Get Daily Recaps
          • Get Daily Recap Questions
          • Get Daily Mood Summary
        • Inisghts
        • Wellness Score
        • Sleep
          • Sleep Time
          • Sleep Quality Score
        • Steps
        • Water and Hydration
        • Heart Rate
        • HRV
        • Weight Tracker
      • USDA Food
      • Users
        • Users
        • User Profile
      • WGPT
        • Assistants
        • Journey
        • Guardrails
    • Mutations
      • Appointments
        • Update Appointment Credits
      • Assessments
        • New User Assessments
        • Set User Answers
      • Content
        • Mark Content as Read
      • Feedback
      • Food Log
        • Log Entries
          • Food Log
            • Add a Food Log Entry
            • Delete a Food Log Entry
          • Meal Log (Legacy)
            • Create Log Entry
            • Update Log Entry
            • Remove Log Entry
        • User's Foods and Recipes
          • Create a User Recipe
          • Create my Branded Food
          • Create my Common Foods
          • Update a User Recipe
          • Delete a User Recipe
          • Legacy: "Own" Recipe
            • Create "Own" Recipe
            • Update "Own" Recipe
            • Remove "Own" Recipe
        • AI Food Log
          • Process Ai Food
        • Legacy (ownFoods and ownRecipes)
          • Create "own" Food Item
          • Update "own Food"
          • Remove "own" Food Item
      • Journey Status
        • Start Journeys
        • Journey Status
        • Toggle Task Completed
      • Lab Tests
        • Add Biomarker
        • Update Biomarker
        • Add Biomarker Result
        • Add Biomarker Category
        • Update Biomarker Category
        • Remove Biomarker Category
        • Add Lab Test Report
        • Delete Lab Test Report
        • Update Lab Test Report
        • Create Recommended Supplement
        • Update Recommended Supplement
        • Remove Recommended Supplement
        • Create Recommended Article
        • Update Recommended Article
        • Remove Recommended Supplement
      • Meal Plan
        • Create Meal Plan Template
          • Custom Options
          • From Days
          • From Scratch
        • Assign a Meal Plan Template to a User
        • Generate Simple Meal Plan
        • Generate Meal Plan
        • Start Over Meal Plan
        • Swap Meals
        • Simplified Meal Tracking
          • Create a Meal Tracker Entry
        • Remove Meal Plan
        • Remove Meal Plan Recipe
      • Recipes
        • Add new recipe
        • Add Favorite Recipe
      • Shopping List
        • Add Multiple Recipes to the Shopping List
        • Add a Recipe to the Shopping List
        • Bulk Check/Uncheck Items
        • Check/Uncheck an Item
        • Clear Checked Items
        • Clear Shopping List
        • Remove Recipe
        • Update Serving Number
      • Subscriptions
        • Update Subscription
      • Supplement Plans
        • Create supplement plan for user
        • Update user supplement plan
        • Add Supplement
        • Update Supplement
      • Tracking
        • Activity and Exercise
          • Add Exercise Entry
          • Delete Exercise Entry
        • Checklists
          • Create my Checklist Item
          • Delete my Checklist Item
        • Daily Recap
          • Create a daily recap question
          • Select Daily Recap Questions
          • Delete a Daily Recap Question
        • Sleep
          • Add Sleep Time
          • Add Sleep Quality Score
        • Steps
          • Add Steps Count
          • Delete Steps Count
        • Heart Rate
          • Add Heart Rate
          • Delete Heart Rate
        • HRV
          • Add HRV
          • Delete HRV
        • Water and Hydration
        • Weight
          • Add Weight Entry
          • Remove Weight Entry
        • User Tracker Goals
          • Create User Goal
          • Update User Goal
          • Remove User Goal
      • Users
        • Authenticate using a Magic Link
        • Create User
        • Custom Attributes
        • Delete a User Account
        • Login User
        • Merge User Accounts
        • Request Reset Password
        • Reset Password
        • Request Password Reset email
        • Sensitive Profile Attributes
        • Update Profile
        • Update User's Program
        • User's Restrictions
        • Update Meal Plan Settings
        • User's Goals
        • Legacy User Mutations
          • Legacy | User's Biomarkers
          • User's Meal Plan Settings (deprecated)
      • WGPT
        • Add user to journey
  • Objects
    • Appointments
      • Appointment
      • Appointment Type
      • Appointment Credit
      • Attendee
      • Coach
    • Common
      • User
      • Adherence
      • Aisle Name
      • CPC
      • CPCIngredientGroup
      • Meal Times
      • Menu Item
      • Own Serving
      • Own Nutrients
      • MacroNutrientsRangeInput
      • Range
      • Tracker
      • Restaurant
    • Food Logs
      • Food Filter
      • Ingredient Amount
      • Ingredients
      • Own Recipe Ingredient
      • Meal Type
      • Nutrients
        • Nutrient Enum
      • Portions
      • Servings
      • AI Food Log
        • Food Analysis
    • Meal Plan
      • Debug Meal Plan Conditions
      • Meal
      • Meal Plan Day
      • Maximum Time per Meal
      • Maximum Ingredient Count
      • Meal Plan Template
      • Simple Meal Plan Filters
    • Recipe
      • Recipe
        • Tags
        • Cuisines
      • Recipe Swap Options
      • Parsed Ingredient Lines
      • Nutritional Info
      • Nutrients Per Serving
      • Calories Per Serving
      • Relative Calories
      • Source
      • Ingredients
      • Units of Measurement
    • Lab Tests
      • Article
      • Biomarker
    • Supplement
    • Assessments
      • Question
      • Answer
    • Content
      • Content Library
      • Content Categories
      • Content Tag
    • WGPT
      • Journey
      • dayJourney
      • Interaction
  • Case Studies
    • Reverse Health Case Study
Powered by GitBook
On this page
  • JWT Authentication
  • How to use a Bearer Authentication within graphQL
  • cURL Request with Bearer token
  • Refresh Token
  • Using JWT without a user's password
  • API Token Authentication
  • Clients/Partners API Token
  • Examples

Was this helpful?

  1. GraphQL

Authentication

Suggestic supported authentication methods

Our GraphQL API currently supports two authentication methods that you can use depending on your case and needs JWT Authentication and API Token Authentication.

JWT Authentication

Use JWT to implement the client-side authentication system only

This method requires a valid user and password and returns a JWT that can be used to consume the GraphQL API.

POST https://production.suggestic.com/api/v1/login

Request Body

Name
Type
Description

email

string

User email

password

string

User password

{
    "email": "test@suggestic.com",
    "name": "Ernesto",
    "phone": "",
    "user_id": "4e9fb96d-3291-aa43-92f1-8226408eb0ac",
    "is_premium": true,
    "birthdate": "1984-03-10",
    "avatar": "https://sg-data.storage.googleapis.com:443/4e9fb96d-3291-4f5e-92f1-8226408eb0ac/avatar",
    "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjasdfadfa311CI6IjIwMTcwMTA5MTYzMSJ9.DIAAit7QDBBvoluIYp6lt-jC3cfEOgZ3sThEu0j_T7A",
    "hashed_email": "790cd2c93f39629asdf2234s761de119b13fc2614f3998cb023cfd",
    "program_id": "46477417-dc4e-425c-b3a9-f2bc9b129102",
    "show_program_view": true,
    "transaction_provider": "",
    "transaction_duration": "",
    "transaction_price": 0,
    "profile_id": "7708db196-27a0-4aa2-999e-1e68203a83udd"
}
{
    "detail": "Incorrect username/password"
}

Once this request is sent, the following information is displayed:

{
    "email": "lizalina@gmail.com",
    "name": "lili",
    "phone": "",
    "user_id": "<user_id>",
    "is_premium": false,
    "birthdate": null,
    "avatar": null,
    "token": "<token>",
    "refresh_token": "<refresh_token>",
    "hashed_email": "59184e9bf7b070d500629ae7410aa1bce18ef6bf98655af15dbadadb58e1f137",
    "program_id": "<program_id>",
    "show_program_view": true,
    "transaction_provider": "",
    "transaction_duration": "",
    "transaction_price": 0,
    "profile_id": "<profile_id>"
}

How to use a Bearer Authentication within graphQL

{
  "Authorization": "Bearer <insert_your_token_here>"
}

When a JWT authentication is used in GraphQL, it is not required to add the sg-user header.

For example:

The following query retrieves the information of a meal plan by giving the bearer token

cURL Request with Bearer token

The bearer token is sent to the server with the 'Authorization: Bearer {token}' authorization header.

In the following example, we are getting the shopping list request.

curl -XPOST 'https://production.suggestic.com/graphql' \
  -H 'Authorization: Bearer <insert_your_bearer_token_here>' \
  -H 'Content-Type: application/json' \
  --data-raw '{"query":"{\n  shoppingList { edges {node {ingredientLine quantity aisleName recipeName isDone unit  databaseId  errors   }  }  }}"}'

Refresh Token

For security purposes, the access token expires after 2 hours. Once expired, your client applications may use a refresh token to “refresh” the access token.

You may obtain a refresh token using the login mutation.

mutation {
  login(userId: "<USERID>") {
    refreshToken
  }
}

Using JWT without a user's password

mutation {
  login(userId: "<USERID>") {
    accessToken
  }
}

In this case, you can expect your authentication flow to be as follows:

  • Authenticate the user on your frontend with your implementation.

  • Request a JWT on your backend, on behalf of the user, via a request to the Suggestic API using your API key and the user’s ID.

  • Pass the JWT to your frontend.

  • The frontend then uses that JWT for all future Suggestic API calls.

API Token Authentication

Use the API authorization token provided on server-side applications only

Use this authentication method to access the API "on behalf" of your users.

To use this method, you require a valid API token and a user id. Add these to a custom HTTP Header, as shown below.

POST https://production.suggestic.com/graphql

Important: if you are using a production API key, make sure you call the production environment on http://production.suggestic.com/graphql

Headers

Name
Type
Description

sg-user

string

User UUID Eg. value: `ffffe9fa-3b49-4050-80d1-06129a722d0b`

Authorization

string

A valid token Eg. value: `Token 7b9f6fd852faba099be1984c97124b7f8d776f26`

{
  "data": { ... },
  "errors": [ ... ]
}

Do not use your API token on client-side authentication. If so, please request a new token.

Clients/Partners API Token

Partners/clients which have an isolated database will need to authenticate by using a different HTTP header named Suggestic-Partner. Use it as it is explained below:

{
  "Authorization": "Token <TOKEN>",
  "Suggestic-Partner":"<PARTNER-SLUG>"
}

Examples

cURL Example

To query GraphQL using cURL, make a POST request with a JSON payload. The payload must contain a string called query:

curl 'https://staging.suggestic.com/graphql' -XPOST \
-H 'Content-Type: application/json' \
-H 'Authorization: Token 7b9f6fd852faba099be1984c97124b7f8d776f26' \
-H 'sg-user: e084268c-5487-4f35-9d74-9ce41de3992b' \
-d '{"query": "{ myProfile { id programName } }"}'
{
  "data": {
    "myProfile": {
      "id": "e084268c-5487-4f35-9d74-9ce41de3992b",
      "programName": "Anti-Inflammatory Diet"
    }
  }
}

Note: The string value of "query" must escape newline characters, or the schema will not parse it correctly. For the POST body, use outer double quotes and escaped inner double quotes.

If you need to use your partner/client header, use the following cURL

curl -XPOST 'https://production.suggestic.com/graphql' \
-H 'Authorization: Token <API-Token>' \
-H 'SG-User: <user-id>' \
-H 'Suggestic-Partner: <PARTNER-SLUG>' \
-H 'Content-Type: application/json' \

Python Example

import requests

# HTTP Headers including sg-user for especific user context
headers = {
    "Authorization": "Token 7b9f6fd852faba099be1984c97124b7f8d776f26",
    "sg-user": "e084268c-5487-4f35-9d74-9ce41de3992b"
}
# GraphQL query
query = """{ myProfile { id programName } }"""

# Make request
r = requests.post(
    "https://staging.suggestic.com/graphql",
    headers=headers,
    json={"query": query}
)

# print json response
print(r.json())

If you need to use your partner/client header, replace sg-user with the Suggestic-Partner information

PreviousGraphQL OverviewNextCalling GraphQL

Last updated 1 year ago

Was this helpful?

Once you log in, open your ; in the authentication section, add the following header

If you are not using Suggestic as your identity provider, you can still obtain a JWT from the API using the login mutation. This should be done from your backend using the standard

Grapqhl Playground
API token authentication.