getProjectId

The getProjectId method is responsible for returning a unique identifier for the content source instance among other instances of the same type.

Return Value

The getProjectId method should return a unique identifier for the content source instance, which must be distinct from other instances of the same content source type within a project.

The pair of values returned by this method, along with the getContentSourceType method, should be unique among other content source instances in the same project.

Examples

If your content source can support multiple projects and the content source instance is configured to work with a specific project, you can return the ID of that project using the getProjectId method. In such cases, it is recommended to include the project ID in the constructor options.

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
import type { ContentSourceInterface } from '@stackbit/types'

export interface ContentSourceOptions {
  projectId: string
}

export class MyContentSource implements ContentSourceInterface {
  private readonly projectId: string

  constructor(options) {
    this.projectId = options.projectId
  }

  getContentSourceType(): string {
    return 'my_content_source'
  }

  getProjectId(): string {
    return this.projectId
  }

  // other methods ...
}

If your content source operates on a singular set of data, you can return a constant string as the project ID.

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
import type { ContentSourceInterface } from '@stackbit/types'

export class MyContentSource implements ContentSourceInterface {
  getContentSourceType(): string {
    return 'my_content_source'
  }

  getProjectId(): string {
    return 'const_id'
  }

  // other methods ...
}