Sync a Questionnaire
Forward sync fetches a published questionnaire from the Strapi API and generates a TypeScript file that the React app imports.
Command
Section titled “Command”yarn sync:questionnaire [options]| Flag | Long form | Type | Default | Description |
|---|---|---|---|---|
-q |
--questionnaireSlug |
string | – | Sync only one questionnaire by its slug |
-t |
--questionnaireType |
enum | all |
Filter by type: signup, claim, adjustPolicy, cancelPolicy, all |
-d |
--dir |
string | src/syncedData/questionnaires |
Output directory for generated files |
-s |
--source |
enum | – | Source environment: prod, staging, dev. Falls back to REACT_APP_STRAPI_URL / REACT_APP_STRAPI_TOKEN env vars when omitted. |
Examples
Section titled “Examples”Sync a single questionnaire by slug and type:
yarn sync:questionnaire -q household -t signupSync all questionnaires from production:
yarn sync:questionnaire -s prodSync only claim questionnaires from staging:
yarn sync:questionnaire -t claim -s stagingSync to a custom output directory:
yarn sync:questionnaire -q household -d src/custom/outputWhat happens
Section titled “What happens”- The script calls the Strapi API to fetch the published version of the questionnaire
- Strapi’s service layer transforms the data into canonical format (flattened questions, simplified rules)
- The script wraps all translatable strings with
t()function calls for i18n - The output is linted automatically
- The generated file is written to:
apps/app/src/syncedData/questionnaires/<slug>.tsFiles are placed in subdirectories by type: claims/, adjustPolicy/, cancelPolicy/, or dependents/ for dependent variants. Signup questionnaires land at the root of the output directory.
After syncing
Section titled “After syncing”- Open the generated file and review it
- Verify questions, rules, and screen text look correct
- Commit the file and open a PR
- The change goes through normal code review and deployment
Troubleshooting
Section titled “Troubleshooting”| Issue | Cause | Fix |
|---|---|---|
| “Failed to fetch questionnaire” | Strapi URL or token misconfigured | Check REACT_APP_STRAPI_URL and REACT_APP_STRAPI_TOKEN env vars, or pass --source to use named credentials |
| “No questionnaires found” (empty output) | Slug typo or questionnaire not published | Verify the slug spelling matches Strapi and ensure the questionnaire is published |
| “Permission denied” or 401/403 | API token lacks read access | Check that the Strapi API token has read permissions for the questionnaire content type |
| File not generated | Output directory does not exist or wrong path | Verify the target directory exists; use -d to specify a valid path |
| “Questionnaire not found” | Slug does not match or not published | Check the name field in Strapi, ensure it is published |
See also
Section titled “See also”- Sync Commands Reference – full CLI reference with all flags and options
- Syncing and Previewing – end-to-end tutorial for the sync workflow
- Strapi Transform Pipeline – how data is reshaped during sync | Missing questions | Questions added but not saved | Save the questionnaire in Strapi | | Stale data | Cached API response | Re-run the sync command |