Fresh API
The Fresh API allows you to retrieve content from Dynamic Content with no cache. It's designed specifically for the use of static site generators (SSG), such as Next.js, NuxtJS and Gatsby, that you can use to build your entire site ahead of time.
The Fresh API is intended for use by your static site generator build tools rather than to deliver content to the user in the browser.
Fresh API usage notes
- The Fresh API uses the same format of requests and responses as the Content Delivery API.
- The Fresh API allows you to retrieve content without a cache.
- The Fresh API should not be used to deliver content to the end user in the browser. It is only intended for use with your build tools.
- Note that if you do attempt to use the Fresh API from a browser, the OPTIONS request sent by the browser to preflight the API request will return a 405 (method not allowed) response.
- To use the Fresh API, you must include an API key in the header of each request. This API key will be provided to you when the API is provisioned on your chosen hubs.
- The Fresh API is rate limited.
- You can use the filter API to list, filter and sort content and return uncached content items.
- You should not include staged content in the build process for your static site. The code for preview and visualization should be separate to your static site code.
- The Content Delivery SDK includes support for the Fresh API.
Why use Fresh APILink copied!
Our next generation Content Delivery API, Content Delivery 2, is optimized for speed and scalability. To ensure that content is delivered to the user in the most efficient way possible, it is cached on our Content Delivery Network (CDN) with a Time to Live (TTL) of 5 minutes. This reduces latency and provides the best experience for the user.
The Fresh API ensures that when your build is triggered you will always retrieve the uncached, latest version of your content, rather than load the content from the cache. When using a static site generator with Dynamic Content you can trigger a build using our customizable webhooks service, when a content item is published, for example.
How do I get the Fresh API?Link copied!
If you want to use the Fresh API then it must be provisioned on your account and enabled on each hub on which you want to use it. Contact your Customer Success Manager for more details.
Rate limitsLink copied!
The Fresh API is rate limited. The limits are: 100 requests per second, with a burst limit of 200 requests per second.
Requests to the Fresh API are tracked against the API keys assigned to your hubs. Each of these API keys has a rate limit associated with it. Exceeding the rate limit will result in 429
responses from the
service. When receiving a 429, your code should attempt a retry after delaying the next request with exponential back-off.
If you use the Content Delivery SDK to make requests to the Fresh API, you can configure the number of retries and the delay between retries.
Using the APILink copied!
To use the Fresh API to retrieve uncached content replace cdn.content.amplience.net
with fresh.content.amplience.net
in your request URLs for the Content Delivery 2 APIs.
In this section we provide an overview of using the Fresh API including example requests and responses. For more examples see the Content Delivery 2 API page.
Get Content by Key or IDLink copied!
Retrieve the content item or slot with the delivery key or content item id.
Request URLsLink copied!
Request method: GET
DescriptionLink copied!
key
is the delivery key for the item. A delivery key may not start or end with "/", must be between 1 and 150 characters and cannot contain certain other special characters.
See the delivery key validation page for more details.
id
is the delivery ID for the item in UUID format
Example:
Request headerLink copied!
Header | Value | Description |
---|---|---|
X-API-Key | {apiKey} | The API key provided to you at the beginning of your project |
Note that if you provide an invalid API key then you will receive a 403 error response to any requests to the Fresh API.
ParametersLink copied!
Additional query parameters can be used to define the format of content retrieved by ID or key.
depthLink copied!
The depth parameter allows you to control whether to return items linked to the specified content item. For example for a carousel, you can control whether to return the carousel slides.
Value | Description |
---|---|
root | Default. Return the root item only and not any descendants. |
all | Return the root item and all its descendants. The content will be returned in the format specified by the format parameter. |
formatLink copied!
The format parameter allows you to specify whether content is retrieved in bandwidth optimised linked data format or inlined as a content tree.
Value | Description |
---|---|
linked | Default. Returns the content in a bandwidth optimised format. |
inlined | Returns the content inlined as a content tree. |
If you do not include the format parameter, then format=linked will be used by default.
When using field level localization, you can retrieve content for the specified locale. See locales on the Content Delivery 2 API page for more details.
Example requestLink copied!
The following example shows the Fresh API URL for a hub named ampproduct-doc
used to retrieve a published item with the content id 6757c1ab-6458-4ece-995e-9819a5cce7ff
.
You must send your API key in the request in the X-API-Key
header.
Example URL:
You can use the following cURL request to try out the API, replacing {api-key} with your API key, ampproduct-doc with your hub name, and the content id with the id of some content from your hub.
Example responseLink copied!
The JSON response for the request is shown below. This content item is a carousel that is linked to carousel slides. The content is returned in inlined format and, because depth=all
is specified, each of the carousel slides is returned as well as the carousel item.
Get multiple content items by key or idLink copied!
Use this request to retrieve multiple content items or slots by id or delivery key.
Note that this is a POST request, while Get Content by Key and Get Content by id are GET requests and are used to retrieve individual items.
Request URLLink copied!
Request method: POST
DescriptionLink copied!
The ids and delivery keys of the items to retrieve are specified in the request body.
Example URL:
Request bodyLink copied!
Property | Description |
---|---|
parameters (optional) object | Settings to apply to all items returned in the response. depth: root (default) or all. See depth for more details. format: linked (default) or inline. See format for more details. locale: Retrieve content for the specified locale. Note that if no parameters are specified the defaults will be used. |
requests array | An array of ids and delivery keys. For each item specify key or id. key: the delivery key of the item to return | id: the id of the item to return overrides: (optional). Parameters to be applied to this item. |
Request headerLink copied!
Header | Value | Description |
---|---|---|
X-API-Key | {apiKey} | The API key provided to you at the beginning of your project |
NotesLink copied!
The combined maximum number of ids and delivery keys that can be included in a request is 12.
ResponseLink copied!
The content-type of the response header is application/json; charset=UTF-8
.
Items will be returned in the order in which they are requested.
When requesting multiple items, if one item cannot be retrieved, for example if an item with the specified id or delivery key cannot be found, then an error will be shown for that individual request and the other content items will still be returned.
Property | Description |
---|---|
responses array | An array of content, linkedContent or error codes. content: The content item requested | error: An error type and message. Note: when requesting content in linked data format, items linked to another content item, such as a carousel or grid, will be returned as linkedContent. |
Status codesLink copied!
Status code | Description |
---|---|
200 | The request has succeeded. Errors may be shown for individual items. |
400 | Bad Request. |
403 | Invalid API key. |
405 | Method not allowed. Returned if you call the Fresh API from a browser (not currently supported). |
500 | Internal error. |
Example multi get requestLink copied!
A simple request body to retrieve two content items, one by id and one by key is shown below. No parameters are specified, so the defaults will be used.
You must send your API key in the request in the X-API-Key
header.
To try out the request use the following cURL with your own API key and some content item ids and delivery keys from your hub.
Example responseLink copied!
List, filter and sortLink copied!
You can also use the Fresh API to list, filter and sort content and return uncached results, using the same format of requests and responses as the Filter API. As with other Fresh API requests, you will need to include your API key in the header of each request and requests are rate limited.
To use the Fresh API to retrieve uncached content replace cdn.content.amplience.net
with fresh.content.amplience.net
in your request URLs for the Filter API.
In this section we'll provide an example of using the Fresh API to retrieve filtered content. You can find more details and lots of examples of how to list, filter and sort content on the Filter API page.
Request URLLink copied!
Request method: POST
DescriptionLink copied!
The filterable properties and (optional) sort key are included in the request body.
Example URL:
Request headerLink copied!
Header | Value | Description |
---|---|---|
X-API-Key | {apiKey} | The API key provided to you at the beginning of your project |
Request bodyLink copied!
Property | Description |
---|---|
filterBy array | An array of filterable properties and values. Filterable properties must be specified in the trait:filterable section of a content type schema. For each filterable property specify path and value: path: The JSON pointer format path to the filterable property to use as a filter. value: The value to match against. If you specify multiple filters then all filters must be matched (AND). |
sortBy (optional) object | The sort key and sort order to use to apply to the result. If no sort key is specified then the default sort order is used. If there is no default sort order then created date is used. The sort key must be specified in the trait:sortable section of each schema that contains the filterable property.key: The sort key defined in the schema. order(optional): ASC or DESC. Ascending or descending sort order. ASC is the default. |
Additional optional parameters can be found on the Filter API page.
Example requestLink copied!
The request body for a filter request to retrieve content filtered by the "pdp-content-block" content type and multiple properties is shown below.
You must send your API key in the request in the X-API-Key
header.
You can try out a filter request with the Fresh API using the following cURL with your own API key, hub name, and content created from the product details schema.
Example responseLink copied!
The JSON response to the example filter request is shown below.
Hierarchy APILink copied!
The Fresh API to can be used with the Hierarchy Get all descendants API to retrieve all descendants of a hierarchy node and return uncached results.
Request URLLink copied!
Request method: GET
DescriptionLink copied!
The properties, including the hierarchy depth and page size are included as path parameters. See parameters for more details.
Example URL:
Request headerLink copied!
Header | Value | Description |
---|---|---|
X-API-Key | {apiKey} | The API key provided to you at the beginning of your project |
ParametersLink copied!
The API accepts the following path parameters, all of which are optional.
Parameter | Description |
---|---|
hierarchyDepth | Returns descendants of the parent node to the specified depth. The maximum depth is 14, the default depth is 1. The parent node is level 0 |
sortByKey | The custom sort order. Note: Content is sorted by creation date if sort order is not specified. See sorting for more details |
sortByOrder | The sort order for the items in the response. Ascending (asc) or descending (desc). Ascending order is used if sort order is not specified |
maxPageSize | The maximum page size. See pagination |
pageCursor | Include to retrieve the next page of results if you have cursor from a previous response. See pagination |
Example requestLink copied!
An example URL is shown below. You will need to include this in a request with the API key in the header. The parameters in this example are used to retrieve all descendants of the hierarchy node with the id 4c67ca5a-6050-490a-9859-be20e81ac89d
to a depth of 3 levels.
To try out the request use the following cURL with your own API key and the content item id of a hierarchy node from your hub.
Example responseLink copied!
The JSON response to an example Hierarchy API request is shown below: