# Contentful

The destination Contentful connector allows content to be transformed from Motation and synced to Contentful.

## Specifics

The destination Contentful connector is able to sync both content and files (as references).

### Entry Ids

Contentful uses a unique id for each entry. When creating and updating entries, Impulse will use the id from the source system. If the id exists, it will update the content, if not it will create it. According to the documentation, the id has to match this regex `/^[a-zA-Z0-9-_.]{1,64}$/`. If the id does not match this regex, it will be cleaned and removed all characters that do not match the regex.

### Content Status

Contentful has support for 4 status:

1. **Draft**: A draft entity is not published
2. **Changed**: An updated entity is published but has pending changes
3. **Published**: A published entity is published and has not been modified since
4. **Archived**: An archived entity is not published and can not be edited

**Note**: File Assets only support Draft and Published status.

#### Matrix of Entry status after Sync

| Matrix             | Destination - Draft | Destination Changed | Destination - Published | Destination Archived |
| ------------------ | ------------------- | ------------------- | ----------------------- | -------------------- |
| Source - Draft     | Draft               | Changed             | Changed                 | Draft                |
| Source - Changed   | Draft               | Changed             | Changed                 | Draft                |
| Source - Published | Published           | Published           | Published               | Published            |
| Source - Archived  | Archived            | Archived            | Archived                | Archived             |

For example: If an entry is *Changed* in the source, and *Published* in the destination, after the sync, the entry will be updated in the destination and the status will be *Changed*.

### Endpoint Config

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

* `contentRepo:contentful`
* `contentRepoVersion:latest`

### Token

Contentful API requires a token for authentication. This token must be provided in the adapter write config. The easiest option is to create a new "[Content management token](https://www.contentful.com/help/personal-access-tokens/)" for a Contentful user and pass that to Impulse.

### Content types

Content types are not synced by Impulse. A content type must already exist to sync content to. Use the [content mapper](https://motivlabs.gitbook.io/impulse-user-manual/getting-started/content-mapper) to align the incoming content to the existing content type.

### Spaces

Spaces are treated as equivalent to Motation's Domains. New synced domains will become new spaces in Contentful. It's required to specify the Space you want to sync to. For this there is a [job option](#space-job-option) that can be set to determine the specific spaces that content should be synced to.

### Environments

Motation does not support environments so new environments will not be synced. By default content will ignore environments.

### Locales

Locales are roughly equivalent to Motation's Languages. However, they are not supported yet. It wil use the default locale of the space.

### Pickup Date time

Setting a time zone is not supported. You must provide the time for the time zone the system uses.

### Number (Integer)

The Number (Integer) field type is supported however the value sent to the destination connector must be an integer. Otherwise it will default to 0. I.e.,if the value `7.000` is sent to the destination connector, the value saved to the system will be `0` not `7` . This can be solved using manipulators such as a Liquid manipulator to round the value to an integer.&#x20;

## Supported Fields

1. Text (Short)
2. Text (Long): Besides its standard use, this field will, also, be used to store any WYSIWYG content from other systems.
3. Number (Integer)
4. Number (Decimal)
5. Date and time
6. Boolean
7. Media
8. Reference
9. JSON Object
10. Array: Handled as an array of only strings.
11. Rich text: This field is handled internally by Contentful using a custom hierarchy. What makes this a System Field. What it means is that it will be synced only to Contentful and not other systems.

## Unsupported Fields

1. Location

## Unsupported Operations

1. Syncing Locales.
2. Creating "folders" in Contentful.

## Adapter Properties

| Property           | Purpose                                                                                                                                   |
| ------------------ | ----------------------------------------------------------------------------------------------------------------------------------------- |
| token              | The content management token to use Contentful's API.                                                                                     |
| space              | The space that should be searched for content and content should be synced to.                                                            |
| environment        | The environment that should be searched for content and content should be synced to.                                                      |
| rateLimitPerSecond | It is used to control the rate at which certain operations can be executed to prevent excessive usage or abuse of resources (default: 7). |

## Job Options

| Name                | Description                                                                                                                                                                                                                           | Data Type | Required | Default Value    |
| ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------- | -------- | ---------------- |
| space               | The space that should be searched for content and content should be synced to.                                                                                                                                                        | Text      | Yes      | No Default Value |
| environment         | The environment that should be searched for content and content should be synced to.                                                                                                                                                  | Text      | Yes      | No Default Value |
| contentType         | The content type to search for.                                                                                                                                                                                                       | Text      | Yes      | No Default Value |
| entry               | Entry id will be searched and synced, sync job will only sync this specific entry                                                                                                                                                     | Text      | No       | No Default Value |
| dependenciesDepth   | The max depth to look for dependencies. Files assets are dependencies.                                                                                                                                                                | Integer   | No       | 1                |
| contentDependencies | If dependencies should be picked up. Files assets are dependencies.                                                                                                                                                                   | Boolean   | No       | false            |
| query               | Query params to add to the request to find contents to pickup. Follows the standard query params from the [contentful doc](https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/search-parameters). | Text      | No       |                  |

### *space* Job Option

The value of the each `space` option should be the ID of the space Impulse should check and sync content to.

```
space:oneSpaceId
```

### *environment* Job Option

The value of the each `environment` option should be the ID of the space Impulse should check and sync content to.

```
environment:master
```

### *contentType* Job Option

The value of the `contentType` job option should match the Content Type ID from Contentful for the content type being checked/synced to.

```
contentType:Article
```

#### Syncing all media files / assets

Use the following value for the `contentType` job option to sync all media files / assets.

```
contentType:IMPULSE_ASSET
```

## Troubleshooting

* When syncing file assets from a Source to this destination with no content type attached you will need to set up a "dummy" content type with a media field in order to sync it over correctly with the content mapper.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://motivlabs.gitbook.io/impulse-user-manual/connectors/destination-connectors/contentful.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
