Skip to main content
Students look for answers across admissions guides, housing policies, and academic calendars owned by different offices. In this tutorial, a script turns each student service’s documentation folder into a Box Hub with Box AI enabled, plus one campus-wide hub, and grants students access. A small portal then embeds Box AI Chat: a focused chat on each service page and an Ask the campus button on the home page. The portal lists each hub’s sources with the Hubs API, so items that content owners add to a hub display in the portal without code changes. If you need a single hub, you do not need code: copy the embed code from the Box web app as described in . This tutorial is for when you manage several hubs and want them in one portal. It extends the blog post .

Before you start

Complete these setup steps before you build. You need:
  • A , or a with Box Hubs and Box AI for Hubs enabled. See .
  • A Box application configured with Client Credentials Grant authentication, authorized in the Admin Console, with these scopes:
    • Read and write all files and folders stored in Box
    • Manage users - required for the seed script to find your test student by email
    • Manage groups - required for the provisioning script to invite the students group to the service folders
  • If you use a seed script, the app’s App Access Level set to App + Enterprise Access on the Configuration tab. With the default App Access Only, the app cannot see the users in your enterprise, so the seed script cannot find your test student. After you change the access level, an admin must re-authorize the app in the Admin Console.
  • A runtime for the stack you choose: Python 3.11+ for Build by hand. Build with an agent also supports Node.js 20+, Java 17+, and .NET 8+.
  • If you build with an agent, a coding agent such as Codex, Claude Code, or Cursor. Installing helps it use current Box APIs.
Every student who uses the portal needs a Box account in your enterprise, which is the Box account that owns your application, whether it is a free developer account or a Box Enterprise account. Students must also be signed in to Box in the same browser. The embedded chat runs with the student’s own Box session, so it never answers from content the student cannot open in Box. Keep the service folder IDs, students group ID, hub admin email, and enterprise ID handy. The prompt and your configuration files need them.
To try the portal with sample content, skip the steps below and use a seed script. The includes seed.py, Build by hand explains how to write it, and the agent path builds one for your stack. As your application’s service account, the seed script creates the Admissions and Housing folders with fictional documents, creates the Students group with one test student, and writes the folder and group IDs to your configuration. You still need the hub admin email and the login email of a test student, a Box user in your enterprise who is not an admin. Use the steps below when you work with your offices’ real folders.
Each student service gets a folder. Each folder becomes the content of that service’s hub, and all folders together feed the campus-wide hub. Box AI answers only from the files in them, so keep them limited to approved, current documentation.
  1. In Box, create 2 folders: Admissions and Housing.
  2. Upload each office’s documents, such as application deadlines and requirements to Admissions, and residence hall guides and move-in dates to Housing.
  3. Note each folder ID from the URL. For example, if the URL is https://app.box.com/folder/123456789, the folder ID is 123456789.
  4. Share both folders with your application’s service account. This is required because Client Credentials Grant applications act as a separate service account user that does not automatically have access to your content.
Without this step, the script fails with 404 “Not found” errors.To find your service account email: go to the Developer Console, open your app, select the Configuration tab, and look in the App Details sidebar for the Service Account ID (it looks like AutomationUser_xxxxx_xxxxxx@boxdevedition.com).Invite this email as a collaborator on each folder with the Editor role. Editor access is required because the script invites the students group to the folders.
A Box group controls who can use the portal’s chat from one place. When a student joins or leaves, you change the group membership and nothing else.
This step requires Admin access. If you do not have access, contact your Box administrator.
  1. Open the Box Admin Console, select Users & Groups, and then select the Groups tab.
  2. Create a group called Students and add the students who use the portal. For testing, add one Box user who is not an admin.
  3. Find the group ID. Copy the numbers that display as part of the URL, or, with a developer token from the Developer Console, call the endpoint and copy the id of the group:
The script creates the hubs as your application’s service account, so the hubs belong to the service account. The service account can then read the hubs for the portal without extra setup. So that a person can manage the hubs in the Box web app, the script also adds one Box user as a co-owner of every hub.Choose the Box user who maintains student-facing content, and note their Box login email.

Build with an agent

