ContentfulSpaceAPI

ContentfulSpaceAPI

Source:
Contentful Space API. Contains methods to access any operations at a space level, such as creating and reading entities contained in a space.

Type Definitions

ContentfulSpaceAPI

Source:
Properties:
Name Type Description
delete function
update function
getEnvironment function
getEnvironments function
createEnvironment function
createEnvironmentWithId function
getContentType function
getContentTypes function
createContentType function
createContentTypeWithId function
getEntry function
getEntries function
createEntry function
createEntryWithId function
getAsset function
getAssets function
createAsset function
createAssetWithId function
getLocale function
getLocales function
createLocale function
getWebhook function
getWebhooks function
createWebhook function
createWebhookWithId function
getRole function
getRoles function
createRole function
createRoleWithId function
getSpaceUser function
getSpaceUsers function
getSpaceMember function
getSpaceMembers function
getSpaceMembership function
getSpaceMemberships function
createSpaceMembership function
createSpaceMembershipWithId function
createTeamSpaceMembership function
getTeamSpaceMembership function
getTeamSpaceMemberships function
getApiKey function
getApiKeys function
createApiKey function
createApiKeyWithId function
getUiExtension function
getUiExtensions function
createUiExtension function
createUiExtensionWithId function
getEntrySnapshots function
getContentTypeSnapshots function
getEnvironmentAliases function
getEnvironmentAlias function
Type:
  • object

Methods

(static) createApiKey(data) → {Promise.<ApiKey.ApiKey>}

Source:
See:
Creates a Api Key
Example
const contentful = require('contentful-management')

const client = contentful.createClient({
  accessToken: '<content_management_api_key>'
})

client.getSpace('<space_id>')
.then((space) => space.createApiKey({
  name: 'API Key name',
  environments:[
   {
    sys: {
     type: 'Link'
     linkType: 'Environment',
     id:'<environment_id>'
    }
   }
  ]
  }
}))
.then((apiKey) => console.log(apiKey))
.catch(console.error)
Parameters:
Name Type Description
data object Object representation of the Api Key to be created
Returns:
Promise for the newly created Api Key
Type
Promise.<ApiKey.ApiKey>

(static) createApiKeyWithId(id, data) → {Promise.<ApiKey.ApiKey>}

Source:
See:
Creates a Api Key with a custom ID
Example
const contentful = require('contentful-management')

const client = contentful.createClient({
  accessToken: '<content_management_api_key>'
})

client.getSpace('<space_id>')
.then((space) => space.createApiKeyWithId('<api-key-id>', {
  name: 'API Key name'
  environments:[
   {
    sys: {
     type: 'Link'
     linkType: 'Environment',
     id:'<environment_id>'
    }
   }
  ]
  }
}))
.then((apiKey) => console.log(apiKey))
.catch(console.error)
Parameters:
Name Type Description
id string Api Key ID
data object Object representation of the Api Key to be created
Returns:
Promise for the newly created Api Key
Type
Promise.<ApiKey.ApiKey>

(static) createAsset(data) → {Promise.<Asset.Asset>}

Source:
Deprecated:
  • since version 5.0
See:
Creates a Asset. After creation, call asset.processForLocale or asset.processForAllLocales to start asset processing.
Example
const client = contentful.createClient({
  accessToken: '<content_management_api_key>'
})

// Create asset
client.getSpace('<space_id>')
.then((space) => space.createAsset({
  fields: {
    title: {
      'en-US': 'Playsam Streamliner'
   },
   file: {
      'en-US': {
        contentType: 'image/jpeg',
       fileName: 'example.jpeg',
       upload: 'https://example.com/example.jpg'
     }
   }
  }
}))
.then((asset) => asset.processForLocale("en-US")) // OR asset.processForAllLocales()
.then((asset) => console.log(asset))
.catch(console.error)
Parameters:
Name Type Description
data object Object representation of the Asset to be created. Note that the field object should have an upload property on asset creation, which will be removed and replaced with an url property when processing is finished.
Returns:
Promise for the newly created Asset
Type
Promise.<Asset.Asset>

(static) createAssetFromFiles(data) → {Promise.<Asset.Asset>}

Source:
Deprecated:
  • since version 5.0
