Migrating from the Entity Service to the Document Service API

If your Strapi v4 project has custom controllers, services or scripts that call the Entity Service, this page explains what the Strapi 5 Document Service changes, what the codemods handle, and what your team must rewrite by hand.

On this page

Why Entity Service calls break in Strapi 5 and where the Document Service fits

If your Strapi v4 project has custom back-end code that calls the Entity Service, those calls must move to the Document Service API before or as part of the move to Strapi 5. Strapi 5 replaces the Entity Service API with the Document Service API, so controllers, services, lifecycle code and scripts that call strapi.entityService will not carry over as written. The rewrite is a back-end task. Front-end response changes are a separate piece of work, covered in the sibling sections on REST and GraphQL clients.

The timing matters. Strapi v4 reached end of life on April 30, 2026, and its final release, 4.26.2 of June 9, 2026, will receive no further updates. Any v4 project that stays where it is will run without fixes for security issues and bugs. The supported route is the v4 to v5 migration documented by Strapi: the upgrade tool with codemods, the breaking changes list, and data migration scripts that run on the first start of Strapi 5. Strapi's docs say to back up the database first, because downgrading is not supported. Confirm the current version of the migration guide before you plan, since the docs change with each release.

Start by inventorying your Entity Service calls. Search the codebase for strapi.entityService, entityService.findMany, findOne, create, update and delete, and list every custom route, controller, service, policy, middleware and lifecycle subscriber that uses them. For each call, record the content type, whether it reads drafts or published entries, whether it touches relations or components, and whether it depends on the v4 response shape. These are the facts that decide how much work each call needs. Ask your team which of these calls run in scheduled jobs or import scripts, because those paths are easy to miss in a code review and will fail only when they run.

Decide early whether the rewrite happens on the v4 codebase before the upgrade or on the v5 codebase after it. Rewriting first lets you test the Document Service calls on a v4 copy, but the codemods then have to run over code you have already changed. Rewriting after the upgrade keeps the migration steps in order, but it means the first run of the Strapi 5 project exercises code that is not yet updated. Whichever order you choose, run the upgrade on a copy of the production database, record every error and confirm with your platform team which environment will be used to test the data migration.

Which Entity Service changes affect your code

This table compares the main Strapi 5 changes that affect Strapi v4 back-end code, with the impact on each change and the action your team needs to take. Read it as a checklist: find each change that touches your services, controllers and lifecycle code, then confirm exact method signatures and return shapes against the breaking changes list and migration docs. The main takeaway is that the Entity Service calls and the v4 response shape are the places where most rewrite work concentrates.

ChangeImpact on back-end codeAction needed
Entity Service replaced by Document ServiceCalls to strapi.entityService and related Entity Service methods no longer map one-to-one onto the new APIFind every Entity Service call and map it to its Document Service equivalent, then confirm the method signature in the migration docs
documentId identifierCode that reads or writes the numeric id as the record identity may point at the wrong entry or a draft versionDecide which identifier each query uses, and update lookups, relations and stored references to documentId where needed
Array results from Document Service queriesCode that expects a single object or a particular wrapper may fail when results come back as arraysCheck each call's return shape against the breaking changes list and update destructuring and null checks
Draft and publish methodsPublishing, unpublishing and draft handling calls differ from the v4 flow and may behave differently in lifecycle codeRewrite publish and draft logic, then test each status transition in a staging copy
Changed API response formatCustom controllers and services that shape or consume responses may return a different structure than v4 clients expectReview custom responses, then use the Strapi-Response-Format: v4 header during migration if front ends still depend on the old shape
Strapi-Response-Format: v4 headerGives temporary backward compatibility for responses while clients are updated, but is not a permanent fixTrack which clients still send or rely on the header, and plan its removal once each client is updated
Upgrade tool codemodsCodemods rewrite many common patterns, but they do not cover every custom service or queryRun the codemods on a branch, review each diff, and list the remaining manual changes before testing
Breaking changes listLists the removed, renamed and changed behaviors that apply to your Strapi versionRead the list for your target version and check each item against your code, plugins and custom routes

What the upgrade tool's codemods rewrite automatically

The Strapi upgrade tool runs codemods that rewrite parts of a v4 project for Strapi 5, and they handle some of the mechanical Entity Service to Document Service changes. Treat that output as a first draft. The Strapi migration documentation describes the tool as covering a set of known patterns, so the work that remains falls to your team: custom controllers, services, scripts and anything that calls strapi.entityService directly may be partly rewritten, partly left alone, or changed in ways that still compile but behave differently. Confirm the exact patterns the current tool version covers against the Strapi v4 to v5 migration introduction and FAQ before you plan the review.

