Content List
Retrieves a list of content items from a project.
This endpoint is useful for retrieving all content or filtering by a specific model.
For example, if you have a model named post, you can use a query param to retrieve all content of that model.
Endpoint
curl https://api.contentisland.net/api/1.0/contents --header 'Authorization: Bearer YOUR_ACCESS_TOKEN'Query Params
This endpoint accepts the following query parameters:
interface ContentListQueryParams { id?: Filter; contentType?: Filter; language?: Filter; `fields.${string}`?: Filter; // Allows filtering by specific field values // For example: 'fields.slug': 'my-post' includeRelatedContent?: boolean; // Whether to include related content in the response (only first level relations) pagination?: { take?: number; // Number of items to retrieve skip?: number; // Number of items to skip }, sort?: { contentType?: 'asc' | 'desc'; // Sort by content type in ascending or descending order lastUpdate?: 'asc' | 'desc'; // Sort by last update time `fields.${string}`?: 'asc' | 'desc'; // Sort by specific field values }}| Name | Description |
|---|---|
id | The id field of the content to retrieve. Useful for retrieving specific items by ID.Example: /contents?id[in]=1,2,3 |
contentType | The model of the content you want to retrieve. Example: /contents?contentType=post |
language | The language of the content to retrieve. Only fields in the selected language will be returned. Example: /contents?language=es |
fields.${string} | Allows filtering by specific field values. Examples: /contents?fields.slug=my-post/contents?fields.title[in]=hello%20world,hola%20mundoRetrieves content with fields matching the specified values. |
includeRelatedContent | A boolean indicating whether to include related content in the response. This is useful when you want to fetch content along with its related items (only first level relations). Example: /contents?includeRelatedContent=true |
pagination | An object to control pagination of the results. - take: Number of items to retrieve.- skip: Number of items to skip.Example: client.getContentList({ pagination: { take: 10, skip: 20 } }) retrieves 10 items, skipping the first 20. |
sort | An object to define sorting of the results. - contentType: Sort by content type in ascending or descending order.- lastUpdate: Sort by last update time.- fields.${string}: Sort by specific field values.Example: client.getContentList({ sort: { 'fields.title': 'asc' } }) sorts by the title field in ascending order. |
type Filter = | string | { in?: string[]; // More filters to be added in the future };| Name | Description |
|---|---|
string | Filters content where the parameter equals the specified value.Example: /contents?contentType=postRetrieves content where the model is equal to post. |
in | Filters content where the parameter matches any of the provided values. Example: /contents?language[in]=es,enRetrieves content fields matching es and/or en. |
Example:
// Retrieve a list of content items filtered by model and languagecurl https://api.contentisland.net/api/1.0/contents?contentType=post&language[in]=es,en --header 'Authorization: Bearer YOUR_ACCESS_TOKEN'Response
The response is an array of JSON objects containing content information. Each object has the following structure:
export interface Content { id: string; contentType: { id: string; name: string }; lastUpdate: Date; fields: Field[];}
export interface Field { id: string; name: string; value: any; type: FieldType; isArray: boolean; language: string;}id: The content ID.contentType: The model to which the content belongs. Contains anidand aname.lastUpdate: The timestamp of the last update.fields: An array of objects representing the content fields.
Example:
[ { "id": "1", "contentType": { "id": "100", "name": "post" }, "lastUpdate": "2023-10-01T12:00:00Z", "fields": [ { "id": "111", "name": "title", "value": "Hola Mundo", "type": "short-text", "isArray": false, "language": "es" }, { "id": "222", "name": "body", "value": "Este es el cuerpo del post en markdown.", "type": "long-text", "isArray": false, "language": "es" }, { "id": "333", "name": "order", "value": 1, "type": "number", "isArray": false, "language": "es" } ] }]Status Codes
| Code | Description |
|---|---|
| 200 | The request was successfully processed and the content list was returned. |
| 401 | Unauthorized. The access token is invalid or has expired. |
| 500 | Internal server error. An error occurred while processing the request. |