See:
Creates a Asset based on files. After creation, call asset.processForLocale or asset.processForAllLocales to start asset processing.
Example
const client = contentful.createClient({
  accessToken: '<content_management_api_key>'
})
client.getSpace('<space_id>')
.then((space) => space.createAssetFromFiles({
  fields: {
    file: {
      'en-US': {
         contentType: 'image/jpeg',
         fileName: 'filename_english.jpg',
         file: createReadStream('path/to/filename_english.jpg')
      },
      'de-DE': {
         contentType: 'image/svg+xml',
         fileName: 'filename_german.svg',
         file: '<svg><path fill="red" d="M50 50h150v50H50z"/></svg>'
      }
    }
  }
}))
.then((asset) => console.log(asset))
.catch(console.error)
Parameters:
Name Type Description
data object Object representation of the Asset to be created. Note that the field object should have an uploadFrom property on asset creation, which will be removed and replaced with an url property when processing is finished.
Properties
Name Type Description
fields.file.[LOCALE].file object Can be a string, an ArrayBuffer or a Stream.
Returns:
Promise for the newly created Asset
Type
Promise.<Asset.Asset>

(static) createAssetWithId(id, data) → {Promise.<Asset.Asset>}

Source:
Deprecated:
  • since version 5.0
See:
Creates a Asset with a custom ID. After creation, call asset.processForLocale or asset.processForAllLocales to start asset processing.
Example
const client = contentful.createClient({
  accessToken: '<content_management_api_key>'
})

// Create asset
client.getSpace('<space_id>')
.then((space) => space.createAssetWithId('<asset_id>', {
  title: {
    'en-US': 'Playsam Streamliner'
  },
  file: {
    'en-US': {
      contentType: 'image/jpeg',
      fileName: 'example.jpeg',
      upload: 'https://example.com/example.jpg'
    }
  }
}))
.then((asset) => asset.process())
.then((asset) => console.log(asset))
.catch(console.error)
Parameters:
Name Type Description
id string Asset ID
data object Object representation of the Asset to be created. Note that the field object should have an upload property on asset creation, which will be removed and replaced with an url property when processing is finished.
Returns:
Promise for the newly created Asset
Type
Promise.<Asset.Asset>

(static) createContentType(data) → {Promise.<ContentType.ContentType>}

Source:
Deprecated:
  • since version 5.0
See:
Creates a Content Type
Example
const contentful = require('contentful-management')

const client = contentful.createClient({
  accessToken: '<content_management_api_key>'
})

client.getSpace('<space_id>')
.then((space) => space.createContentType({
  name: 'Blog Post',
  fields: [
    {
      id: 'title',
      name: 'Title',
      required: true,
      localized: false,
      type: 'Text'
    }
  ]
}))
.then((contentType) => console.log(contentType))
.catch(console.error)
Parameters:
Name Type Description
data object Object representation of the Content Type to be created
Returns:
Promise for the newly created Content Type
Type
Promise.<ContentType.ContentType>

(static) createContentTypeWithId(id, data) → {Promise.<ContentType.ContentType>}

Source:
Deprecated:
  • since version 5.0
See:
Creates a Content Type with a custom ID
Example
const contentful = require('contentful-management')

const client = contentful.createClient({
  accessToken: '<content_management_api_key>'
})

client.getSpace('<space_id>')
.then((space) => space.createContentTypeWithId('<content-type-id>', {
  name: 'Blog Post',
  fields: [
    {
      id: 'title',
      name: 'Title',
      required: true,
      localized: false,
      type: 'Text'
    }
  ]
}))
.then((contentType) => console.log(contentType))
.catch(console.error)
Parameters:
Name Type Description
id string Content Type ID
data object Object representation of the Content Type to be created
Returns:
Promise for the newly created Content Type
Type
Promise.<ContentType.ContentType>

(static) createEntry(contentTypeId, data) → {Promise.<Entry.Entry>}

Source:
Deprecated:
  • since version 5.0
See:
Creates a Entry
Example
const contentful = require('contentful-management')

const client = contentful.createClient({
  accessToken: '<content_management_api_key>'
})

client.getSpace('<space_id>')
.then((space) => space.createEntry('<content_type_id>', {
  fields: {
    title: {
      'en-US': 'Entry title'
    }
  }
}))
.then((entry) => console.log(entry))
.catch(console.error)
Parameters:
Name Type Description
contentTypeId string The Content Type which this Entry is based on
data object Object representation of the Entry to be created
Returns:
Promise for the newly created Entry
Type
Promise.<Entry.Entry>

(static) createEntryWithId(contentTypeId, id, data) → {Promise.<Entry.Entry>}

Source:
Deprecated:
  • since version 5.0
See:
Creates a Entry with a custom ID
Example
const contentful = require('contentful-management')

const client = contentful.createClient({
  accessToken: '<content_management_api_key>'
})

// Create entry
client.getSpace('<space_id>')
.then((space) => space.createEntryWithId('<content_type_id>', '<entry_id>', {
  fields: {
    title: {
      'en-US': 'Entry title'
    }
  }
}))
.then((entry) => console.log(entry))
.catch(console.error)
Parameters:
Name Type Description
contentTypeId string The Content Type which this Entry is based on
id string Entry ID
data object Object representation of the Entry to be created
Returns:
Promise for the newly created Entry
Type
Promise.<Entry.Entry>