Run the tool on a dedicated branch cut from the v4 code that matches the production release, never on the main branch. Commit before running it so every change is isolated in one diff. Then read every changed line in custom code, not only the files that fail to build. Silent changes are the risk: a call that still returns a value but now returns an array, or a lookup that still runs but filters on id where it should filter on documentId, will pass a build and fail in production. Pay particular attention to code that reads id from one call and passes it to another, and to any place where a response shape is assumed by a front end or a webhook consumer.

Codemods change code, but the data migration scripts run only when Strapi 5 starts for the first time against your database. That means a code change you accept and a data change Strapi makes on boot meet at the same moment, and a bad combination surfaces only then. Before the first start on a copy of production, confirm that your rewritten services and your scripts agree on which identifier and which status they expect, and keep the pre-upgrade database backup, since the docs state downgrading is not supported. Ask your team to document which custom code paths were rewritten, which were rewritten by hand, and which were deliberately left unchanged so the record is reviewable later.

Which back-end patterns need manual rewriting

The upgrade tool rewrites many calls mechanically, but the patterns below depend on how your own code uses entity IDs, results and publication state. They share one root cause: Strapi 5 identifies content by documentId and returns results as documents, so code that assumed one numeric row per entity needs a deliberate review.

Controllers and services that pass entity IDs

Custom controllers and services often receive a numeric ID from a route or request body and hand it straight to strapi.entityService or a similar call. In Strapi 5, the equivalent lookup uses documentId through the Document Service. Confirm every route parameter, service argument and webhook payload that carries an ID, and decide whether it should become a documentId or be resolved from one. Inspect each place where an ID is stored or returned to a caller.

Migration FAQ

Numeric ID used as the public key

Front-end paths, cache keys, search indexes and third-party sync jobs may treat the numeric id as the stable identifier for an entry. In Strapi 5 the id is an internal database value tied to a version of the document, while documentId identifies the content across drafts and published versions. Search the codebase and integrations for .id, /:id routes and foreign keys that point at entries, then decide which identifier each one should use.

Array results where one entry was expected

Code that reads result.data as a single object can break when the Document Service returns an array for a query or a list call. Find each call that previously returned one entity, check the response shape it now produces, and add explicit handling for empty results and multiple results. Pay attention to helper functions that were shared across endpoints, because one change can affect several callers.

Publication state logic

Custom code that sets publishedAt directly, or reads it to decide whether content is live, relied on the v4 draft and publish model. Strapi 5 uses a status concept and dedicated publish and unpublish methods on the Document Service. Confirm every filter, update and conditional that touches publishedAt, and test draft and published reads separately, since the same documentId can have both states.

Lifecycle hooks tied to the old entity flow

Database lifecycle hooks such as beforeCreate and afterUpdate that send emails, sync data or set fields may fire at different points or with different arguments under Strapi 5. Document Service middlewares are the newer place for this logic. List every hook in the project, record what each one does on create, update, publish and delete, and test each action in a staging copy before you move the logic.

Custom queries built on the Entity Service

Raw database queries, db.query calls and custom filters written against v4 tables or the Entity Service can return different columns, joins or identifiers after the migration. Confirm which custom queries read the id column, which join through link tables, and which expect draft rows. Rewrite them against the Document Service where possible, and check each result against expected output on a copy of the production database.

How to move Entity Service code to the Document Service

