Contentful Personalization & Analytics
    Preparing search index...

    Interface ContentfulClientApi<Modifiers>

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

    interface ContentfulClientApi<Modifiers extends ChainModifiers> {
        version: string;
        withAllLocales: "WITH_ALL_LOCALES" extends Modifiers
            ? never
            : ContentfulClientApi<AddChainModifier<Modifiers, "WITH_ALL_LOCALES">>;
        withoutLinkResolution: "WITHOUT_LINK_RESOLUTION" extends Modifiers
            ? never
            : "WITHOUT_UNRESOLVABLE_LINKS" extends Modifiers
                ? never
                : ContentfulClientApi<
                    AddChainModifier<Modifiers, "WITHOUT_LINK_RESOLUTION">,
                >;
        withoutUnresolvableLinks: "WITHOUT_LINK_RESOLUTION" extends Modifiers
            ? never
            : "WITHOUT_UNRESOLVABLE_LINKS" extends Modifiers
                ? never
                : ContentfulClientApi<
                    AddChainModifier<Modifiers, "WITHOUT_UNRESOLVABLE_LINKS">,
                >;
        createAssetKey(expiresAt: number): Promise<AssetKey>;
        getAsset<Locales extends string = string>(
            id: string,
            query?: AssetQueries<Modifiers>,
        ): Promise<Asset<Modifiers, Locales>>;
        getAssets<Locales extends string = string>(
            query?: AssetsQueries<AssetFields, Modifiers>,
        ): Promise<AssetCollection<Modifiers, Locales>>;
        getAssetsWithCursor<Locales extends string = string>(
            query?: AssetsQueriesWithCursor<AssetFields, Modifiers>,
        ): Promise<AssetCursorPaginatedCollection<Modifiers, Locales>>;
        getConcept<Locales extends string>(id: string): Promise<Concept<Locales>>;
        getConceptAncestors<Locales extends string>(
            id: string,
            query?: ConceptAncestorsDescendantsQueries,
        ): Promise<ConceptCollection<Locales>>;
        getConceptDescendants<Locale extends string>(
            id: string,
            query?: ConceptAncestorsDescendantsQueries,
        ): Promise<ConceptCollection<Locale>>;
        getConcepts<Locales extends string = "en-US">(
            query?: ConceptsQueries,
        ): Promise<ConceptCollection<Locales>>;
        getConceptScheme<Locales extends string = "en-US">(
            id: string,
        ): Promise<ConceptScheme<Locales>>;
        getConceptSchemes<Locales extends string = "en-US">(
            query?: ConceptSchemesQueries,
        ): Promise<ConceptSchemeCollection<Locales>>;
        getContentType(id: string): Promise<ContentType>;
        getContentTypes(query?: { query?: string }): Promise<ContentTypeCollection>;
        getEntries<
            EntrySkeleton extends EntrySkeletonType = EntrySkeletonType,
            Locales extends string = string,
        >(
            query?: EntriesQueries<EntrySkeleton, Modifiers>,
        ): Promise<EntryCollection<EntrySkeleton, Modifiers, Locales>>;
        getEntriesWithCursor<
            EntrySkeleton extends EntrySkeletonType = EntrySkeletonType,
            Locales extends string = string,
        >(
            query?: EntriesQueriesWithCursor<EntrySkeleton, Modifiers>,
        ): Promise<
            EntryCursorPaginatedCollection<EntrySkeleton, Modifiers, Locales>,
        >;
        getEntry<
            EntrySkeleton extends EntrySkeletonType = EntrySkeletonType,
            Locales extends string = string,
        >(
            id: string,
            query?: EntryQueries<Modifiers>,
        ): Promise<Entry<EntrySkeleton, Modifiers, Locales>>;
        getLocales(): Promise<LocaleCollection>;
        getSpace(): Promise<Space>;
        getTag(id: string): Promise<Tag>;
        getTags(query?: TagQueries): Promise<TagCollection>;
        parseEntries<
            EntrySkeleton extends EntrySkeletonType = EntrySkeletonType,
            Locales extends string = string,
        >(
            data: EntryCollection<
                EntrySkeleton,
                AddChainModifier<Modifiers, "WITHOUT_LINK_RESOLUTION">,
                Locales,
            >,
        ): EntryCollection<EntrySkeleton, Modifiers, Locales>;
        sync<
            EntrySkeleton extends EntrySkeletonType = EntrySkeletonType,
            Modifiers extends ChainModifiers = ChainModifiers,
            Locales extends string = string,
        >(
            query: SyncQuery,
            syncOptions?: SyncOptions,
        ): Promise<SyncCollection<EntrySkeleton, Modifiers, Locales>>;
    }

    Type Parameters

    • Modifiers extends ChainModifiers

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

    Index

    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)

      Parameters

      • expiresAt: number

      Returns Promise<AssetKey>

      Promise for an asset key

      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)
    • Fetches an 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
      • Optionalquery: AssetQueries<Modifiers>

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

      Returns Promise<Asset<Modifiers, Locales>>

      Promise for an asset

      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)
    • Fetches a collection of assets

      Type Parameters

      • Locales extends string = string

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

      Parameters

      • Optionalquery: AssetsQueries<AssetFields, Modifiers>

        Object with search parameters

      Returns Promise<AssetCollection<Modifiers, Locales>>

      Promise for a collection of Assets

      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)
    • Fetches a cursor paginated collection of assets

      Type Parameters

      • Locales extends string = string

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

      Parameters

      • Optionalquery: AssetsQueriesWithCursor<AssetFields, Modifiers>

        Object with search parameters

      Returns Promise<AssetCursorPaginatedCollection<Modifiers, Locales>>

      Promise for a cursor paginated collection of Assets

      const contentful = require('contentful')

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

      const response = await client.getAssetsWithCursor()
      console.log(response.items)
    • Fetches a Concept

      Type Parameters

      • Locales extends string

      Parameters

      • id: string

        The concept’s ID

      Returns Promise<Concept<Locales>>

      Promise for a concept

      const contentful = require('contentful')

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

      const concept = await client.getConcept('<concept_id>')
      console.log(concept)
    • Fetches a Concept Ancestors traversing the concept hierarchy by depth

      Type Parameters

      • Locales extends string

      Parameters

      • id: string

        The concept’s ID

      • Optionalquery: ConceptAncestorsDescendantsQueries

      Returns Promise<ConceptCollection<Locales>>

      Promise for a concept

      const contentful = require('contentful')

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

      const concept = await client.getConceptAncestors('<concept_id>', { depth: 5, order: 'sys.updatedAt' })
      console.log(concept)
    • Fetches a Concept Descendants traversing the concept hierarchy by depth

      Type Parameters

      • Locale extends string

      Parameters

      • id: string

        The concept’s ID

      • Optionalquery: ConceptAncestorsDescendantsQueries

      Returns Promise<ConceptCollection<Locale>>

      Promise for a concept

      const contentful = require('contentful')

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

      const concept = await client.getConceptDescendants('<concept_id>', { depth: 5, order: 'sys.updatedAt' })
      console.log(concept)
    • Fetches a collection of Concepts

      Type Parameters

      • Locales extends string = "en-US"

      Parameters

      • Optionalquery: ConceptsQueries

        Object with search parameters

      Returns Promise<ConceptCollection<Locales>>

      Promise for a collection of Concepts

      const contentful = require('contentful')

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

      const response = await client.getConcepts()
      console.log(response.items)
    • Fetches a Concept Scheme

      Type Parameters

      • Locales extends string = "en-US"

      Parameters

      • id: string

        The concept scheme's ID

      Returns Promise<ConceptScheme<Locales>>

      Promise for a concept scheme

      const contentful = require('contentful')

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

      const conceptScheme = await client.getConceptScheme('<concept_id>')
      console.log(conceptScheme)
    • Fetches a collection of Concept Schemes

      Type Parameters

      • Locales extends string = "en-US"

      Parameters

      • Optionalquery: ConceptSchemesQueries

        Object with search parameters

      Returns Promise<ConceptSchemeCollection<Locales>>

      Promise for a collection of Concept Schemes

      const contentful = require('contentful')

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

      const response = await client.getConceptSchemes()
      console.log(response.items)
    • Fetches a content type

      Parameters

      • id: string

        The content type’s ID

      Returns Promise<ContentType>

      Promise for a content type

      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)
    • Fetches a collection of content types

      Parameters

      • Optionalquery: { query?: string }

      Returns Promise<ContentTypeCollection>

      Promise for a collection of content types

      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)
    • Fetches an entry

      Type Parameters

      • EntrySkeleton extends EntrySkeletonType = EntrySkeletonType

        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

      • Optionalquery: 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

      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)
    • Fetches a collection of locales

      Returns Promise<LocaleCollection>

      Promise for a collection of locales

      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)
    • Fetches the space which the client is currently configured to use

      Returns Promise<Space>

      Promise for the space

      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)
    • Fetches a tag

      Parameters

      • id: string

        The tag’s ID

      Returns Promise<Tag>

      Promise for a tag

      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)
    • Gets a collection of Tags

      Parameters

      • Optionalquery: TagQueries

      Returns Promise<TagCollection>

      Promise for a collection of tags

      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)
    • Parse raw json data into a collection of entries. objects.Links will be resolved also

      Type Parameters

      • EntrySkeleton extends EntrySkeletonType = EntrySkeletonType

        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>

      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
    • 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.

      Type Parameters

      • EntrySkeleton extends EntrySkeletonType = EntrySkeletonType

        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

      • query: SyncQuery

        Query object

        • initial

          Optional, unless first sync call

        • limit

          Optional, sets the page size for the number of retrieved entries

        • nextSyncToken

          Optional, used in subsequent sync calls

        • nextPageToken

          Optional, used in subsequent sync calls

        • type

          Optional, query for specific entities

        • content_type

          Query for specific content types; optional, unless query.type is defined as Entry

      • OptionalsyncOptions: SyncOptions
        • paginate

          Configures the client to call the sync API recursively, collecting all items from responses into one collection

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

      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
      })