POST /reviews with selected evidence file IDs, the service tags those files with the claim ID and begins a Box Automate workflow. Box Automate assigns the approval task, waits for the decision, then runs the approved or rejected branch.
Clone the working sample
What you are building
By the end of this tutorial, you have a working Python service that:- Exposes a
POST /reviewsendpoint your claims system uses to start a review on selected evidence files. - Writes the claim ID onto each selected evidence file as Box metadata, so the workflow can read it as a variable.
- Looks up the published Automate workflow attached to the claims folder and starts it on the selected files.
- Receives a webhook when the reviewer approves or rejects, and patches
reviewStatuson each file toapprovedorrejected.
TASK_ASSIGNMENT.UPDATED lets your service receive the decision and patch reviewStatus through the Metadata API.Prerequisites
Before you start, make sure you have the following:- A Box Enterprise Advanced account with Box Automate enabled. See Enabling Box Automate.
- A Box platform application configured with Client Credentials Grant authentication. Enable Read and write all files and folders stored in Box and Manage Webhooks. Set application access to App + Enterprise Access, and turn on Generate user access tokens. After you change these settings, re-authorize the app in the Admin Console.
- The user ID of a managed user who can build and start Automate workflows (for testing, use your own user ID). The Automate list and start endpoints return workflows that user can start. They do not return results for the enterprise service account.
- Admin access to create a metadata template, or a Box administrator who can create one for you.
- Permission to build and publish workflows in the Box Automate builder.
- Python 3.11 or higher.
- A coding agent with installed. Run
npx skills add box/box-for-aiin your project, or install the Cursor, Codex, or Claude Code plugin. See for setup.
root_readwrite, the OAuth scope behind Read and write all files and folders stored in Box. Webhook registration requires Manage Webhooks. If a scope or feature is missing from the Developer Console, contact Box Support with the user or app context you plan to use.Configure Box once
These steps happen in the Box Admin Console and Automate builder. An agent cannot do them for you. Complete them before you build the service.-
Create a
Claimmetadata template in the Admin Console under Metadata. Add two text fields: Claim ID and Review status. Select Save, select the template again, then copy the template key. Confirm the generated field keys withGET /2.0/metadata_templates/enterprise/<TEMPLATE_KEY>/schema. This tutorial assumesclaimIdandreviewStatus. -
Configure Client Credentials Grant for a managed user. In Developer Console > your CCG app > Configuration, enable Read and write all files and folders stored in Box and Manage Webhooks. Set application access to App + Enterprise Access, enable Generate user access tokens, and save. Re-authorize the app in the Admin Console. Copy the managed user’s ID (Admin Console > Users & Groups, or
GET /2.0/users/mewith that user’s token). You pass this ID asBOX_USER_IDso the service authenticates as that user, not as the enterprise service account. -
Create a
Claims Reviewfolder in Box as that managed user (or invite them as an Editor), note its folder ID from the URL, and upload two or three sample PDFs. Without folder access for the user your app acts as, file and metadata calls return 404. -
Build and publish a Manual Start workflow in the Box Automate builder. For a full walkthrough of the builder UI, see Creating workflows in Box Automate.
- Open Automate, select New+ → Workflow, and name it
Claims evidence review. - Drag Manual Start onto the canvas and scope it to the
Claims Reviewfolder. - Add a Task Action outcome. Set the type to Approval, assign the file to Trigger: File, and for testing set both complete and manage to Workflow owner. Optionally include the Claim ID metadata field in the task message.
- Branch on Approved and Rejected, and add Send Notification on each branch.
- Select Activate (not only Save).
- Open Automate, select New+ → Workflow, and name it
- Optional: inspect the workflow IDs so you recognize the response shape later. Use an access token for the same managed user your app will act as:
id is the action ID, not the workflow ID. Passing the action ID in the path returns a 404.
Build the service
Choose how to scaffold the service. Both paths produce the same app; continue to Run and verify when you finish.- Build with an agent
- Build by hand
.env; otherwise leave them and fill credentials yourself after scaffolding..env.example to .env and fill in your credentials, user ID, folder ID, and template key. Put each variable on its own line.Run and verify
- Terminal 1 — start the server. Make sure you are in the
claims-evidence-reviewdirectory and the virtual environment is activated:
- Terminal 2 — start a review. Open a new terminal tab or window. Use file IDs from the sample PDFs in
Claims Review, not the folder ID:
-
Confirm in Box:
- Open an evidence file → Metadata tab shows claim
CLM-1042and statusin_review. - As the task assignee, open the approval task and confirm the claim ID appears in the message.
- Approve or reject from the file’s Activity sidebar panel, and confirm the matching branch runs.
- Open an evidence file → Metadata tab shows claim
reviewStatus stays in_review after this step. Continue to Update review status after the decision to patch metadata when the task completes.
Update review status after the decision
The workflow assigns the task and runs the approved or rejected branch, but it does not write back to the file’s metadata. To close the loop, add a that listens forTASK_ASSIGNMENT.UPDATED and patches reviewStatus to approved or rejected.
Add webhook signature keys
- In the Developer Console, open your app and select Webhooks → Manage signature keys. Generate a primary and secondary key.
- Add them to
.env:
Expose the app for webhook delivery
Box must reach your endpoint over HTTPS. For local testing, use a tunnel such as ngrok:https:// forwarding URL. You need it for the registration step.
/webhooks/task-updated. A webhook delivered to a different public URL does not run this handler unless you forward the request or reimplement the metadata patch there.Register the webhook
Runregister_webhook.py once with the public URL of your endpoint. From the project directory with the virtual environment activated:
TASK_ASSIGNMENT.UPDATED. Register the webhook once per environment. If you create it in the Box UI instead, skip the script.
If you create the webhook in the Box UI, set Content Type to Folder, select the Claims Review folder, and select Task Assignment Updated. In this form, content type means the target item type, not the HTTP Content-Type header.
Add the webhook handler
If you used the agent prompt, the handler is already inapp.py. If you built by hand, add the endpoint from step 6 of Build by hand.
The handler:
- Verifies the webhook signature using the SDK’s
WebhooksManager.validate_message. - Reads the decision from
source.resolution_stateand the file ID fromsource.item.id. - Normalizes the decision to
approvedorrejectedand patchesreviewStatuson the file.
source.resolution_state and source.item.id, normalize the decision to lowercase, and call PUT /2.0/files/:id/metadata/enterprise/:templateKey with a JSON Patch replace on /reviewStatus.
Verify the full loop
- Start a review with
POST /reviews. - Open the file’s Metadata tab and confirm that
reviewStatusisin_review. - Approve or reject the task from the file’s Activity sidebar.
- Confirm that the webhook endpoint returns
200. - Refresh the file’s Metadata tab.
reviewStatusnow displaysapprovedorrejected.
Troubleshooting
ModuleNotFoundError: No module named '...'
ModuleNotFoundError: No module named '...'
source .venv/bin/activate from the project directory before running any python3 commands. Each new terminal tab needs its own activation.invalid_client: The client credentials are invalid
invalid_client: The client credentials are invalid
.env file:- Verify
BOX_CLIENT_IDandBOX_CLIENT_SECRETmatch the values in Developer Console > Configuration. - Ensure the app is authorized and its type is Client Credentials Grant.
invalid_grant: Grant credentials are invalid
invalid_grant: Grant credentials are invalid
BOX_USER_ID is the managed user’s ID (digits only, no spaces).Empty entries list from GET /2.0/automate_workflows
Empty entries list from GET /2.0/automate_workflows
- You are authenticated as a managed user who can run Automate, not as the enterprise service account. A user token that returns the workflow while the app returns
entries: []usually means the app still usesenterprise_idinstead ofuser_id. - The workflow is published, not saved as a draft.
- The workflow has a Manual Start trigger.
- The trigger’s folder is the folder whose ID you passed as
folder_id. - The managed user can access that folder.
404 Not Found on an Automate endpoint
404 Not Found on an Automate endpoint
- Box Automate is not enabled for your enterprise. Ask your admin to enable Box Automate.
- Your account is on the Free Developer Plan, where these endpoints are unavailable.
- The
box-version: 2026.0header is missing. - You passed the action ID in the URL path. The path takes
entries[].workflow.id; the body takesentries[].id.
400 Action not found when starting the workflow
400 Action not found when starting the workflow
BOX_USER_ID, then confirm that file_ids contains at least one ID, at most 20 IDs, and that every file is within the Manual Start folder scope.400 Bad Request when starting the workflow
400 Bad Request when starting the workflow
file_ids contains at least one ID, that it holds no more than 20 IDs, and that every file is within the folder scope configured on the Manual Start trigger.The approval task shows no claim ID
The approval task shows no claim ID
tag_evidence match the fields[].key values returned by GET /2.0/metadata_templates/enterprise/:key/schema, and that the task message references the Claim ID field from that template.Workflow not found on folder
Workflow not found on folder
find_workflow_action returned no match for BOX_CLAIMS_WORKFLOW_NAME. Confirm that the published workflow name matches the value in .env exactly. Rename the workflow in the Automate builder and activate it again, or set BOX_CLAIMS_WORKFLOW_NAME to the name shown in the error response. The folder display name is unrelated.403 Forbidden
403 Forbidden
Webhook returns 403 invalid signature
Webhook returns 403 invalid signature
BOX_WEBHOOK_PRIMARY_KEY and BOX_WEBHOOK_SECRET_KEY in .env match the keys shown in the Developer Console under Webhooks → Manage signature keys. If you recently rotated a key, the in-flight delivery may still carry the old signature. See .reviewStatus does not update after approval
reviewStatus does not update after approval
source.resolution_state is approved or rejected and source.item.id is the evidence file ID. Box may send the decision in uppercase in the webhook body. Normalize it to lowercase before you compare or write metadata. If the webhook never arrives, verify that the webhook is registered and that your handler is reachable from the internet. An external processor must call the Metadata API to change reviewStatus.The agent used /2.0/workflows or invented SDK methods
The agent used /2.0/workflows or invented SDK methods
client.make_request with box-version: 2026.0, or select the Build by hand tab in Build the service for the tested modules.Scaling to production
Cache the workflow and action IDs
Cache the workflow and action IDs
GET /2.0/automate_workflows on every review to resolve the workflow by name. That list call is optional in production. The IDs you need are stable for a given published workflow:find_workflow_action. Keep the list lookup as a fallback if start begins failing (for example after you replace the workflow in the builder).Make review starts idempotent
Make review starts idempotent
reviewStatus as a guard: skip the start if the value is already in_review. The webhook handler resets it to approved or rejected after the decision, so the field accurately reflects the current state.Alternatively, catch duplicates in your claims system. For example, ignore a second request with the same claim_id and file_ids while a review is still open. You can also list tasks on the file and skip start if an incomplete approval task already exists.Secure the endpoint
Secure the endpoint
POST /reviews needs authentication in production. Verify a signed request from your claims system, or place the service behind your existing gateway. Keep credentials in a secret manager rather than a .env file, and never expose user or app tokens to a browser client. Prefer a dedicated managed user with the least Automate and folder access your flow needs, rather than a personal admin account.Plan for fields at start
Plan for fields at start
claims_metadata.py makes that a single-module change.Handle more than 20 files
Handle more than 20 files