Besides the provisioning script and the portal, the agent builds a seed script that creates the service folders with sample documents and the students group. You do not need to create them in Box first. Gather these values:
  • Enterprise ID - from the Developer Console, using the icon in the top-right
  • Hub admin email - the Box login of the person who manages the hubs
  • Test student email - the Box login of a user in your enterprise who is not an admin, for testing the portal
Choose your stack and copy the prompt. It lists these values as prerequisites, so the agent reads them from environment variables instead of trying to create them. Replace the <ENTERPRISE_ID>, <ADMIN_EMAIL>, and <STUDENT_EMAIL> placeholders if you want the agent to pre-fill the configuration. Otherwise, leave them and fill in the files yourself after scaffolding. Leave <ADMISSIONS_FOLDER_ID> and <HOUSING_FOLDER_ID> as they are. The seed script replaces them.
Python + Flask

Review generated code before using it in production. Never paste Box credentials into your coding agent.

When the agent finishes, copy .env.example to .env and fill in your client ID, client secret, enterprise ID, hub admin email, and test student email. Then run the seed script with the command in the generated README. It writes the folder IDs to hubs.config.json and the students group ID to .env. To use your offices’ real folders and group instead, complete Before you start, skip the seed script, add your folder IDs to hubs.config.json, and set the students group ID in .env. Then skip ahead to Run and verify. Prefer to write the code yourself? See Build by hand below.

Build by hand

Use this path if you prefer to write the code yourself, or if you need a reference when the agent drifts. Complete Before you start first, then follow the steps in order. The code is in Python. For other languages, use the agent path. You can also clone a working sample if you prefer to start from running code:

Python working sample

Clone the provisioning script and Flask portal, add your Box credentials, and run seed.py to create sample folders, documents, and the students group.
  1. Open your terminal and create a new project directory:
  1. Create a virtual environment and install the dependencies:
After activation, your terminal prompt displays (.venv) at the beginning. Every time you open a new terminal window or tab, re-activate the virtual environment with source .venv/bin/activate from the project directory. If you see ModuleNotFoundError, the venv is usually not activated.
  1. Create a .env file to store your configuration, then add the following content. Replace the placeholder values with your own:
If you use the seed script in step 4, leave STUDENTS_GROUP_ID empty. The script fills it in. Set TEST_STUDENT_LOGIN to the login of a Box user in your enterprise who is not an admin. Only the seed script uses it. If your enterprise uses a custom Box domain, such as yourcompany.app.box.com, set BOX_EMBED_DOMAIN to it. BOX_CHAT_BUTTON_SCRIPT is the URL of the Box-hosted script for the chat button. To check for a newer version, open any hub in the Box web app, open the menu in the top-right corner, select Embed, and on the Hub AI Chat tab, select Chat button. The src value of the script tag is the current URL.
Never commit .env files to version control. Add .env to your .gitignore.
  1. Create hubs.config.json. It describes every hub the portal uses: one per student service and one campus-wide hub that combines all service folders. Replace the folder ID placeholders with your own. If you use the seed script in step 4, leave the placeholders. The script replaces them:
To add a student service later, you add an entry here and run the provisioning script again.
Create the Box client module in your project directory:
box_client.py
Client Credentials Grant is recommended for server-to-server automations where no end user is present. For other authentication options, see the .
Create the hub module. It lists hub items, creates or reuses a hub, turns on Box AI, adds folders that are not in the hub yet, and grants access. After a hub exists, configure_hub adds its folders and grants access to it:
hubs.py
Adding a folder to a hub indexes every file inside it, including subfolders. When content owners add or update files in the folder, the hub picks up the changes, so you do not need to re-run the script for content updates.
Hub access does not replace file permissions. If students can open the hub but not the files in it, Box AI has nothing to answer from. That is why configure_hub grants the group access to both the hub and its folders.
When a collaboration already exists, Box returns an error instead of creating a duplicate. The module treats that error as success, and it skips folders that are already in the hub, so you can run it again safely.
Skip this step if you completed Before you start with your offices’ real folders and group. To try the portal with sample content instead, the seed script sets up Box for you as your application’s service account. Because the service account owns the folders it creates, you do not need to share them with it. The script:
  • Creates a folder for each service in hubs.config.json, named after the service’s title, and uploads the documents from sample-docs/<slug>/.
  • Invites the hub admin to each folder as an editor, so they can maintain the content.
  • Creates the Students group and adds one test student.
  • Writes the folder IDs to hubs.config.json and the group ID to .env.