(static) createEnvironment(dataopt) → {Promise.<Environment.Environment>}

Source:
See:
Creates an Environement
Example
const contentful = require('contentful-management')

const client = contentful.createClient({
  accessToken: '<content_management_api_key>'
})

client.getSpace('<space_id>')
.then((space) => space.createEnvironment({ name: 'Staging' }))
.then((environment) => console.log(environment))
.catch(console.error)
Parameters:
Name Type Attributes Description
data object <optional>
Object representation of the Environment to be created
Returns:
Promise for the newly created Environment
Type
Promise.<Environment.Environment>

(static) createEnvironmentWithId(id, dataopt, sourceEnvironmentIdopt) → {Promise.<Environment.Environment>}

Source:
See:
Creates an Environment with a custom ID
Example
const contentful = require('contentful-management')

const client = contentful.createClient({
  accessToken: '<content_management_api_key>'
})

client.getSpace('<space_id>')
.then((space) => space.createEnvironmentWithId('<environment-id>', { name: 'Staging'}, 'master'))
.then((environment) => console.log(environment))
.catch(console.error)
Parameters:
Name Type Attributes Description
id string Environment ID
data object <optional>
Object representation of the Environment to be created
sourceEnvironmentId string <optional>
ID of the source environment that will be copied to create the new environment. Default is "master"
Returns:
Promise for the newly created Environment
Type
Promise.<Environment.Environment>

(static) createLocale(data) → {Promise.<Locale.Locale>}

Source:
Deprecated:
  • since version 5.0
See:
Creates a Locale
Example
const contentful = require('contentful-management')

const client = contentful.createClient({
  accessToken: '<content_management_api_key>'
})

// Create locale
client.getSpace('<space_id>')
.then((space) => space.createLocale({
  name: 'German (Austria)',
  code: 'de-AT',
  fallbackCode: 'de-DE',
  optional: true
}))
.then((locale) => console.log(locale))
.catch(console.error)
Parameters:
Name Type Description
data object Object representation of the Locale to be created
Returns:
Promise for the newly created Locale
Type
Promise.<Locale.Locale>

(static) createRole(data) → {Promise.<Role.Role>}

Source:
See:
Creates a Role
Example
const contentful = require('contentful-management')

const client = contentful.createClient({
  accessToken: '<content_management_api_key>'
})
client.getSpace('<space_id>')
.then((space) => space.createRole({
  name: 'My Role',
  description: 'foobar role',
  permissions: {
    ContentDelivery: 'all',
    ContentModel: ['read'],
    Settings: []
  },
  policies: [
    {
      effect: 'allow',
      actions: 'all',
      constraint: {
        and: [
          {
            equals: [
              { doc: 'sys.type' },
              'Entry'
            ]
          },
          {
            equals: [
              { doc: 'sys.type' },
              'Asset'
            ]
          }
        ]
      }
    }
  ]
}))
.then((role) => console.log(role))
.catch(console.error)
Parameters:
Name Type Description
data object Object representation of the Role to be created
Returns:
Promise for the newly created Role
Type
Promise.<Role.Role>

(static) createRoleWithId(id, data) → {Promise.<Role.Role>}

Source:
See:
Creates a Role with a custom ID
Example
const contentful = require('contentful-management')

const client = contentful.createClient({
  accessToken: '<content_management_api_key>'
})
client.getSpace('<space_id>')
.then((space) => space.createRoleWithId('<role-id>', {
  name: 'My Role',
  description: 'foobar role',
  permissions: {
    ContentDelivery: 'all',
    ContentModel: ['read'],
    Settings: []
  },
  policies: [
    {
      effect: 'allow',
      actions: 'all',
      constraint: {
        and: [
          {
            equals: [
              { doc: 'sys.type' },
              'Entry'
            ]
          },
          {
            equals: [
              { doc: 'sys.type' },
              'Asset'
            ]
          }
        ]
      }
    }
  ]
}))
.then((role) => console.log(role))
.catch(console.error)
Parameters:
Name Type Description
id string Role ID
data object Object representation of the Role to be created
Returns:
Promise for the newly created Role
Type
Promise.<Role.Role>

(static) createTeamSpaceMembership(id, data) → {Promise.<TeamSpaceMembership.TeamSpaceMembership>}

Source:
See:
Creates a Team Space Membership
Example
const contentful = require('contentful-management')

const client = contentful.createClient({
  accessToken: '<content_management_api_key>'
})