This sequence takes Strapi v4 back-end code from Entity Service calls to the Document Service API on a copy of the project first, so the team knows what changed, what still needs hand work, and how to return to a known state if the data migration fails.

  1. Inventory every Entity Service call

    Search the whole back-end codebase for strapi.entityService, strapi.query calls that touch content types, controllers, services, lifecycle hooks, policies, middlewares, custom routes and any plugin code you have written or forked. Record each call with its file, content type and purpose, and note which calls read drafts, publish or unpublish, or depend on numeric id values. Include tests and seed scripts in the list. The output is a written inventory that the developer and reviewer both sign off, so nothing relies on memory when the rewrite starts.

  2. Back up the database before any upgrade step

    Take a full, restorable backup of the production database and the uploads storage, then confirm the backup can be restored into a separate environment. Strapi's migration documentation says to back up the database first because downgrading is not supported, so this backup is the only rollback point once Strapi 5 starts on real data. Record the backup identifier, time, database version and the code commit that matches it. Done means a test restore has succeeded on a separate host.

  3. Run the upgrade tool on a copy

    Create a copy of the project and its database on a separate environment, then run the Strapi v4 to v5 upgrade tool against the copy. Keep the copy's code under version control on a separate branch so every automated change is visible as a diff. Do not start Strapi 5 against the production database at this stage. The checkpoint is a working branch with the tool's output committed, and a list of anything the tool reported but did not change.

  4. Review the codemod changes line by line

    Read the diff produced by the codemods against the inventory from the first step. Confirm that calls the codemods rewrote now use the Document Service with documentId where the code needs a stable identifier, and check that results are handled as arrays or single documents as the new API returns them. Flag any rewrite that changes filtering, population or status behavior, because codemods do not verify business logic. The checkpoint is a reviewed list where each inventory item is marked as changed, unchanged, or pending manual work.

  5. Rewrite remaining calls to the Document Service

    Work through every item still marked pending. Replace Entity Service calls with Document Service methods, use documentId for lookups and updates, and remove code that assumes numeric id values are the public identifier. Where a route or service returned the v4 shape, decide whether the response change belongs in the back end or in the front end, and record that decision. Keep each change small enough to review on its own. The checkpoint is a compiling project where the inventory has no unresolved entries.

  6. Update draft and publish logic

    Find every place that reads or sets publication state, including custom controllers, lifecycle hooks, scheduled jobs and any code that calls publish or unpublish. Rewrite that logic to use the Document Service draft and publish methods, and confirm that the status field is used where your code previously checked publication state. Test the behavior with a draft entry, a published entry and an entry that has both a draft and a published version. The checkpoint is a test matrix where each state returns the expected result.

  7. Run tests and a staging data migration

    Run the full automated test suite on the rewritten code, then start Strapi 5 against a restored copy of production data so the data migration scripts run on first start. Compare content counts, relations, media links and a sample of published and draft entries against the pre-upgrade backup, and repeat the check for any locales you use. Record every difference and fix it before the next step. The checkpoint is a staging run where the data migration completes and the comparison has no unexplained differences.

  8. Promote only after a verified rollback point

    Before the first Strapi 5 start on real data, confirm that the pre-upgrade backup from the second step is still restorable, that the matching v4 code commit is tagged, and that the team knows who will make the restore decision and how. Then promote the reviewed code and run the upgrade on production during an agreed window. Watch the logs and run the smoke tests from the staging list. Done means the production checks match staging, and the backup and code tag are retained until the owner signs off.

Who does what when the rewrite is in-house or outsourced

An in-house rewrite keeps code ownership and day-to-day decisions with your own staff, so the main question is whether the developer who will do the work already knows Strapi 5 internals well enough to judge Document Service behavior. Your team owns every step, including the parts that look administrative, and the most common gap is an inventory that nobody was assigned to finish.

  • Inventory: Your developer lists every strapi.entityService call, custom controller, service, policy, lifecycle hook and plugin that touches content, and records which ones rely on numeric id values.
  • Code rewrite: Your developer applies the codemods from the upgrade tool, then hand-edits the calls the codemods cannot translate, such as logic that depends on array results or on publishedAt state.
  • Test writing: Your team writes tests for draft and publish paths, relations and locale handling before changing behavior, since the existing suite may not cover them.
  • Staging runs: Your team runs the migrated code against a copy of production data and records every error, timing change and response shape difference.
  • Sign-off: Your product owner and an engineer who did not write the change approve the release, with a written record of what was tested.

Check that the developer has time allocated for the inventory and test writing, not only the code changes, and that someone outside the team can review the sign-off record.

Testing the rewrite and planning a rollback

Treat every rewritten service and controller as untested until a test proves it behaves the same way it did under the Entity Service. Write unit or integration tests for each replaced call, covering the cases that changed shape: a lookup by documentId instead of numeric id, array results from findMany, and the draft and published versions returned by status rather than publicationState. Run these tests against a real database engine that matches production, since query behavior differs between PostgreSQL, MySQL and SQLite. Lifecycle behavior needs its own checks: confirm that any hook, email or sync that used to fire on an Entity Service call still fires once, and only once, when the same logic runs through the Document Service. Lifecycle hooks and Document Service middlewares are covered on a sibling page, so use that page for the detail of what to assert.

