Interface ContentfulClientApi<Modifiers>

Contentful Delivery API Client. Contains methods which allow access to the different kinds of entities present in Contentful (Entries, Assets, etc).

Type Parameters

  • Modifiers extends ChainModifiers

    The chain modifiers used to configure the client. They’re set automatically when using the client chain modifiers.

Hierarchy

  • ContentfulClientApi

Properties

version: string

The current Contentful.js version

withAllLocales: "WITH_ALL_LOCALES" extends Modifiers
    ? never
    : ContentfulClientApi<AddChainModifier<Modifiers, "WITH_ALL_LOCALES">>

A client that will fetch assets and entries with all locales. Only available if not already enabled.

withoutLinkResolution: "WITHOUT_LINK_RESOLUTION" extends Modifiers
    ? never
    : "WITHOUT_UNRESOLVABLE_LINKS" extends Modifiers
        ? never
        : ContentfulClientApi<AddChainModifier<Modifiers, "WITHOUT_LINK_RESOLUTION">>

A client that will not resolve links in entries. Only available if not already disabled.

withoutUnresolvableLinks: "WITHOUT_LINK_RESOLUTION" extends Modifiers
    ? never
    : "WITHOUT_UNRESOLVABLE_LINKS" extends Modifiers
        ? never
        : ContentfulClientApi<AddChainModifier<Modifiers, "WITHOUT_UNRESOLVABLE_LINKS">>

A client that will remove unresolvable links from entries. Only available if not already disabled.

Methods

  • Creates an asset key for signing asset URLs (Embargoed Assets)

    Example

    import * as contentful from 'contentful'

    const client = contentful.createClient({
    space: '<space_id>',
    accessToken: '<content_delivery_api_key>'
    })

    const assetKey = await client.getAssetKey(<UNIX timestamp>)
    console.log(assetKey)

    Parameters

    • expiresAt: number

    Returns Promise<AssetKey>

    Promise for an asset key

  • Fetches an asset

    Example

    const contentful = require('contentful')

    const client = contentful.createClient({
    space: '<space_id>',
    accessToken: '<content_delivery_api_key>'
    })

    const asset = await client.getAsset('<asset_id>')
    console.log(asset)

    Type Parameters

    • Locales extends string = string

      If provided for a client using allLocales modifier, response type defines locale keys for asset field values.

    Parameters

    • id: string
    • Optional query: AssetQueries<Modifiers>

      Object with search parameters. In this method it's only useful for locale.

    Returns Promise<Asset<Modifiers, Locales>>

    Promise for an asset

  • Fetches a collection of assets

    See

    Example

    const contentful = require('contentful')

    const client = contentful.createClient({
    space: '<space_id>',
    accessToken: '<content_delivery_api_key>'
    })

    const response = await client.getAssets()
    console.log(response.items)

    Type Parameters

    • Locales extends string = string

      If provided for a client using allLocales modifier, response type defines locale keys for asset field values.

    Parameters

    Returns Promise<AssetCollection<Modifiers, Locales>>

    Promise for a collection of Assets

  • Fetches a content type

    Example

    import * as contentful from 'contentful'

    const client = contentful.createClient({
    space: '<space_id>',
    accessToken: '<content_delivery_api_key>'
    })

    const contentType = await client.getContentType('<content_type_id>')
    console.log(contentType)

    Parameters

    • id: string

      The content type’s ID

    Returns Promise<ContentType>

    Promise for a content type

  • Fetches a collection of content types

    Example

    import * as contentful from 'contentful'

    const client = contentful.createClient({
    space: '<space_id>',
    accessToken: '<content_delivery_api_key>'
    })

    const response = await client.getContentTypes()
    console.log(response.items)

    Parameters

    • Optional query: {
          query?: string;
      }
      • Optional query?: string

    Returns Promise<ContentTypeCollection>

    Promise for a collection of content types

  • Fetches a collection of Entries

    See

    Example

    const contentful = require('contentful')

    const client = contentful.createClient({
    space: '<space_id>',
    accessToken: '<content_delivery_api_key>'
    })

    const response = await client.getEntries()
    console.log(response.items)

    Type Parameters

    • EntrySkeleton extends EntrySkeletonType<FieldsType, string> = EntrySkeletonType<FieldsType, string>

      Shape of entry fields used to calculate dynamic keys

    • Locales extends string = string

      If provided for a client using allLocales modifier, response type defines locale keys for entry field values.

    Parameters

    • Optional query: EntriesQueries<EntrySkeleton, Modifiers>

      Object with search parameters

    Returns Promise<EntryCollection<EntrySkeleton, Modifiers, Locales>>

    Promise for a collection of Entries

  • Fetches an entry

    Example

    const contentful = require('contentful')

    const client = contentful.createClient({
    space: '<space_id>',
    accessToken: '<content_delivery_api_key>'
    })

    const entry = await client.getEntry('<entry_id>')
    console.log(entry)

    Type Parameters

    • EntrySkeleton extends EntrySkeletonType<FieldsType, string> = EntrySkeletonType<FieldsType, string>

      Shape of entry fields used to calculate dynamic keys

    • Locales extends string = string

      If provided for a client using allLocales modifier, response type defines locale keys for entry field values.

    Parameters

    • id: string

      The entry’s ID

    • Optional query: EntryQueries<Modifiers>

      Object with search parameters. In this method it's only used for locale when querying.

    Returns Promise<Entry<EntrySkeleton, Modifiers, Locales>>

    Promise for an entry

  • Fetches a collection of locales

    Example

    import * as contentful from 'contentful'

    const client = contentful.createClient({
    space: '<space_id>',
    accessToken: '<content_delivery_api_key>'
    })

    const response = await client.getLocales()
    console.log(response.items)

    Returns Promise<LocaleCollection>

    Promise for a collection of locales

  • Fetches the space which the client is currently configured to use

    Example

    import * as contentful from 'contentful'

    const client = contentful.createClient({
    space: '<space_id>',
    accessToken: '<content_delivery_api_key>'
    })

    const space = await client.getSpace()
    console.log(space)

    Returns Promise<Space>

    Promise for the space

  • Fetches a tag

    Example

    import * as contentful from 'contentful'

    const client = contentful.createClient({
    space: '<space_id>',
    accessToken: '<content_delivery_api_key>'
    })

    const tag = await client.getTag('<asset_id>')
    console.log(tag)

    Parameters

    • id: string

      The tag’s ID

    Returns Promise<Tag>

    Promise for a tag

  • Gets a collection of Tags

    Example

    import * as contentful from 'contentful'

    const client = contentful.createClient({
    space: '<space_id>',
    accessToken: '<content_delivery_api_key>'
    })

    const response = await client.getTags()
    console.log(response.items)

    Parameters

    Returns Promise<TagCollection>

    Promise for a collection of tags

  • Parse raw json data into a collection of entries. objects.Links will be resolved also

    Example

    const data = {items: [
    {
    sys: {type: 'Entry', locale: 'en-US'},
    fields: {
    animal: {sys: {type: 'Link', linkType: 'Animal', id: 'oink'}},
    anotheranimal: {sys: {type: 'Link', linkType: 'Animal', id: 'middle-parrot'}}
    }
    }
    ],
    includes: {
    Animal: [
    {
    sys: {type: 'Animal', id: 'oink', locale: 'en-US'},
    fields: {
    name: 'Pig',
    friend: {sys: {type: 'Link', linkType: 'Animal', id: 'groundhog'}}
    }
    }
    ]
    }
    }
    console.log( data.items[0].fields.foo ); // undefined
    const parsedData = client.parseEntries(data);
    console.log( parsedData.items[0].fields.foo ); // foo

    Type Parameters

    • EntrySkeleton extends EntrySkeletonType<FieldsType, string> = EntrySkeletonType<FieldsType, string>

      Shape of entry fields used to calculate dynamic keys

    • Locales extends string = string

      If provided for a client using allLocales modifier, response type defines locale keys for entry field values.

    Parameters

    Returns EntryCollection<EntrySkeleton, Modifiers, Locales>

  • Synchronizes either all the content or only new content since last sync. Important note: The Sync API endpoint does not support include or link resolution. However, contentful.js can do link resolution on the client side for the initial sync. For the delta sync (using nextSyncToken) link resolution is not possible since the sdk won’t have access to all linked entities.

    See

    Example

    import * as contentful from 'contentful'

    const client = contentful.createClient({
    space: '<space_id>',
    accessToken: '<content_delivery_api_key>'
    })

    const response = await client.sync({
    initial: true
    })
    console.log({
    entries: response.entries,
    assets: response.assets,
    nextSyncToken: response.nextSyncToken
    })

    Type Parameters

    • EntrySkeleton extends EntrySkeletonType<FieldsType, string> = EntrySkeletonType<FieldsType, string>

      Shape of entity fields used to calculate dynamic keys

    • Modifiers extends ChainModifiers = ChainModifiers

      The chain modifiers used to configure the client. They’re set automatically when using the client chain modifiers.

    • Locales extends string = string

      If provided for a client using allLocales modifier, response type defines locale keys for entity field values.

    Parameters

    Returns Promise<SyncCollection<EntrySkeleton, Modifiers, Locales>>