Entry
Entry
Warning Contentstack has deprecated the Dart Delivery SDK for new projects. Existing apps can keep using it. For new Dart or Flutter projects, call the Content Delivery API directly with an HTTP client.
An Entry reads one published entry of a content type. Use this class to
- fetch one entry by its UID
- choose the locale, the references and the fields that the response carries
- create a Query for the entries of the content type
stack.contentType('<CONTENT_TYPE_UID>').entry() creates an entry and takes one optional argument. The table below describes it:
| Name | Type | Description |
|---|---|---|
| entryUid | String? (named) | UID of the entry to fetch. Omit it when you only need a query. |
Instance State
The entryUid argument decides which methods do anything useful.
- Call entry(entryUid: '<ENTRY_UID>') to read one entry. Chain setters such as locale and includeReference, then call fetch.
- Call entry() without a UID to list entries. Call query and then the find method of the query.
The Method Index below lists the full set. fetch throws Exception on an entry without a UID. The setters work on both forms, but query does not copy them, so a setter on an entry without a UID has no effect.
Warning entry(entryUid: '') does not throw. fetch rejects null only, so an empty string requests a path that ends in /entries/. Check that a UID variable is non-empty before you pass it.
Class-Level Notes
Settings stay on the entry.
- Every setter writes a URL parameter to the entry and returns void. Chain setters with the cascade operator ... fetch sends them all.
- A second value for the same key replaces the first. No method removes a value. Create a new entry to send a request without it.
Typed results.
- fetch() without type arguments returns the response body as a Map. fetch<contentstack.EntryModel, void>() returns an EntryModel instead, which contains the fields in the EntryModel section below. See fetch for the Known issue on API errors.
Live Preview.
- When the livePreview map of the stack contains enable: true, fetch throws ArgumentError unless the map has a content_type_uid key.
- When that key matches the content type of the entry, fetch adds the live_preview parameter to the request.
Capability Matrix
| Capability | Supported | Notes / Alternative |
|---|---|---|
| Read several entries | No | Call query, then the find method of the query. |
| Read custom fields from an EntryModel | No | Call fetch() without type arguments and read the field from the Map. |
| Keep or drop several top-level fields with only or except | No | Pass one field through addParam, or read the fields you need from the full response. |
| Resolve several reference fields | Yes | Pass a List<String> to includeReference. |
| Remove a setting | No | Create a new entry. |
| Automatic retry on 429 | No | Implement backoff in your calling code. |
EntryModel
fetch<contentstack.EntryModel, void>() returns an EntryModel. You can also build one from a response map with contentstack.EntryModel.fromJson(map). The table below lists its twelve fields:
| Property | Type | Access | Default | Description |
|---|---|---|---|---|
| locale | String? | Read and write | null | Locale of the entry, from locale. |
| title | String? | Read and write | null | Title of the entry, from title. |
| url | String? | Read and write | null | URL of the entry, from url. |
| description | String? | Read and write | null | Value of the description field. |
| categories | List? | Read and write | null | Value of the categories field. |
| tags | List? | Read and write | null | Tags of the entry, from tags. |
| uid | String? | Read and write | null | UID of the entry, from uid. |
| createdBy | String? | Read and write | null | UID of the creator, from created_by. |
| updatedBy | String? | Read and write | null | UID of the last editor, from updated_by. |
| createdAt | String? | Read and write | null | Creation time, from created_at. |
| updatedAt | String? | Read and write | null | Last update time, from updated_at. |
| version | int? | Read and write | null | Version number, from _version. |
- EntryModel drops every other field of the content type. Read custom fields from the untyped Map.
- fromJson casts each value to the type in the table. A title, url or description field of another type, such as a JSON Rich Text Editor object, makes the typed call throw TypeError.
IncludeClass and IncludeType
includeReference takes an optional IncludeClass, which pairs an IncludeType with a list of field UIDs. The package library exports both. Build one with two positional arguments: contentstack.IncludeClass(contentstack.IncludeType.Only, ['title']). The table below lists the two properties of IncludeClass:
| Property | Type | Access | Default | Description |
|---|---|---|---|---|
| includeType | IncludeType | Read-only | Not applicable | Projection to apply to the referenced entries. |
| fieldUidList | List<String> | Read-only | Not applicable | Field UIDs that the projection uses. |
IncludeType has three values: None, Only and Except. The includeReference method lists what each value sends, and the Known issue that affects all three.
Method Index
Every setter works on any entry. The groups follow what you are trying to do.
Read the entry. Available on entry(entryUid: '<ENTRY_UID>'), as the last call in the chain.
| Method Name | Returns | Description |
|---|---|---|
| fetch | The requested entry. | Sends the request and returns the entry. |
List entries. Available on any entry, usually entry() without a UID.
| Method Name | Returns | Description |
|---|---|---|
| query | A new query for the content type. | Creates a query for the entries of the content type. |
Choose the locale. Available on any entry, before fetch.
| Method Name | Returns | Description |
|---|---|---|
| locale | Nothing. The entry keeps the setting for its next fetch. | Sets the locale to read. |
| includeFallback | Nothing. The entry keeps the setting for its next fetch. | Returns fallback locale content when the locale has none. |
Shape the response. Available on any entry, before fetch.
| Method Name | Returns | Description |
|---|---|---|
| only | Nothing. The entry keeps the setting for its next fetch. | Keeps the listed top-level fields. |
| except | Nothing. The entry keeps the setting for its next fetch. | Leaves the listed top-level fields out. |
| includeReference | Nothing. The entry keeps the setting for its next fetch. | Returns referenced entries in full instead of as UIDs. |
| includeReferenceContentTypeUID | Nothing. The entry keeps the setting for its next fetch. | Adds the content type UID to each referenced entry. |
| includeContentType | Nothing. The entry keeps the setting for its next fetch. | Returns the content type schema with the entry. |
| includeEmbeddedItems | Nothing. The entry keeps the setting for its next fetch. | Returns items embedded in Rich Text Editor fields. |
| includeBranch | Nothing. The entry keeps the setting for its next fetch. | Adds the _branch key to the entry. |
Send a parameter the SDK has no method for. Available on any entry, before fetch.
| Method Name | Returns | Description |
|---|---|---|
| addParam | Nothing. The entry keeps the setting for its next fetch. | Adds one URL parameter. |
Class-Level Snippet
The following snippet reads one entry in a locale, with fallback content and the author reference resolved.
import 'package:contentstack/contentstack.dart' as contentstack;
Future<void> main() async {
final stack = contentstack.Stack('<API_KEY>', '<DELIVERY_TOKEN>', '<ENVIRONMENT>');
final entry = stack.contentType('<CONTENT_TYPE_UID>').entry(entryUid: '<ENTRY_UID>')
..locale('<LOCALE>')
..includeFallback()
..includeReference('author');
try {
final response = await entry.fetch();
if (response is Map && response.containsKey('error_code')) {
// The API rejected the request
print('Request failed: ${response['error_code']} ${response['error_message']}');
} else {
print(response['entry']['title']);
print(response['entry']['author']);
}
} catch (e) {
// Thrown for a missing UID, a non-JSON response, a network failure or a 30-second timeout
print('Request did not complete: $e');
}
}Methods
Each method of the Entry class has its own section below, with its parameters, validation rules, behavior, and examples.
addParam
addParam adds one URL parameter to the request that the fetch method sends.
| Name | Type | Description |
|---|---|---|
| key (required) | String | Name of the URL parameter. |
| value (required) | String | Value of the URL parameter. |
Returns: void. Nothing. The entry keeps the setting for its next fetch.
Validation
- addParam ignores the call when key or value is an empty string. It throws nothing, so the parameter is missing from the request with no sign in your code.
- The SDK does not check the parameter name against the API. An unknown name or an invalid value surfaces when fetch() sends the request. The API rejection comes back as the result, not as an exception. Check the result for an error_code key.
Additional Resource Refer to Content Delivery API Errors for the full error code list.
Behavior
- Client-side only. addParam writes one key to the URL parameters of the entry and makes no request.
- Use addParam for an API parameter that has no method of its own, for example include_metadata. See the Get a single entry request.
- A second call with the same key replaces the value. That includes keys that other methods write, such as locale and environment.
- addParam is the workaround for the only and except methods, which send a list in a form that the API does not read. Pass one field, for example addParam('only[BASE][]', 'title'). See the Only operator request.
Example
Basic usage: add the metadata of the entry to the response
import 'package:contentstack/contentstack.dart' as contentstack;
Future<void> main() async {
final stack = contentstack.Stack('<API_KEY>', '<DELIVERY_TOKEN>', '<ENVIRONMENT>');
final entry = stack.contentType('<CONTENT_TYPE_UID>').entry(entryUid: '<ENTRY_UID>')
..addParam('include_metadata', 'true');
try {
final response = await entry.fetch();
if (response is Map && response.containsKey('error_code')) {
// The API rejected the request
print('Request failed: ${response['error_code']} ${response['error_message']}');
} else {
print(response['entry']['_metadata']);
}
} catch (e) {
// Thrown for a missing UID, a non-JSON response, a network failure or a 30-second timeout
print('Request did not complete: $e');
}
}Projection: keep one top-level field
import 'package:contentstack/contentstack.dart' as contentstack;
Future<void> main() async {
final stack = contentstack.Stack('<API_KEY>', '<DELIVERY_TOKEN>', '<ENVIRONMENT>');
final entry = stack.contentType('<CONTENT_TYPE_UID>').entry(entryUid: '<ENTRY_UID>')
..addParam('only[BASE][]', 'title');
final response = await entry.fetch();
print(response['entry']);
}except
except asks the API to leave the listed top-level fields out of the entry.
| Name | Type | Description |
|---|---|---|
| fieldUid (required) | List<String> | UIDs of the top-level fields to leave out. |
Returns: void. Nothing. The entry keeps the setting for its next fetch.
Validation
- except ignores an empty list.
- except removes every character other than letters, digits, -, _ and . from each UID. It throws nothing for an invalid UID.
- An invalid value surfaces when fetch() sends the request. The API rejection comes back as the result, not as an exception. Check the result for an error_code key.
Additional Resource Refer to Content Delivery API Errors for the full error code list.
Behavior
- Client-side only. except writes the except[BASE][] URL parameter and makes no request. The fetch method sends it. See the Exclude operator request.
- BASE stands for the top-level fields of the entry. To leave out one field of a referenced entry, call includeReference for the reference field, then addParam with addParam('except[author][]', 'title').
- A second call replaces the first list.
Known issue except sends the whole list as one value in the form [description, tags], not one except[BASE][] value per field, so the API does not apply your field list. To leave out one field, call addParam with addParam('except[BASE][]', 'description'). To leave out several, ignore the fields you do not need in the full response.
Example
Basic usage: pass the fields to leave out
import 'package:contentstack/contentstack.dart' as contentstack;
Future<void> main() async {
final stack = contentstack.Stack('<API_KEY>', '<DELIVERY_TOKEN>', '<ENVIRONMENT>');
// The SDK sends this list as one value. See the Known issue above.
final entry = stack.contentType('<CONTENT_TYPE_UID>').entry(entryUid: '<ENTRY_UID>')
..except(['description', 'tags']);
try {
final response = await entry.fetch();
if (response is Map && response.containsKey('error_code')) {
// The API rejected the request
print('Request failed: ${response['error_code']} ${response['error_message']}');
} else {
print(response['entry'].keys);
}
} catch (e) {
// Thrown for a missing UID, a non-JSON response, a network failure or a 30-second timeout
print('Request did not complete: $e');
}
}Workaround: leave out one field with addParam
import 'package:contentstack/contentstack.dart' as contentstack;
Future<void> main() async {
final stack = contentstack.Stack('<API_KEY>', '<DELIVERY_TOKEN>', '<ENVIRONMENT>');
final entry = stack.contentType('<CONTENT_TYPE_UID>').entry(entryUid: '<ENTRY_UID>')
..addParam('except[BASE][]', 'description');
final response = await entry.fetch();
print(response['entry'].keys);
}fetch
fetch requests the published entry whose UID the entry holds, with every setting chained on the entry.
This method takes no parameters. It reads the content type UID, the entry UID and every setting from the entry.
Returns: Future<T>. The requested entry.
Validation
- fetch throws Exception if the entry has no UID, because fetch reads one entry. Create the entry with entry(entryUid: '<ENTRY_UID>').
- The check rejects null only. An empty string passes, and fetch requests a path that ends in /entries/. Check that a UID variable is non-empty before you pass it.
- When the livePreview map of the stack holds enable: true, fetch throws ArgumentError if the map has no content_type_uid key.
- Beyond those cases, fetch throws only for a network failure, a 30-second timeout, or a response body that is not JSON.
- An API rejection returns as a normal result with an error_code key. It does not throw an exception.
- Check the result for an error_code key even inside a try block.
Additional Resource Refer to Content Delivery API Errors for the full error code list.
Behavior
- Each call sends one GET /content_types/{content_type_uid}/entries/{entry_uid} request with the headers of the stack. The API returns the latest published version. See the Get a single entry request.
- The query string holds the environment, which the entry copies from the stack when you create it, and every value from the setters, such as locale and includeReference.
- The type arguments decide the result:
- Without type arguments (fetch()), the result is the response body as a Map. Read the entry from its entry key.
- With fetch<contentstack.EntryModel, void>(), the result is an EntryModel that holds twelve standard fields. Every other field of the content type is missing from it. The Entry class page lists the fields.
- When you enable Live Preview, fetch adds a live_preview parameter when the content type UID of the entry matches the content_type_uid key of the livePreview map. It sends the live_preview value of the map, or init when the map has none.
- The entry keeps every setting, so a second fetch sends the same request again.
Known issue When the API rejects the request, fetch<contentstack.EntryModel, void>() returns an EntryModel with every field set to null, and the error is not visible. Call fetch() without type arguments, check for error_code, then build the model with contentstack.EntryModel.fromJson(response['entry']).
Example
Basic usage: read one entry
import 'package:contentstack/contentstack.dart' as contentstack;
Future<void> main() async {
final stack = contentstack.Stack('<API_KEY>', '<DELIVERY_TOKEN>', '<ENVIRONMENT>');
final entry = stack.contentType('<CONTENT_TYPE_UID>').entry(entryUid: '<ENTRY_UID>');
try {
final response = await entry.fetch();
if (response is Map && response.containsKey('error_code')) {
// The API rejected the request
print('Request failed: ${response['error_code']} ${response['error_message']}');
} else {
print(response['entry']['title']);
}
} catch (e) {
// Thrown for a missing UID, a non-JSON response, a network failure or a 30-second timeout
print('Request did not complete: $e');
}
}Model: read the entry as an EntryModel after checking for errors
import 'package:contentstack/contentstack.dart' as contentstack;
Future<void> main() async {
final stack = contentstack.Stack('<API_KEY>', '<DELIVERY_TOKEN>', '<ENVIRONMENT>');
final entry = stack.contentType('<CONTENT_TYPE_UID>').entry(entryUid: '<ENTRY_UID>');
final response = await entry.fetch();
if (response is Map && !response.containsKey('error_code')) {
final model = contentstack.EntryModel.fromJson(response['entry'] as Map<String, dynamic>);
print('${model.title}, version ${model.version}');
}
}Settings: read one locale with the author reference resolved
import 'package:contentstack/contentstack.dart' as contentstack;
Future<void> main() async {
final stack = contentstack.Stack('<API_KEY>', '<DELIVERY_TOKEN>', '<ENVIRONMENT>');
final entry = stack.contentType('<CONTENT_TYPE_UID>').entry(entryUid: '<ENTRY_UID>')
..locale('<LOCALE>')
..includeReference('author');
final response = await entry.fetch();
print(response['entry']['author']);
}includeBranch
includeBranch asks the API to add the _branch key, the UID of the branch that holds the entry, to the entry.
This method takes no parameters.
Returns: void. Nothing. The entry keeps the setting for its next fetch.
Validation
- There is no client-side validation.
- An invalid value surfaces when fetch() sends the request. The API rejection comes back as the result, not as an exception. Check the result for an error_code key.
Additional Resource Refer to Content Delivery API Errors for the full error code list.
Behavior
- Client-side only. includeBranch writes include_branch=true to the URL parameters and makes no request. The fetch method sends it. See the Get a single entry request.
- includeBranch does not choose a branch. The branch argument of the Stack constructor sets the branch that the request reads.
- No method removes the flag. Create a new entry to send a request without it.
Example
Basic usage: show the branch of the entry
import 'package:contentstack/contentstack.dart' as contentstack;
Future<void> main() async {
final stack = contentstack.Stack('<API_KEY>', '<DELIVERY_TOKEN>', '<ENVIRONMENT>');
final entry = stack.contentType('<CONTENT_TYPE_UID>').entry(entryUid: '<ENTRY_UID>')
..includeBranch();
try {
final response = await entry.fetch();
if (response is Map && response.containsKey('error_code')) {
// The API rejected the request
print('Request failed: ${response['error_code']} ${response['error_message']}');
} else {
print(response['entry']['_branch']);
}
} catch (e) {
// Thrown for a missing UID, a non-JSON response, a network failure or a 30-second timeout
print('Request did not complete: $e');
}
}includeContentType
includeContentType asks the API to return the schema of the content type, including the schema of its Global fields, along with the entry.
This method takes no parameters.
Returns: void. Nothing. The entry keeps the setting for its next fetch.
Validation
- There is no client-side validation.
- An invalid value surfaces when fetch() sends the request. The API rejection comes back as the result, not as an exception. Check the result for an error_code key.
Additional Resource Refer to Content Delivery API Errors for the full error code list.
Behavior
- Client-side only. includeContentType writes two URL parameters, include_content_type=true and include_global_field_schema=true, and makes no request. The fetch method sends them.
- The include_global_field_schema parameter returns the schema of each Global field in the content type. See the Get a single content type request.
- To read the schema without an entry, use the fetch method of the ContentType class.
- No method removes the flag. Create a new entry to send a request without it.
Example
Basic usage: read the entry with its content type
import 'package:contentstack/contentstack.dart' as contentstack;
Future<void> main() async {
final stack = contentstack.Stack('<API_KEY>', '<DELIVERY_TOKEN>', '<ENVIRONMENT>');
final entry = stack.contentType('<CONTENT_TYPE_UID>').entry(entryUid: '<ENTRY_UID>')
..includeContentType();
try {
final response = await entry.fetch();
if (response is Map && response.containsKey('error_code')) {
// The API rejected the request
print('Request failed: ${response['error_code']} ${response['error_message']}');
} else {
// The response carries the content type next to the entry
print(response.keys);
}
} catch (e) {
// Thrown for a missing UID, a non-JSON response, a network failure or a 30-second timeout
print('Request did not complete: $e');
}
}includeEmbeddedItems
includeEmbeddedItems asks the API to return the entries and assets embedded in the Rich Text Editor fields of the entry.
This method takes no parameters.
Returns: void. Nothing. The entry keeps the setting for its next fetch.
Validation
- There is no client-side validation.
- An invalid value surfaces when fetch() sends the request. The API rejection comes back as the result, not as an exception. Check the result for an error_code key.
Additional Resource Refer to Content Delivery API Errors for the full error code list.
Behavior
- Client-side only. includeEmbeddedItems writes include_embedded_items[]=BASE to the URL parameters and makes no request. The fetch method sends it.
- BASE returns the first level of embedded items, under the _embedded_items key. See the Get information on embedded RTE objects request.
- To also return items embedded inside those items, call addParam with addParam('include_embedded_items[]', 'RECURSIVE') instead. It writes the same key and replaces BASE. Add embedded_items_depth to set the number of levels. The API caps it at 5.
- No method removes the flag. Create a new entry to send a request without it.
Example
Basic usage: read the embedded items of the entry
import 'package:contentstack/contentstack.dart' as contentstack;
Future<void> main() async {
final stack = contentstack.Stack('<API_KEY>', '<DELIVERY_TOKEN>', '<ENVIRONMENT>');
final entry = stack.contentType('<CONTENT_TYPE_UID>').entry(entryUid: '<ENTRY_UID>')
..includeEmbeddedItems();
try {
final response = await entry.fetch();
if (response is Map && response.containsKey('error_code')) {
// The API rejected the request
print('Request failed: ${response['error_code']} ${response['error_message']}');
} else {
print(response['entry']['_embedded_items']);
}
} catch (e) {
// Thrown for a missing UID, a non-JSON response, a network failure or a 30-second timeout
print('Request did not complete: $e');
}
}Nested items: read embedded items three levels deep
import 'package:contentstack/contentstack.dart' as contentstack;
Future<void> main() async {
final stack = contentstack.Stack('<API_KEY>', '<DELIVERY_TOKEN>', '<ENVIRONMENT>');
final entry = stack.contentType('<CONTENT_TYPE_UID>').entry(entryUid: '<ENTRY_UID>')
..addParam('include_embedded_items[]', 'RECURSIVE')
..addParam('embedded_items_depth', '3');
final response = await entry.fetch();
print(response['entry']['_embedded_items']);
}includeFallback
includeFallback asks the API to return content from the fallback locale when the entry has no published content in the requested locale.
This method takes no parameters.
Returns: void. Nothing. The entry keeps the setting for its next fetch.
Validation
- There is no client-side validation.
- An invalid value surfaces when fetch() sends the request. The API rejection comes back as the result, not as an exception. Check the result for an error_code key.
Additional Resource Refer to Content Delivery API Errors for the full error code list.
Behavior
- Client-side only. includeFallback writes include_fallback=true to the URL parameters and makes no request. The fetch method sends it. See the Get a single entry request.
- Use it with the locale method, which sets the requested locale.
- No method removes the flag. Create a new entry to send a request without it.
Example
Basic usage: read one locale with fallback content
import 'package:contentstack/contentstack.dart' as contentstack;
Future<void> main() async {
final stack = contentstack.Stack('<API_KEY>', '<DELIVERY_TOKEN>', '<ENVIRONMENT>');
final entry = stack.contentType('<CONTENT_TYPE_UID>').entry(entryUid: '<ENTRY_UID>')
..locale('<LOCALE>')
..includeFallback();
try {
final response = await entry.fetch();
if (response is Map && response.containsKey('error_code')) {
// The API rejected the request
print('Request failed: ${response['error_code']} ${response['error_message']}');
} else {
print(response['entry']['title']);
}
} catch (e) {
// Thrown for a missing UID, a non-JSON response, a network failure or a 30-second timeout
print('Request did not complete: $e');
}
}includeReference
includeReference asks the API to return the entries that one or more reference fields point to in full, instead of their UIDs only.
| Name | Type | Description |
|---|---|---|
| referenceFieldUid (required) | dynamic | Reference field UID as a String, or several as a List<String>. |
| includeReferenceField | IncludeClass? (named) | Field projection for the referenced entries. null returns every field. |
Returns: void. Nothing. The entry keeps the setting for its next fetch.
Validation
- includeReference ignores the call when referenceFieldUid is null, an empty string or an empty list.
- Pass a String or a List<String>. includeReference throws NoSuchMethodError at the call for another type, such as an int, because it reads isNotEmpty from the value.
- With includeReferenceField, includeReference removes every character other than letters, digits, -, _ and . from each UID. It throws nothing for an invalid UID.
- An invalid value surfaces when fetch() sends the request. The API rejection comes back as the result, not as an exception. Check the result for an error_code key.
Additional Resource Refer to Content Delivery API Errors for the full error code list.
Behavior
- Client-side only. includeReference writes the include[] URL parameter, and the only or except parameter for a projection, and makes no request. The fetch method sends them. See the Include Reference request.
- For a reference field inside a Group field, pass the path with a dot, for example bank_offers.bank.
- Build includeReferenceField with contentstack.IncludeClass(contentstack.IncludeType.Only, ['title']). The Entry class page describes both types. The table below lists what the entry sends for each form:
| Arguments | What the entry sends |
|---|---|
| 'author' | include[]=author |
| ['author', 'category'] | include[]=author&include[]=category, one pair per UID |
| 'author' with IncludeType.None and a field list | include[]=[author, category], one value |
| 'author' with IncludeType.Only and a field list | include[]=author and only={author: [title]} |
| 'author' with IncludeType.Except and a field list | include[]=author and except={author: [title]} |
- A second call replaces the reference fields of the first. Pass every reference field in one list instead.
- To resolve every reference field of the entry, call addParam with addParam('include_all', 'true'), which returns referenced entries to a depth of 1. See the Include all references request.
Known issue With IncludeType.None, the SDK sends every UID as one value ([author, category]), so the API does not resolve the references. Pass a list of UIDs without includeReferenceField instead. With IncludeType.Only or IncludeType.Except, the SDK sends the field list as only={author: [title]}, not the only[author][]=title form that the API documents, so the API does not apply the list. Call includeReference('author'), then addParam with addParam('only[author][]', 'title') to keep one field.
Example
Basic usage: resolve the author reference
import 'package:contentstack/contentstack.dart' as contentstack;
Future<void> main() async {
final stack = contentstack.Stack('<API_KEY>', '<DELIVERY_TOKEN>', '<ENVIRONMENT>');
final entry = stack.contentType('<CONTENT_TYPE_UID>').entry(entryUid: '<ENTRY_UID>')
..includeReference('author');
try {
final response = await entry.fetch();
if (response is Map && response.containsKey('error_code')) {
// The API rejected the request
print('Request failed: ${response['error_code']} ${response['error_message']}');
} else {
print(response['entry']['author']);
}
} catch (e) {
// Thrown for a missing UID, a non-JSON response, a network failure or a 30-second timeout
print('Request did not complete: $e');
}
}Several references: resolve two reference fields in one call
import 'package:contentstack/contentstack.dart' as contentstack;
Future<void> main() async {
final stack = contentstack.Stack('<API_KEY>', '<DELIVERY_TOKEN>', '<ENVIRONMENT>');
final entry = stack.contentType('<CONTENT_TYPE_UID>').entry(entryUid: '<ENTRY_UID>')
..includeReference(['author', 'category']);
final response = await entry.fetch();
print(response['entry']['author']);
print(response['entry']['category']);
}Projection: pass a field list for the referenced entries
import 'package:contentstack/contentstack.dart' as contentstack;
Future<void> main() async {
final stack = contentstack.Stack('<API_KEY>', '<DELIVERY_TOKEN>', '<ENVIRONMENT>');
// The SDK sends the field list in a form that the API does not apply. See the Known issue above.
final entry = stack.contentType('<CONTENT_TYPE_UID>').entry(entryUid: '<ENTRY_UID>')
..includeReference(
'author',
includeReferenceField: contentstack.IncludeClass(contentstack.IncludeType.Only, ['title']),
);
final response = await entry.fetch();
print(response['entry']['author']);
}Workaround: keep one field of the referenced entries
import 'package:contentstack/contentstack.dart' as contentstack;
Future<void> main() async {
final stack = contentstack.Stack('<API_KEY>', '<DELIVERY_TOKEN>', '<ENVIRONMENT>');
final entry = stack.contentType('<CONTENT_TYPE_UID>').entry(entryUid: '<ENTRY_UID>')
..includeReference('author')
..addParam('only[author][]', 'title');
final response = await entry.fetch();
print(response['entry']['author']);
}includeReferenceContentTypeUID
includeReferenceContentTypeUID asks the API to add the content type UID to each referenced entry in the response.
This method takes no parameters.
Returns: void. Nothing. The entry keeps the setting for its next fetch.
Validation
- There is no client-side validation.
- An invalid value surfaces when fetch() sends the request. The API rejection comes back as the result, not as an exception. Check the result for an error_code key.
Additional Resource Refer to Content Delivery API Errors for the full error code list.
Behavior
- Client-side only. includeReferenceContentTypeUID writes include_reference_content_type_uid=true to the URL parameters and makes no request. The fetch method sends it.
- Use it with the includeReference method. It tells you which content type each referenced entry belongs to when a reference field points to more than one content type.
- No method removes the flag. Create a new entry to send a request without it.
Example
Basic usage: resolve a reference and show the content type of each referenced entry
import 'package:contentstack/contentstack.dart' as contentstack;
Future<void> main() async {
final stack = contentstack.Stack('<API_KEY>', '<DELIVERY_TOKEN>', '<ENVIRONMENT>');
final entry = stack.contentType('<CONTENT_TYPE_UID>').entry(entryUid: '<ENTRY_UID>')
..includeReference('author')
..includeReferenceContentTypeUID();
try {
final response = await entry.fetch();
if (response is Map && response.containsKey('error_code')) {
// The API rejected the request
print('Request failed: ${response['error_code']} ${response['error_message']}');
} else {
print(response['entry']['author']);
}
} catch (e) {
// Thrown for a missing UID, a non-JSON response, a network failure or a 30-second timeout
print('Request did not complete: $e');
}
}locale
locale sets the language version of the entry that the fetch method returns.
| Name | Type | Description |
|---|---|---|
| locale (required) | String | Locale code to read, for example fr-fr. |
Returns: void. Nothing. The entry keeps the setting for its next fetch.
Validation
- There is no client-side validation. An empty string reaches the request as locale=.
- An invalid value surfaces when fetch() sends the request. The API rejection comes back as the result, not as an exception. Check the result for an error_code key.
Additional Resource Refer to Content Delivery API Errors for the full error code list.
Behavior
- Client-side only. locale writes the locale URL parameter and makes no request. The fetch method sends it.
- The API returns the entry only when the entry has published content in that locale. See the Get a single entry request.
- Add the includeFallback method to return fallback content when the entry has no published content in the locale.
- A second call replaces the first value.
Example
Basic usage: read the entry in one locale
import 'package:contentstack/contentstack.dart' as contentstack;
Future<void> main() async {
final stack = contentstack.Stack('<API_KEY>', '<DELIVERY_TOKEN>', '<ENVIRONMENT>');
final entry = stack.contentType('<CONTENT_TYPE_UID>').entry(entryUid: '<ENTRY_UID>')
..locale('<LOCALE>');
try {
final response = await entry.fetch();
if (response is Map && response.containsKey('error_code')) {
// The API rejected the request
print('Request failed: ${response['error_code']} ${response['error_message']}');
} else {
print(response['entry']['title']);
}
} catch (e) {
// Thrown for a missing UID, a non-JSON response, a network failure or a 30-second timeout
print('Request did not complete: $e');
}
}only
only asks the API to return only the listed top-level fields of the entry.
| Name | Type | Description |
|---|---|---|
| fieldUid (required) | List<String> | UIDs of the top-level fields to keep. |
Returns: void. Nothing. The entry keeps the setting for its next fetch.
Validation
- only ignores an empty list.
- only removes every character other than letters, digits, -, _ and . from each UID. It throws nothing for an invalid UID.
- An invalid value surfaces when fetch() sends the request. The API rejection comes back as the result, not as an exception. Check the result for an error_code key.
Additional Resource Refer to Content Delivery API Errors for the full error code list.
Behavior
- Client-side only. only writes the only[BASE][] URL parameter and makes no request. The fetch method sends it. See the Only operator request.
- BASE stands for the top-level fields of the entry. To keep one field of a referenced entry, call includeReference for the reference field, then addParam with addParam('only[author][]', 'title').
- A second call replaces the first list.
Known issue only sends the whole list as one value in the form [title, url], not one only[BASE][] value per field, so the API does not apply your field list. To keep one field, call addParam with addParam('only[BASE][]', 'title'). To keep several, read the fields you need from the full response.
Example
Basic usage: pass the fields to keep
import 'package:contentstack/contentstack.dart' as contentstack;
Future<void> main() async {
final stack = contentstack.Stack('<API_KEY>', '<DELIVERY_TOKEN>', '<ENVIRONMENT>');
// The SDK sends this list as one value. See the Known issue above.
final entry = stack.contentType('<CONTENT_TYPE_UID>').entry(entryUid: '<ENTRY_UID>')
..only(['title', 'url']);
try {
final response = await entry.fetch();
if (response is Map && response.containsKey('error_code')) {
// The API rejected the request
print('Request failed: ${response['error_code']} ${response['error_message']}');
} else {
print(response['entry'].keys);
}
} catch (e) {
// Thrown for a missing UID, a non-JSON response, a network failure or a 30-second timeout
print('Request did not complete: $e');
}
}Workaround: keep one field with addParam
import 'package:contentstack/contentstack.dart' as contentstack;
Future<void> main() async {
final stack = contentstack.Stack('<API_KEY>', '<DELIVERY_TOKEN>', '<ENVIRONMENT>');
final entry = stack.contentType('<CONTENT_TYPE_UID>').entry(entryUid: '<ENTRY_UID>')
..addParam('only[BASE][]', 'title');
final response = await entry.fetch();
print(response['entry'].keys);
}query
query creates a Query for the entries of the content type that the entry belongs to.
This method takes no parameters.
Returns: Query. A new query for the content type.
Validation
- query throws TypeError if you called stack.contentType() without a UID, because a query reads the entries of one content type.
- query accepts an empty content type UID, and the query requests the path /content_types//entries.
- Errors that do occur come from the find call that follows, not from query(). The API rejection comes back as the result of find(), not as an exception. Check the result for an error_code key.
Additional Resource Refer to Content Delivery API Errors for the full error code list.
Behavior
- Client-side only. query makes no request. Call find on the query to send it.
- The query does not copy the settings or the UID of the entry. A locale or includeReference call on the entry has no effect on the query. Call the method of the same name on the query instead.
- Each call returns a new query with no settings. Create the entry without a UID, entry(), when you only need the query.
Example
Basic usage: list five entries of a content type
import 'package:contentstack/contentstack.dart' as contentstack;
Future<void> main() async {
final stack = contentstack.Stack('<API_KEY>', '<DELIVERY_TOKEN>', '<ENVIRONMENT>');
final query = stack.contentType('<CONTENT_TYPE_UID>').entry().query()..limit(5);
try {
final response = await query.find();
if (response is Map && response.containsKey('error_code')) {
// The API rejected the request
print('Request failed: ${response['error_code']} ${response['error_message']}');
} else {
for (final entry in response['entries']) {
print(entry['title']);
}
}
} catch (e) {
// Thrown for a non-JSON response, a network failure or a 30-second timeout
print('Request did not complete: $e');
}
}