client.getSpace('<space_id>')
.then((space) => space.createTeamSpaceMembership('team_id', {
  admin: false,
  roles: [
    {
      type: 'Link',
      linkType: 'Role',
      id: '<role_id>'
    }
  ],
}))
.then((teamSpaceMembership) => console.log(teamSpaceMembership))
.catch(console.error)
Parameters:
Name Type Description
id string Team ID
data object Object representation of the Team Space Membership to be created
Returns:
Promise for the newly created Team Space Membership
Type
Promise.<TeamSpaceMembership.TeamSpaceMembership>

(static) createUiExtension(data) → {Promise.<UiExtension.UiExtension>}

Source:
Deprecated:
  • since version 5.0
See:
Creates a UI Extension
Example
const contentful = require('contentful-management')

const client = contentful.createClient({
  accessToken: '<content_management_api_key>'
})

client.getSpace('<space_id>')
.then((space) => space.createUiExtension({
  extension: {
    name: 'My awesome extension',
    src: 'https://example.com/my',
    fieldTypes: [
      {
        type: 'Symbol'
      },
      {
        type: 'Text'
      }
    ],
    sidebar: false
  }
}))
.then((uiExtension) => console.log(uiExtension))
.catch(console.error)
Parameters:
Name Type Description
data object Object representation of the UI Extension to be created
Returns:
Promise for the newly created UI Extension
Type
Promise.<UiExtension.UiExtension>

(static) createUiExtensionWithId(id, data) → {Promise.<UiExtension.UiExtension>}

Source:
Deprecated:
  • since version 5.0
See:
Creates a UI Extension with a custom ID
Example
const contentful = require('contentful-management')

const client = contentful.createClient({
  accessToken: '<content_management_api_key>'
})

client.getSpace('<space_id>')
.then((space) => space.createUiExtensionWithId('<extension_id>', {
  extension: {
    name: 'My awesome extension',
    src: 'https://example.com/my',
    fieldTypes: [
      {
        type: 'Symbol'
      },
      {
        type: 'Text'
      }
    ],
    sidebar: false
  }
}))
.then((uiExtension) => console.log(uiExtension))
.catch(console.error)
Parameters:
Name Type Description
id string UI Extension ID
data object Object representation of the UI Extension to be created
Returns:
Promise for the newly created UI Extension
Type
Promise.<UiExtension.UiExtension>

(static) createUpload(data) → {Promise.<Upload>}

Source:
Deprecated:
  • since version 5.0
