The APIs · Lesson 5 of 15 · 10 min

The four APIs

Read your content as JSON from the terminal and learn which API does which job.

Contentful is “API-first”. Everything the web app does, it does through an API you can call too.

The four APIs

API Host Use it for Token
Content Delivery cdn.contentful.com Published content for the live site Delivery
Content Preview preview.contentful.com Drafts, for people checking work Preview
GraphQL Content graphql.contentful.com Asking for exact fields in one request Delivery or Preview
Content Management api.contentful.com Creating and changing content and models Management

The first three only read. The last one writes.

1. Call the Delivery API

Put your Space ID and Delivery token in your terminal so the commands stay short:

export SPACE=your_space_id
export TOKEN=your_delivery_token

Now ask for your lessons:

curl -s "https://cdn.contentful.com/spaces/$SPACE/environments/master/entries?content_type=lesson" \
  -H "Authorization: Bearer $TOKEN"

You get JSON back. The parts that matter:

Part What it is
total How many entries match
items The entries. 100 per request unless you ask for more.
items[].sys System info: id, updatedAt, the content type
items[].fields Your fields: title, slug, body, and the rest
includes Linked entries and assets, sent along so you don’t need more requests

total should be 2. Your draft lesson isn’t there.

Find the author field on a lesson. It isn’t the author. It’s a link:

"author": {
  "sys": { "type": "Link", "linkType": "Entry", "id": "3xYz..." }
}

The real author is in includes.Entry, matched by that id. The JavaScript SDK you’ll install in lesson 7 does this matching for you, so lesson.fields.author.fields.name just works.

3. Useful query parameters

Parameter Does
content_type=lesson Only entries of one type
fields.slug=my-first-lesson Only the entry with that slug
include=2 Follow links two levels deep (Course → Lesson → Author)
limit=100&skip=100 The next page of results
order=-sys.updatedAt Newest first
select=fields.title,fields.slug Only send these fields

4. Call the Preview API

Same request, different host and token:

export PREVIEW_TOKEN=your_preview_token

curl -s "https://preview.contentful.com/spaces/$SPACE/environments/master/entries?content_type=lesson" \
  -H "Authorization: Bearer $PREVIEW_TOKEN"

Now total is 3. The draft shows up.