Before you rely on those tests, run the upgraded code against a staging copy of production data. Compare responses from the v4 and v5 builds for the same requests, using the Strapi-Response-Format: v4 header during the switch if your front ends still expect the old envelope. Diff the outputs for key endpoints, relations, components and localized entries, and record every difference you cannot explain. Confirm with your team which fields are allowed to change before you start, so the diff has a clear pass condition. Check the staging database's row counts and a sample of published and draft entries against the source as well, because the data migration scripts run on first start of Strapi 5 and will change stored data.

Plan the rollback before the production upgrade, not after it fails. Strapi does not support downgrading from Strapi 5 to v4, and the migration docs advise backing up the database first for this reason. Your rollback plan is therefore a restored pre-upgrade database together with the v4 code, deployed from the same version control state you used before the change. Agree who makes the call to roll back, how long the team will wait before deciding, and where the backup is stored and tested. For the full sequence, read the rollback page in this content group, which covers restoring the database and code and the staging and backup steps that reduce the chance of needing it.

What makes the Entity Service rewrite take longer

This table compares the factors that expand or shrink the rewrite of v4 back-end code from the Entity Service to the Document Service API. Read each row against your own codebase to estimate where your team will spend time, then use the check column to scope the audit before quoting work.

DriverEffect on effortWhat to check
Custom controllers, services and scripts calling the Entity ServiceEach call site needs a Document Service equivalent, and each one can change the return shape from a single object to an arraySearch the codebase for entityService calls and count them by file, including seed scripts and cron jobs
Reliance on draft and publish logicPublish, unpublish and draft-version handling changes, so flows that depended on separate draft and published records need redesignList every place code reads publishedAt, publicationState or a draft flag and confirm the intended status behavior
Custom lifecycle hooks and their side effectsHooks that send emails, call external APIs or write other records may fire at different points or more than once, which adds test and rework timeInventory lifecycle subscribers and note any that trigger outside requests or background jobs
Test coverageThin coverage means behavior changes surface late in staging, while good coverage makes regressions visible during the rewriteCheck whether tests exist for create, update, publish and delete paths on each content type
Number of content types and componentsMore types and components increase the number of queries to verify and the number of relations that use documentIdCount content types, components and dynamic zones, and note which relations are referenced by custom code
Data volume affecting staging runsLarge datasets lengthen data migration runs and test cycles on a copy of production dataConfirm record counts per type and ask for a staging copy that matches production size
Plugins that call the Entity ServiceThird-party or custom plugins may need their own rewrite or an upgraded version before your code can moveCheck each plugin's Strapi 5 compatibility and whether it calls entityService directly

Questions teams ask before the Document Service rewrite

How much does the Document Service rewrite cost?

The cost depends on how much custom back-end code you have, not on the Strapi version alone. No price is given here because DeployOpen quotes from a written scope. The main cost components are: the audit of controllers, services, lifecycle hooks and custom queries that call the Entity Service; the rewrite of those calls to Document Service methods; test work to confirm that responses, drafts and published entries behave as before; and the staging runs needed for sign-off. One-time work covers the rewrite and testing. Recurring cost appears only if you later buy support or a retainer. When you ask for a quote, request a list of files in scope, the number of custom endpoints and lifecycle hooks, which plugins touch the affected code, and whether the scope includes a staging rehearsal and a retest.

How long does a Document Service migration take?

Duration is set by the size and shape of your custom code and by how quickly your team can review and test behavior. The biggest drivers are the number of Entity Service calls, how many custom routes return entries to front ends, how much logic depends on draft and publish state, and whether internationalization is enabled. Test coverage matters too: a project with automated tests for its custom endpoints usually moves faster than one where every change must be checked by hand. Ask for a timeline that separates the audit, the rewrite, the staging rehearsal and the sign-off window, and confirm which parts depend on your reviewers rather than the implementer.

Can an in-house developer do the Document Service rewrite?

Yes, if the developer knows Strapi 5 well enough to read the Document Service documentation and reason about draft and published state. The work is mostly careful code reading and testing rather than new architecture. Teams that do it in-house usually need time to learn how documentId replaces numeric id in their code, how array results change the shape of returned data, and how the status option replaces older publication parameters. A useful check is whether the team can write tests that prove a custom endpoint returns the same data before and after the change. If that skill is missing, a partner can cover the audit and tests while your developers keep ownership of the code.

What does the rewrite need from our team?