Creates a Upload.
Example
const client = contentful.createClient({
  accessToken: '<content_management_api_key>'
})
const uploadStream = createReadStream('path/to/filename_english.jpg')
client.getSpace('<space_id>')
.then((space) => space.createUpload({file: uploadStream, 'image/png'})
.then((upload) => console.log(upload))
.catch(console.error)
Parameters:
Name Type Description
data object Object with file information.
Properties
Name Type Description
file object Actual file content. Can be a string, an ArrayBuffer or a Stream.
Returns:
Upload object containing information about the uploaded file.
Type
Promise.<Upload>

(static) createWebhook(data) → {Promise.<Webhook.Webhook>}

Source:
See:
Creates a Webhook
Example
const contentful = require('contentful-management')

client.getSpace('<space_id>')
.then((space) => space.createWebhook({
  'name': 'My webhook',
  'url': 'https://www.example.com/test',
  'topics': [
    'Entry.create',
    'ContentType.create',
    '*.publish',
    'Asset.*'
  ]
}))
.then((webhook) => console.log(webhook))
.catch(console.error)
Parameters:
Name Type Description
data object Object representation of the Webhook to be created
Returns:
Promise for the newly created Webhook
Type
Promise.<Webhook.Webhook>

(static) createWebhookWithId(id, data) → {Promise.<Webhook.Webhook>}

Source:
See:
Creates a Webhook with a custom ID
Example
const contentful = require('contentful-management')

client.getSpace('<space_id>')
.then((space) => space.createWebhookWithId('<webhook_id>', {
  'name': 'My webhook',
  'url': 'https://www.example.com/test',
  'topics': [
    'Entry.create',
    'ContentType.create',
    '*.publish',
    'Asset.*'
  ]
}))
.then((webhook) => console.log(webhook))
.catch(console.error)
Parameters:
Name Type Description
id string Webhook ID
data object Object representation of the Webhook to be created
Returns:
Promise for the newly created Webhook
Type
Promise.<Webhook.Webhook>

(static) getApiKey(id) → {Promise.<ApiKey.ApiKey>}

Source:
Gets a Api Key
Example
const contentful = require('contentful-management')

const client = contentful.createClient({
  accessToken: '<content_management_api_key>'
})

client.getSpace('<space_id>')
.then((space) => space.getApiKey('<apikey-id>'))
.then((apikey) => console.log(apikey))
.catch(console.error)
Parameters:
Name Type Description
id string API Key ID
Returns:
Promise for a Api Key
Type
Promise.<ApiKey.ApiKey>

(static) getApiKeys() → {Promise.<ApiKey.ApiKeyCollection>}

Source:
Gets a collection of Api Keys
Example
const contentful = require('contentful-management')

const client = contentful.createClient({
  accessToken: '<content_management_api_key>'
})

client.getSpace('<space_id>')
.then((space) => space.getApiKeys())
.then((response) => console.log(response.items))
.catch(console.error)
Returns:
Promise for a collection of Api Keys
Type
Promise.<ApiKey.ApiKeyCollection>

(static) getAsset(id, queryopt) → {Promise.<Asset.Asset>}

Source:
Deprecated:
  • since version 5.0
Gets an Asset Warning: if you are using the select operator, when saving, any field that was not selected will be removed from your entry in the backend
Example
const contentful = require('contentful-management')

const client = contentful.createClient({
  accessToken: '<content_management_api_key>'
})

client.getSpace('<space_id>')
.then((space) => space.getAsset('<asset_id>'))
.then((asset) => console.log(asset))
.catch(console.error)
Parameters:
Name Type Attributes Description
id string Asset ID
query object <optional>
Object with search parameters. In this method it's only useful for `locale`.
Returns:
Promise for an Asset
Type
Promise.<Asset.Asset>

(static) getAssets(queryopt) → {Promise.<Asset.AssetCollection>}

Source:
Deprecated:
  • since version 5.0
Gets a collection of Assets Warning: if you are using the select operator, when saving, any field that was not selected will be removed from your entry in the backend
Example
const contentful = require('contentful-management')

const client = contentful.createClient({
  accessToken: '<content_management_api_key>'
})

client.getSpace('<space_id>')
.then((space) => space.getAssets())
.then((response) => console.log(response.items))
.catch(console.error)
Parameters:
Name Type Attributes Description
query object <optional>
Object with search parameters. Check the JS SDK tutorial and the REST API reference for more details.
Returns:
Promise for a collection of Assets
Type
Promise.<Asset.AssetCollection>

(static) getContentType(id) → {Promise.<ContentType.ContentType>}

Source:
Deprecated:
  • since version 5.0
Gets a Content Type
Example
const contentful = require('contentful-management')

const client = contentful.createClient({
  accessToken: '<content_management_api_key>'
})

client.getSpace('<space_id>')
.then((space) => space.getContentType('<content_type_id>'))
.then((contentType) => console.log(contentType))
.catch(console.error)
Parameters:
Name Type Description
id string Content Type ID
Returns:
Promise for a Content Type
Type
Promise.<ContentType.ContentType>

(static) getContentTypes(queryopt) → {Promise.<ContentType.ContentTypeCollection>}

Source:
Deprecated:
  • since version 5.0
Gets a collection of Content Types
Example
const contentful = require('contentful-management')

const client = contentful.createClient({
  accessToken: '<content_management_api_key>'
})

client.getSpace('<space_id>')
.then((space) => space.getContentTypes())
.then((response) => console.log(response.items))
.catch(console.error)
Parameters:
Name Type Attributes Description
query object <optional>
Object with search parameters. Check the JS SDK tutorial and the REST API reference for more details.
Returns:
Promise for a collection of Content Types
Type
Promise.<ContentType.ContentTypeCollection>

(static) getContentTypeSnapshots(contentTypeId, queryopt) → {Promise.<Snapshot.SnapshotCollection>}

Source:
Deprecated:
  • since version 5.0
Gets all snapshots of a contentType
Example
const contentful = require('contentful-management')

const client = contentful.createClient({
  accessToken: '<content_management_api_key>'
})

client.getSpace('<space_id>')
.then((space) => space.getContentTypeSnapshots('<contentTypeId>'))
.then((snapshots) => console.log(snapshots.items))
.catch(console.error)
Parameters:
Name Type Attributes Description
contentTypeId string Content Type ID
query object <optional>
additional query paramaters
Returns:
Promise for a collection of Content Type Snapshots
Type
Promise.<Snapshot.SnapshotCollection>

(static) getEditorInterfaceForContentType(contentTypeId) → {Promise.<EditorInterface.EditorInterface>}

Source:
Deprecated:
  • since version 5.0
Gets an EditorInterface for a ContentType
Example
const contentful = require('contentful-management')

const client = contentful.createClient({
  accessToken: '<content_management_api_key>'
})

client.getSpace('<space_id>')
.then((space) => space.getEditorInterfaceForContentType('<content_type_id>'))
.then((EditorInterface) => console.log(EditorInterface))
.catch(console.error)
Parameters:
Name Type Description
contentTypeId string Content Type ID
Returns:
Promise for an EditorInterface
Type
Promise.<EditorInterface.EditorInterface>

(static) getEntry(id, queryopt) → {Promise.<Entry.Entry>}

Source:
Deprecated:
  • since version 5.0
Gets an Entry Warning: if you are using the select operator, when saving, any field that was not selected will be removed from your entry in the backend
Example
const contentful = require('contentful-management')

const client = contentful.createClient({
  accessToken: '<content_management_api_key>'
})

client.getSpace('<space_id>')
.then((space) => space.getEntry('<entry-id>'))
.then((entry) => console.log(entry))
.catch(console.error)
Parameters:
Name Type Attributes Description
id string Entry ID
query object <optional>
Object with search parameters. In this method it's only useful for `locale`.
Returns:
Promise for an Entry
Type
Promise.<Entry.Entry>

(static) getEntrySnapshots(entryId, queryopt) → {Promise.<Snapshot.SnapshotCollection>}

Source:
Deprecated:
  • since version 5.0
Gets all snapshots of an entry
Example
const contentful = require('contentful-management')

const client = contentful.createClient({
  accessToken: '<content_management_api_key>'
})

client.getSpace('<space_id>')
.then((space) => space.getEntrySnapshots('<entry_id>'))
.then((snapshots) => console.log(snapshots.items))
.catch(console.error)
Parameters:
Name Type Attributes Description
entryId string Entry ID
query object <optional>
additional query paramaters
Returns:
Promise for a collection of Entry Snapshots
Type
Promise.<Snapshot.SnapshotCollection>

(static) getEnvironment(id) → {Promise.<Environment.Environment>}

Source:
Gets an environment
Example
const contentful = require('contentful-management')

const client = contentful.createClient({
  accessToken: '<content_management_api_key>'
})

client.getSpace('<space_id>')
.then((space) => space.getEnvironment('<environement_id>'))
.then((environment) => console.log(environment))
.catch(console.error)
Parameters:
Name Type Description
id string Environment ID
Returns:
Promise for an Environment
Type
Promise.<Environment.Environment>

(static) getEnvironmentAlias(id) → {Promise.<EnvironmentAlias.EnvironmentAlias>}

Source:
Gets an Environment Alias
Example
const contentful = require('contentful-management')

const client = contentful.createClient({
  accessToken: '<content_management_api_key>'
})

client.getSpace('<space_id>')
.then((space) => space.getEnvironmentAlias('<alias-id>'))
.then((alias) => console.log(alias))
.catch(console.error)
Parameters:
Name Type Description
id string Environment Alias ID
Returns:
Promise for an Environment Alias
Type
Promise.<EnvironmentAlias.EnvironmentAlias>

(static) getEnvironmentAliases() → {Promise.<EnvironmentAlias.EnvironmentAliasCollection>}

Source:
Gets a collection of Environment Aliases
Example
const contentful = require('contentful-management')

const client = contentful.createClient({
  accessToken: '<content_management_api_key>'
})

client.getSpace('<space_id>')
.then((space) => space.getEnvironmentAliases()
.then((response) => console.log(response.items))
.catch(console.error)
Returns:
Promise for a collection of Environment Aliases
Type
Promise.<EnvironmentAlias.EnvironmentAliasCollection>

(static) getEnvironments() → {Promise.<Environment.EnvironmentCollection>}

Source:
Gets a collection of Environments
Example
const contentful = require('contentful-management')

const client = contentful.createClient({
  accessToken: '<content_management_api_key>'
})

client.getSpace('<space_id>')
.then((space) => space.getEnvironments())
.then((response) => console.log(response.items))
.catch(console.error)
Returns:
Promise for a collection of Environment
Type
Promise.<Environment.EnvironmentCollection>

(static) getLocale(id) → {Promise.<Locale.Locale>}

Source:
Deprecated:
  • since version 5.0
Gets a Locale
Example
const contentful = require('contentful-management')

const client = contentful.createClient({
  accessToken: '<content_management_api_key>'
})

client.getSpace('<space_id>')
.then((space) => space.getLocale('<locale_id>'))
.then((locale) => console.log(locale))
.catch(console.error)
Parameters:
Name Type Description
id string Locale ID
Returns:
Promise for an Locale
Type
Promise.<Locale.Locale>

(static) getLocales() → {Promise.<Locale.LocaleCollection>}

Source:
Deprecated:
  • since version 5.0
Gets a collection of Locales
Example
const contentful = require('contentful-management')

const client = contentful.createClient({
  accessToken: '<content_management_api_key>'
})

client.getSpace('<space_id>')
.then((space) => space.getLocales())
.then((response) => console.log(response.items))
.catch(console.error)
Returns:
Promise for a collection of Locales
Type
Promise.<Locale.LocaleCollection>

(static) getPreviewApiKey(id) → {Promise.<PreviewApiKey.PreviewApiKey>}

Source:
Gets a preview Api Key
Example
const contentful = require('contentful-management')

const client = contentful.createClient({
  accessToken: '<content_management_api_key>'
})

client.getSpace('<space_id>')
.then((space) => space.getPreviewApiKey('<preview-apikey-id>'))
.then((previewApikey) => console.log(previewApikey))
.catch(console.error)
Parameters:
Name Type Description
id string Preview API Key ID
Returns:
Promise for a Preview Api Key
Type
Promise.<PreviewApiKey.PreviewApiKey>

(static) getPreviewApiKeys() → {Promise.<PreviewApiKey.PreviewApiKeyCollection>}

Source:
Gets a collection of preview Api Keys
Example
const contentful = require('contentful-management')

const client = contentful.createClient({
  accessToken: '<content_management_api_key>'
})

client.getSpace('<space_id>')
.then((space) => space.getPreviewApiKeys())
.then((response) => console.log(response.items))
.catch(console.error)
Returns:
Promise for a collection of Preview Api Keys
Type
Promise.<PreviewApiKey.PreviewApiKeyCollection>

(static) getRole(id) → {Promise.<Role.Role>}

Source:
Gets a Role
Example
const contentful = require('contentful-management')

const client = contentful.createClient({
  accessToken: '<content_management_api_key>'
})

client.getSpace('<space_id>')
.then((space) => space.createRole({
  fields: {
    title: {
      'en-US': 'Role title'
    }
  }
}))
.then((role) => console.log(role))
.catch(console.error)
Parameters:
Name Type Description
id string Role ID
Returns:
Promise for a Role
Type
Promise.<Role.Role>

(static) getRoles() → {Promise.<Role.RoleCollection>}

Source:
Gets a collection of Roles
Example
const contentful = require('contentful-management')

const client = contentful.createClient({
  accessToken: '<content_management_api_key>'
})

client.getSpace('<space_id>')
.then((space) => space.getRoles())
.then((response) => console.log(response.items))
.catch(console.error)
Returns:
Promise for a collection of Roles
Type
Promise.<Role.RoleCollection>

(static) getSpaceMember(idopt) → {Promise.<SpaceMember.SpaceMember>}

Source:
Gets a Space Member
Example
const contentful = require('contentful-management')

client.getSpace('<space_id>')
.then((space) => space.getSpaceMember(id))
.then((spaceMember) => console.log(spaceMember))
.catch(console.error)
Parameters:
Name Type Attributes Description
id object <optional>
Get Space Member by user_id
Returns:
Promise for a Space Member
Type
Promise.<SpaceMember.SpaceMember>

(static) getSpaceMembers(queryopt) → {Promise.<SpaceMember.SpaceMemberCollection>}

Source:
Gets a collection of Space Members
Example
const contentful = require('contentful-management')

client.getSpace('<space_id>')
.then((space) => space.getSpaceMembers({'limit': 100}))
.then((spaceMemberCollection) => console.log(spaceMemberCollection))
.catch(console.error)
Parameters:
Name Type Attributes Description
query object <optional>
Returns:
Promise for a collection of Space Members
Type
Promise.<SpaceMember.SpaceMemberCollection>

(static) getSpaceMembership(id) → {Promise.<SpaceMembership.SpaceMembership>}

Source:
Gets a Space Membership Warning: the user attribute in the space membership root is deprecated. The attribute has been moved inside the sys object (i.e. sys.user).
Example
const contentful = require('contentful-management')

client.getSpace('<space_id>')
.then((space) => space.getSpaceMembership('id'))
.then((spaceMembership) => console.log(spaceMembership))
.catch(console.error)
Parameters:
Name Type Description
id string Space Membership ID
Returns:
Promise for a Space Membership
Type
Promise.<SpaceMembership.SpaceMembership>

(static) getSpaceMemberships(queryopt) → {Promise.<SpaceMembership.SpaceMembershipCollection>}

Source:
Gets a collection of Space Memberships Warning: the user attribute in the space membership root is deprecated. The attribute has been moved inside the sys object (i.e. sys.user).
Example
const contentful = require('contentful-management')

client.getSpace('<space_id>')
.then((space) => space.getSpaceMemberships({'limit': 100})) // you can add more queries as 'key': 'value'
.then((response) => console.log(response.items))
.catch(console.error)
Parameters:
Name Type Attributes Description
query object <optional>
Object with search parameters. Check the JS SDK tutorial and the REST API reference for more details.
Returns:
Promise for a collection of Space Memberships
Type
Promise.<SpaceMembership.SpaceMembershipCollection>

(static) getSpaceUser(id) → {Promise.<User.User>}

Source:
Gets a User
Example
const contentful = require('contentful-management')

client.getSpace('<space_id>')
.then((space) => space.getSpaceUser('id'))
.then((user) => console.log(user))
.catch(console.error)
Parameters:
Name Type Description
id string User ID
Returns:
Promise for a User
Type
Promise.<User.User>

(static) getSpaceUsers(queryopt) → {Promise.<User.UserCollection>}

Source:
Gets a collection of Users in a space
Example
const contentful = require('contentful-management')

client.getSpace('<space_id>')
.then((space) => space.getSpaceUsers(query))
.then((data) => console.log(data))
.catch(console.error)
Parameters:
Name Type Attributes Description
query object <optional>
Object with search parameters. Check the JS SDK tutorial and the REST API reference for more details.
Returns:
Promise a collection of Users in a space
Type
Promise.<User.UserCollection>

(static) getTeamSpaceMembership(id) → {Promise.<TeamSpaceMembership.TeamSpaceMembership>}

Source:
Gets a Team Space Membership
Example
const contentful = require('contentful-management')

client.getSpace('<space_id>')
.then((space) => space.getTeamSpaceMembership('team_space_membership_id'))
.then((teamSpaceMembership) => console.log(teamSpaceMembership))
.catch(console.error)
Parameters:
Name Type Description
id string Team Space Membership ID
Returns:
Promise for a Team Space Membership
Type
Promise.<TeamSpaceMembership.TeamSpaceMembership>

(static) getTeamSpaceMemberships(queryopt) → {Promise.<TeamSpaceMembership.TeamSpaceMembershipCollection>}

Source:
Gets a collection of Team Space Memberships
Example
const contentful = require('contentful-management')

client.getSpace('<space_id>')
.then((space) => space.getTeamSpaceMemberships())
.then((response) => console.log(response.items))
.catch(console.error)
Parameters:
Name Type Attributes Description
query object <optional>
Object with search parameters. Check the JS SDK tutorial and the REST API reference for more details.
Returns:
Promise for a collection of Team Space Memberships
Type
Promise.<TeamSpaceMembership.TeamSpaceMembershipCollection>

(static) getUiExtension(id) → {Promise.<UiExtension.UiExtension>}

Source:
Deprecated:
  • since version 5.0
Gets an UI Extension
Example
const contentful = require('contentful-management')

const client = contentful.createClient({
  accessToken: '<content_management_api_key>'
})

client.getSpace('<space_id>')
.then((space) => space.getUiExtension('<extension-id>'))
.then((uiExtension) => console.log(uiExtension))
.catch(console.error)
Parameters:
Name Type Description
id string UI Extension ID
Returns:
Promise for an UI Extension
Type
Promise.<UiExtension.UiExtension>

(static) getUiExtensions() → {Promise.<UiExtension.UiExtensionCollection>}

Source:
Deprecated:
  • since version 5.0
Gets a collection of UI Extension
Example
const contentful = require('contentful-management')

const client = contentful.createClient({
  accessToken: '<content_management_api_key>'
})

client.getSpace('<space_id>')
.then((space) => space.getUiExtensions()
.then((response) => console.log(response.items))
.catch(console.error)
Returns:
Promise for a collection of UI Extensions
Type
Promise.<UiExtension.UiExtensionCollection>

(static) getUpload(id) → {Promise.<Upload>}

Source:
Deprecated:
  • since version 5.0
Gets an Upload
Example
const client = contentful.createClient({
  accessToken: '<content_management_api_key>'
})
const uploadStream = createReadStream('path/to/filename_english.jpg')
client.getSpace('<space_id>')
.then((space) => space.getUpload('<upload-id>')
.then((upload) => console.log(upload))
.catch(console.error)
Parameters:
Name Type Description
id string Upload ID
Returns:
Promise for an Upload
Type
Promise.<Upload>

(static) getWebhook(id) → {Promise.<Webhook.Webhook>}

Source:
Gets a Webhook
Example
const contentful = require('contentful-management')

const client = contentful.createClient({
  accessToken: '<content_management_api_key>'
})

client.getSpace('<space_id>')
.then((space) => space.getWebhook('<webhook_id>'))
.then((webhook) => console.log(webhook))
.catch(console.error)
Parameters:
Name Type Description
id string Webhook ID
Returns:
Promise for a Webhook
Type
Promise.<Webhook.Webhook>

(static) getWebhooks() → {Promise.<Webhook.WebhookCollection>}

Source:
Gets a collection of Webhooks
Example
const contentful = require('contentful-management')

const client = contentful.createClient({
  accessToken: '<content_management_api_key>'
})

client.getSpace('<space_id>')
.then((space) => space.getWebhooks())
.then((response) => console.log(response.items))
.catch(console.error)
Returns:
Promise for a collection of Webhooks
Type
Promise.<Webhook.WebhookCollection>