Strapi v4

The source Strapi v4 connector allows content to be picked up from Strapi versions 4.1.0 to be picked up and transformed into motation.

Configuration walkthrough

Specifics

The source Strapi v4 connector is able to sync both content and media files as well as users and roles/permissions.

UID Field

Impulse expects users to use the UID field provided in Strapi as a UUID for contents. Rather than rely on the auto incrementing ID of contents use the UID field and provide every content a UUID so that it can be queried and searched for. This is not only the best way to work with Impulse, but also the best way to build your Strapi deployment.

User Permissions

To pickup content from the Strapi system, you will need to pass a user's login credentials into the endpoint config. The user requires the appropriate permissions to be able to pickup the content. The permissions required are the same as the admin UI permissions. If the user is able to use the admin UI, it will work in Impulse.

Because the adapters communicate with Strapi through Strapi’s REST API, the JWT timeout for that adapter user should be long enough to complete a sync.

The easiest option is to create a super user and use those credential for Impulse.

Same System Only

Strapi v4 has a few field types that are synced only to another Strapi system.

Those fields are:

  • Component

  • Dynamic Zone

In addition Strapi v4 has a few Strapi v4 only objects that can be synced.

Those objects are:

  • Users

  • Roles

Private fields

Any field in a collection type that has the "private" attribute set will not be synced.

This includes the password field type as they are always private.

Endpoint Config

When saving an endpoint for a Strapi v4 repository via REST instead of the UI you must use the following key:value pairs in the payload.

  • contentRepo:strapi

  • contentRepoVersion:4.1.0

Pickup Date time

Setting a time zone is not supported. You must provide the time for the time zone the system uses. Strapi defaults to using UTC. This time zone may not match the time zone shown in the backend.

Login User

A "Login User" is a regular user created as a content in strapi to access the strapi API.

The login user used with Impulse requires full access to a content type's content. As well as access to the /api/user/me API.

It is best practice to set the login user up and use it's credentials in the sync. Using only an admin user is a deprecated functionality and may cause unexpected problems.

Unsupported

Multiple collection types per job. You can only sync one collection type per job. Setting multiple collection types will result in only one of them being synced.

Strapi v4 adapter does not support running as a remote adapter apart from Impulse.

Adapter Properties

PropertyPurpose

strapiURL

The URL to access the Strapi system.

user

The admin user with appropriate permissions.

password

The password for the admin user with appropriate permissions.

loginUser

The username for a regular user with appropriate permissions.

loginPassword

The password for the regular user with appropriate permissions.

rateLimitPerSecond

It is used to control the rate at which certain operations can be executed to prevent excessive usage or abuse of resources (default: 10).

Job Options

NameDescriptionData TypeRequiredDefault Value

contentNameField

Name of the field to be used as the content.properties.name of the motation object

Text

Yes

No Default Value

path

The path to pickup media files.

Array

No

No Default Value

contentType

The content type to pickup.

Text

No

No Default Value

contentTypeRoute

The endpoint route for the content type to pick up.

Text

dependenciesDepth

The max depth to look for dependencies.

Integer

No

1

contentDependencies

If dependencies should be picked up.

Boolean

No

false

role

Set true to pickup related roles

Boolean

No

No Default Value

user

Deprecated.

Array

No

No Default Value

query

Query params to add to the request to find contents to pick up. Follows the standard query params from strapi api doc.

Text

Sending specific contents of collection/single types.

To get the content of a collection type (or a single type) you will need to provide the API ID of the content type in the details of the endpoint like this: api::<api-id>.<api-id>

Note the difference between Strapi v3 using application::<api-id>.<api-id> and Strapi v4 using api::<api-id>.<api-id>

Example:

Syncing media files from the media library

Media files in the media library are treated as files that live under a path. As such the details to get files would be as follows: /uploads/files/<file-id>

Example 1: all media files

Example 2: specific media file with Id 1

Example 3: media files in a range

This example will get all media files within the query range. I.e. 2 files starting at the second in the list.

Example 4: multiple media files by id

Note: This list may change order. It is based on modification date of the files. You may want to verify the query before using it.

Getting dependencies

Dependencies in Strapi are:

  • Relation field

  • Media field

To sync the data of these fields you will need to set contentDependencies flag to true and set the dependency depth to the appropriate level.

Example: get dependencies 1 level deep

This will get any media files and related contents for a content of a collection type that is directly on the content. Any content that has a relationship to the related content will not be picked up.

I.e. Collection type, demo, has a media field and a one-to-one relationship field with related-type. related-type has its own media field. A depth of 1 will sync demo, demo’s media, and related-type. It will not sync related-type’s media field.

Getting Users

At this time, users are treated as a collection type. As such, they can be synced like a collection type. This also means that syncing user from Strapi v4 to any other repository, is not supported. It will be treated the same that any other collection type is treated.

To sync the user collection type, use the Contenttype job option. And set the value to plugin::users-permissions.user

Getting Roles

Roles will only sync from Strapi v4 to Strapi v4. They are only picked up as a dependency. As such to sync roles you need to set the "Role" job option to true. In addition, you will need to set Contentdependencies flag to true and set the dependency depth to the appropriate level.

Important: Each Impulse job syncs content in a specific order. Impulse will always sync primary content last. This means for a job that syncs users as the primary content with the roles option set to true, roles will be synced before users. This can cause some unexpected side effects.

gotcha 1: Job syncing users as primary content with roles option

The user being synced over has a UID that does not exist in the destination yet. But there is a user with the same Strapi content ID at the destination. This destination content with a matching ID will be updated because it was found before the UID was found. This is because the UID does not exist until the primary user content is synced which happens last.

To work around this you can run two user syncs.

  1. Without roles to sync the user content.

  2. With roles to sync the roles.

Motation Object Support

ObjectSupported

Category

No

Definition

Yes

Domain

No

Folder

Yes

Language

Yes

Relationship

Yes

Tag

No

Content Mapper

Below are details on how to find the appropriate values to use in the content mapper.

  • origin.uniqueId

    • Collection type's api id

  • fields.origin.uniqueId

    • Field name (case sensitive)

Troubleshooting

  • Dotcms Source Config:

    • If you find the content mapper set up correctly and the job configuration looks correct but the content still is not syncing over despite the job finishing make sure to check if the job option "deliver content types" is set to false this will ensure your content can be synced over correctly

  • When using CotnentTypeRoute make sure to apply admin to each collecton type that is being used in the sync

Last updated