It needs the Manage users scope and App + Enterprise Access to find the test student by the TEST_STUDENT_LOGIN email that you set in .env in step 1.Create a sample-docs folder with an admissions and a housing subfolder, and add a few short documents to each, such as application deadlines and move-in dates. You can also copy the fictional documents from the sample-docs folder of the . Then create the seed script:
seed.py
The script finds existing folders, files, and the group by name, so you can run it again safely. You run it in Run and verify.
Create the provisioning script. It reads hubs.config.json, provisions one hub per service and the campus-wide hub, and saves each hub ID to portal-config.json as soon as the hub exists. On later runs, it reads the IDs from portal-config.json and reuses the same hubs, including after a run that fails partway:
provision_hubs.py
Keep portal-config.json after the first run. If you delete it, the next run creates a new set of hubs instead of reusing the existing ones.
The portal uses both Box AI Chat embedding modes, one on each of these 2 page templates. Create a templates folder in your project directory and add them:
  • Home page: the chat button. A Box-hosted script adds a floating Ask the campus button that opens a chat grounded in the campus-wide hub. Use this mode when the chat is secondary to the page content.
  • Service page: the chat widget. An iframe displays the chat for the service’s hub next to the list of sources. Use this mode when the chat is the main way to use the page.
The chat button script reads its settings from the attributes of its own script tag. data-hub-id is required and selects the hub that the chat answers from. Without it, the chat cannot load. data-custom-box-domain sets your Box domain, and data-button-text sets the button label. The portal fills in these values from portal-config.json and .env.The widget URL includes showCloseButton=true, so the chat displays a close button. When a student selects it, the chat sends a BOX_AI_CHAT_CLOSE message to the page, and the script hides the chat and displays an Open chat button. The script ignores messages that do not come from the chat iframe. It checks the sender instead of the domain because Box can serve the chat from your enterprise’s custom domain, such as yourcompany.app.box.com, even when the iframe points to app.box.com.Neither embed passes a sharedLink parameter, so the chat works only for hub collaborators. For all parameters, see .
Create the portal server. It fills in the page templates with the hub IDs from portal-config.json, and builds each service’s source list from the Hubs API. Sources are cached for 5 minutes so that page views do not call Box every time:
portal.py
The source links open the files and folders in the Box web app, where Box applies the student’s own permissions. The service account reads the hub items for the list, so every student sees the same list.At this point, your project directory should contain the following files:
When you finish scaffolding, continue to Run and verify.

Run and verify

Create the hubs and check them in Box before you start the portal. If the chat works in Box, any problem you hit later is in the portal. The commands below are for Build by hand. If you built with an agent, use the matching commands from the generated README.
  1. Run the seed script, if you created one. Make sure you are in the campus-ai-assistant directory, then run:
    You should see each folder, upload, and the group confirmed:
  2. Run the provisioning script:
  3. Check the output. You should see each hub confirmed, followed by the path of the portal configuration:
    Run the script again. It reuses the hubs from portal-config.json and reports that the folders and collaborators already exist, instead of creating new hubs.
  4. Check the hubs in Box. Sign in to Box as the hub admin, select Hubs in the left sidebar, and open Admissions, Housing, and Campus Assistant. Each hub lists its folders as hub content.
    Wait a few minutes for Box to index the files before you test the chat. A newly created hub might return empty or incomplete answers until indexing finishes.
  5. Start the portal:
  6. Test as a student. In a browser where you are signed in to Box as a member of the students group, open http://localhost:3000. Do not use a private or incognito window, because it does not share your Box session.
    • On the home page, select Ask the campus and ask a question that one of your documents answers, such as “When is the move-in date?”. Confirm that the answer cites the document.
    • Select Admissions. The page lists the Admissions folder under Sources, and the chat answers admissions questions.
    • Select the close button in the chat. The chat hides and Open chat displays. Select Open chat to display the chat again.

Scaling to production