The engagement needs access and decisions from your side. Typically this includes:

  • Read access to the repository, including custom controllers, services, policies, lifecycle hooks and plugin code.
  • A staging environment with a recent copy of production data, so behavior can be compared on real content shapes.
  • Test data and known edge cases, such as drafts, localized entries, relations and media fields.
  • A named reviewer who can sign off on API responses that front ends depend on.
  • A window for the staging rehearsal and a decision on the production cutover date.

Ask for the access list in writing before work starts, and confirm who owns the staging database and who approves changes to the main branch.

Are the Strapi codemods enough to finish the migration?

No. The upgrade tool with codemods handles many mechanical changes, but it does not rewrite every custom Entity Service call or every place where your code depends on numeric IDs, array results or publication state. Codemods are useful for the common patterns, and your team should review every change they make. Manual work usually remains in custom queries, lifecycle logic, custom endpoints that build responses by hand, and code that passes id values between services. Check the Strapi v4 to v5 migration documentation for the current list of what the codemods cover, then search your own code for strapi.entityService and strapi.db.query calls, since those are the places most likely to need hand edits.

What happens if the upgrade fails partway through?

Plan for a restore, not a downgrade. Strapi's migration documentation says to back up the database before upgrading because downgrading is not supported, and data migration scripts run on the first start of Strapi 5. If the upgrade fails, the recovery path is to restore the pre-upgrade database and the matching code revision, then investigate on a copy. Before any production cutover, confirm that you have a tested database backup, a tagged code revision you can deploy again, and a rehearsal on staging that uses a copy of production data. A rollback plan that has never been run tends to fail when it is needed.

Does Strapi v4 end of life force the move to Strapi 5?

Strapi v4 reached end of life on April 30, 2026, and its final release, 4.26.2 of June 9, 2026, will receive no further updates. That date means a v4 project no longer gets upstream security or bug fixes, so staying on v4 becomes a risk you must accept and document. Moving to Strapi 5 is the supported path, and the Document Service rewrite is part of it for any project with custom back-end code. Confirm your own exposure with your security team, and check the Strapi migration documentation for the current requirements. Strapi 5 also requires supported Node.js versions and a supported database, so review those before scheduling the work.

Does the Document Service rewrite affect compliance evidence?

It can, because the change alters how content is read, published and returned, and your change records must show that. Auditors and internal reviewers usually want to see the scope of the change, the test results, the approval for the production cutover and the rollback plan. DeployOpen prepares systems, controls and evidence for compliance assessments, but it does not issue audit reports or certifications. Ask your compliance lead which records they need, such as change tickets, test logs and reviewer sign-offs, and agree on those artifacts before the rewrite starts.

How code, data and the upgrade tool fit together

The path starts with the v4 codebase and its database, which must be backed up before anything else runs, because Strapi does not support downgrading. The upgrade tool applies codemods to the code, and the Document Service rewrite is then done by hand. Strapi 5 runs its data migration on first start, so the staging run is the check that matters: if the result is wrong, the team restores the backup and does not try to reverse the migration in place.

Migration path from the v4 codebase and database to a tested Strapi 5 release, with rollback to the backup.

How DeployOpen scopes and delivers Strapi back-end rewrites

DeployOpen approaches the move from the Entity Service to the Document Service API as a scoped code change, not a loose cleanup. We inventory the v4 back-end code, agree what the rewrite covers in writing, and deliver the changed code with tests and notes that your team can review and keep. Engagements are fixed-scope, with ongoing support available as a retainer.

How we scope

  • We inventory the custom controllers, services, lifecycle hooks and queries that call the Entity Service API.
  • The written scope lists which files, routes and content types are rewritten, and which are left for a later phase.
  • We confirm with your team which codemod output is accepted as-is and which calls need manual Document Service work.

How we build

  • We rewrite calls to documentId-based Document Service methods and update array result handling in your code.
  • We rework draft and publish logic so status and publish actions run through the Document Service methods you agreed.
  • We test each rewritten endpoint against a copy of your database, comparing responses before and after the change.

How we hand over

  • We deliver the code changes in your repository with a per-file record of what the codemod changed and what we changed by hand.
  • We document remaining v4 response assumptions, so front-end teams know which clients still need the v4 compatibility header.
  • We walk your developers through the test results and leave a list of open items, owners and the agreed next steps.

How we support

  • Ongoing support, upgrades and continuous testing are available as retainers after the rewrite is handed over.
  • Support can cover later Strapi 5 minor releases, so the Document Service code is checked as the project moves forward.
  • Ask for the written support scope, response expectations and the testing cadence before the engagement starts.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.