Create and share the service folder as in Before you start, add an entry to hubs.config.json, and run the provisioning script. The script creates the new hub, adds the new folder to the campus-wide hub, and updates portal-config.json. Restart the portal to display the new service.
Neither embed uses a shared link, so only hub collaborators can use the chat. To give a student access, add them to the Students group in Box. To remove access, remove them from the group. You do not need to change the portal or re-run the script.
Box AI answers only from the files in the service folders. Keep drafts and outdated versions out of them. To review new content before it reaches a hub, see the tutorial.
Before you deploy, run the portal on a production server instead of the development server, serve it over HTTPS, and store the values from .env in your hosting platform’s secrets manager. Keep portal-config.json with the deployment so the portal uses the same hubs.
The same approach works for any portal that groups knowledge by team, such as an employee intranet with one hub per department or a partner portal with one hub per product line.

Troubleshooting

Your Python virtual environment is not activated. Run source .venv/bin/activate from the project directory before running any python3 commands. Each new terminal tab needs its own activation.
Check your .env file:
  • Verify BOX_CLIENT_ID and BOX_CLIENT_SECRET match the values in Developer Console > Configuration.
  • Confirm BOX_ENTERPRISE_ID is your enterprise ID (found in Admin Console > Account & Billing, or Developer Console > icon in the top-right > Copy Enterprise ID).
  • Ensure your app is authorized in the Admin Console.
  • Make sure the app type is Client Credentials Grant.
The service account does not have access to a service folder. Invite the service account email (found in Developer Console > your app > Configuration > App Details sidebar) as a collaborator with the Editor role on every folder in hubs.config.json.
If the script adds the folders but fails with 404 not_found when it adds the students group to a hub, check that STUDENTS_GROUP_ID is the id from the list groups response. If the error persists, contact with the box-request-id value from the error response.As a temporary workaround, invite each member of the group to the hubs as a viewer instead. In Python, add these functions to hubs.py after add_hub_collaborator. When Box returns not_found for the group, add_hub_group_viewer invites each member of the group:
hubs.py
Then, in configure_hub, replace the add_hub_collaborator call for the group with:
hubs.py
Run the provisioning script again. Students get hub access individually, so when a student joins the group, run the script again to invite them to the hubs. The group still controls access to the service folders.
Your application is missing the Manage groups scope, which the script needs to invite the students group to the service folders. In the Developer Console, enable Manage groups on the Configuration tab, save the changes, and make sure the app is re-authorized. See . Then run the script again. It reuses the hubs it already created.
The portal reads hub IDs from portal-config.json, which the provisioning script writes. Run the provisioning script first, and start the portal from the project directory.
The seed script creates the folders and the students group when you run it. The agent must not create them while it builds the project. Re-paste the prompt with the prerequisites block intact, or follow Build by hand.
If the seed script stops because no user matches the test student login, check the login email in .env. Then, on the Configuration tab of your app in the Developer Console, make sure the Manage users scope is enabled and the App Access Level is App + Enterprise Access. Without either setting, Box returns an empty list of users instead of an error. Save the changes, and re-authorize the app. See . Then run the seed script again. It reuses the folders, files, and group it already created.
  • Make sure BOX_CHAT_BUTTON_SCRIPT in .env contains only the script URL, not the whole script tag. The home page template adds the data-hub-id and data-custom-box-domain attributes.
  • If your enterprise uses a custom Box domain, such as yourcompany.app.box.com, set BOX_EMBED_DOMAIN to it and restart the portal.
  • If the chat displays “Oops! We can’t seem to find what you’re looking for”, the browser is not signed in to Box as a hub collaborator. Confirm that the student is signed in to Box in the same browser, not in a private or incognito window, and is a member of the students group. Without a shared link, the chat loads only for hub collaborators.
  • Wait a few minutes after creating the hubs. Indexing is not instantaneous.
  • Confirm the student is a member of the students group, and that the group has access to the folders as well as the hubs.
  • Make sure your documents contain text. Scanned PDFs without OCR are not searchable.

Next steps

Build your company brain

Review new content with Box AI before you publish it to a hub.

Box Embed

See every embed option for hubs, folders, files, and Hubs AI Chat.
Last modified on November 27, 2026