In Segment, you create a Source (or more than one!) for each website or app you want to track. While it’s not required that you have a single Source for each server, site or app, Segment recommends that you create a Source for each unique source of data.
Like the Segment Public API, the Config API has one endpoint to retrieve details about a Workspace. The getSource endpoint returns the following fields:
Config API | Public API |
---|---|
name |
See note on names vs IDs in the migration guide |
name |
slug (workspace/ prefix removed) |
display_name |
name |
create_time |
None |
To migrate, replace any use of the Config API endpoints with the Segment Public API counterparts, using the field mappings in the table above.
Adds an existing label to a Source.
• When called, this endpoint may generate the Source Modified
event in the audit trail.
OK
Resource not found
Validation failure
Too many requests
{- "labels": [
- {
- "key": "type",
- "value": "web"
}
]
}
{- "data": {
- "labels": [
- {
- "key": "type",
- "value": "web"
}, - {
- "key": "environment",
- "value": "prod"
}
]
}
}
Replaces all labels in a Source.
OK
Resource not found
Validation failure
Too many requests
{- "labels": [
- {
- "key": "environment",
- "value": "prod"
}
]
}
{- "data": {
- "labels": [
- {
- "key": "environment",
- "value": "prod"
}
]
}
}
Creates a new Source.
• When called, this endpoint may generate the Source Created
event in the audit trail.
Created
Resource not found
Validation failure
Too many requests
{- "slug": "my-test-source-s3_e9_",
- "enabled": true,
- "metadataId": "IqDTy1TpoU",
- "settings": { }
}
{- "data": {
- "source": {
- "id": "5BKZVyYHdt1D7ZrtHyNR7W",
- "slug": "my-test-source-s3_e9_",
- "name": "my-test-source-s3_e9_",
- "workspaceId": "9aQ1Lj62S4bomZKLF4DPqW",
- "enabled": true,
- "writeKeys": [
- "0j4zjt3VGSKQ1rNDXXaEPM7Tnbg0V55K"
], - "metadata": {
- "id": "IqDTy1TpoU",
- "slug": "javascript",
- "name": "Javascript",
- "categories": [
- "Website"
], - "description": "This is our most flexible and powerful tracking system, using analytics.js. Track and analyze information about your visitors and customers, and every action that they take, in any of our 140 integrations, business intelligence tools, or directly with SQL tools.",
- "logos": {
}, - "options": [ ],
- "isCloudEventSource": false
}, - "settings": { },
- "labels": [ ]
}
}
}
Returns a list of Sources.
object (PaginationInput) Defines the pagination parameters. This parameter exists in alpha. Example: pagination=pagination.count=2 |
OK
Resource not found
Validation failure
Too many requests
import { configureApis, unwrap } from '@segment/public-api-sdk-typescript' const api = configureApis('/* Insert your Public API token here */') try { const result = await unwrap(api.sources.listSources()) console.log(JSON.stringify(result)) } catch (e) { console.log('ERROR:', e) }
{- "data": {
- "sources": [
- {
- "id": "qQEHquLrjRDN9j1ByrChyn",
- "slug": "swift",
- "name": "",
- "workspaceId": "9aQ1Lj62S4bomZKLF4DPqW",
- "enabled": true,
- "writeKeys": [
- "bEj5MzDqCkHYRqreZgbPuH"
], - "metadata": {
- "id": "dZeHygTSD4",
- "slug": "swift",
- "name": "Apple",
- "categories": [
- "Mobile"
], - "description": "The hassle-free way to add Segment analytics to your swift app (iOS, macOS, tvOS).",
- "logos": {
}, - "options": [ ],
- "isCloudEventSource": false
}, - "settings": { },
- "labels": [ ]
}, - {
- "id": "rh5BDZp6QDHvXFCkibm1pR",
- "slug": "web",
- "name": "",
- "workspaceId": "9aQ1Lj62S4bomZKLF4DPqW",
- "enabled": true,
- "writeKeys": [
- "dfL8upyPumumx23SjgwHjs"
], - "metadata": {
- "id": "IqDTy1TpoU",
- "slug": "javascript",
- "name": "Javascript",
- "categories": [
- "Website"
], - "description": "This is our most flexible and powerful tracking system, using analytics.js. Track and analyze information about your visitors and customers, and every action that they take, in any of our 140 integrations, business intelligence tools, or directly with SQL tools.",
- "logos": {
}, - "options": [ ],
- "isCloudEventSource": false
}, - "settings": { },
- "labels": [ ]
}
], - "pagination": {
- "current": "MA==",
- "totalEntries": 2
}
}
}
Creates a new Write Key for the Source.
• When called, this endpoint may generate the Source Modified
event in the audit trail.
OK
Resource not found
Validation failure
Too many requests
import { configureApis, unwrap } from '@segment/public-api-sdk-typescript' const api = configureApis('/* Insert your Public API token here */') try { const result = await unwrap(api.sources.createWriteKeyForSource('idR4zzU9iGcGJgoAX891nf')) console.log(JSON.stringify(result)) } catch (e) { console.log('ERROR:', e) }
{- "data": {
- "source": {
- "id": "idR4zzU9iGcGJgoAX891nf",
- "slug": "update-source-slug-ymbehd",
- "name": "update-source-slug-ymbehd",
- "workspaceId": "9aQ1Lj62S4bomZKLF4DPqW",
- "enabled": true,
- "writeKeys": [
- "kXjAavdaGFdiF6or2A6CmohtlFnuTNFJ",
- "wk123"
], - "metadata": {
- "id": "IqDTy1TpoU",
- "slug": "javascript",
- "name": "Javascript",
- "categories": [
- "Website"
], - "description": "This is our most flexible and powerful tracking system, using analytics.js. Track and analyze information about your visitors and customers, and every action that they take, in any of our 140 integrations, business intelligence tools, or directly with SQL tools.",
- "logos": {
}, - "options": [ ],
- "isCloudEventSource": false
}, - "settings": { },
- "labels": [ ]
}
}
}
Deletes an existing Source.
• When called, this endpoint may generate the Source Deleted
event in the audit trail.
OK
Resource not found
Validation failure
Too many requests
import { configureApis, unwrap } from '@segment/public-api-sdk-typescript' const api = configureApis('/* Insert your Public API token here */') try { const result = await unwrap(api.sources.deleteSource('rYxTjyaPtAELCjnFE5EYfM')) console.log(JSON.stringify(result)) } catch (e) { console.log('ERROR:', e) }
{- "data": {
- "status": "SUCCESS"
}
}
Returns a Source by its id.
OK
Resource not found
Validation failure
Too many requests
import { configureApis, unwrap } from '@segment/public-api-sdk-typescript' const api = configureApis('/* Insert your Public API token here */') try { const result = await unwrap(api.sources.getSource('qQEHquLrjRDN9j1ByrChyn')) console.log(JSON.stringify(result)) } catch (e) { console.log('ERROR:', e) }
{- "data": {
- "source": {
- "id": "qQEHquLrjRDN9j1ByrChyn",
- "slug": "swift",
- "name": "",
- "workspaceId": "9aQ1Lj62S4bomZKLF4DPqW",
- "enabled": true,
- "writeKeys": [
- "bEj5MzDqCkHYRqreZgbPuH"
], - "metadata": {
- "id": "dZeHygTSD4",
- "slug": "swift",
- "name": "Apple",
- "categories": [
- "Mobile"
], - "description": "The hassle-free way to add Segment analytics to your swift app (iOS, macOS, tvOS).",
- "logos": {
}, - "options": [ ],
- "isCloudEventSource": false
}, - "settings": { },
- "labels": [ ]
}, - "trackingPlanId": null
}
}
Updates an existing Source.
• When called, this endpoint may generate one or more of the following audit trail events:* Source Modified
Config API omitted fields:
updateMask
OK
Resource not found
Validation failure
Too many requests
{- "name": "My updated source",
- "enabled": false
}
{- "data": {
- "source": {
- "id": "unVUQvuR3SsyiQibd8M91V",
- "slug": "update-source-slug-azff9s",
- "name": "My updated source",
- "workspaceId": "9aQ1Lj62S4bomZKLF4DPqW",
- "enabled": false,
- "writeKeys": [
- "WQROIu5oTBbq8acxk6QC6yzMIqEL4oD2"
], - "metadata": {
- "id": "IqDTy1TpoU",
- "slug": "javascript",
- "name": "Javascript",
- "categories": [
- "Website"
], - "description": "This is our most flexible and powerful tracking system, using analytics.js. Track and analyze information about your visitors and customers, and every action that they take, in any of our 140 integrations, business intelligence tools, or directly with SQL tools.",
- "logos": {
}, - "options": [ ],
- "isCloudEventSource": false
}, - "settings": { },
- "labels": [ ]
}
}
}
Returns a list of Destinations connected to a Source.
OK
Resource not found
Validation failure
Too many requests
import { configureApis, unwrap } from '@segment/public-api-sdk-typescript' const api = configureApis('/* Insert your Public API token here */') try { const result = await unwrap(api.sources.listConnectedDestinationsFromSource('qQEHquLrjRDN9j1ByrChyn')) console.log(JSON.stringify(result)) } catch (e) { console.log('ERROR:', e) }
{- "data": {
- "destinations": [ ],
- "pagination": {
- "current": "MQ==",
- "totalEntries": 0
}
}
}
Returns a list of Warehouses connected to a Source.
OK
Resource not found
Validation failure
Too many requests
import { configureApis, unwrap } from '@segment/public-api-sdk-typescript' const api = configureApis('/* Insert your Public API token here */') try { const result = await unwrap(api.sources.listConnectedWarehousesFromSource('qQEHquLrjRDN9j1ByrChyn')) console.log(JSON.stringify(result)) } catch (e) { console.log('ERROR:', e) }
{- "data": {
- "warehouses": [
- {
- "id": "kjU72LCJexvrqL7G4TMHHN",
- "workspaceId": "9aQ1Lj62S4bomZKLF4DPqW",
- "enabled": true,
- "metadata": {
- "id": "55d3d3aea3c",
- "slug": "postgres",
- "name": "Postgres",
- "description": "Open source data warehouse",
- "logos": {
- "mark": "",
- "alt": ""
}, - "options": [
- {
- "name": "port",
- "required": true,
- "type": "string"
}, - {
- "name": "database",
- "required": true,
- "type": "string"
}, - {
- "name": "hostname",
- "required": true,
- "type": "string"
}, - {
- "name": "password",
- "required": true,
- "type": "string"
}, - {
- "name": "username",
- "required": true,
- "type": "string"
}, - {
- "name": "ciphertext",
- "required": true,
- "type": "string"
}
]
}, - "settings": { }
}, - {
- "id": "v1e6FCE8P9EvQmCLWpKtJ3",
- "workspaceId": "9aQ1Lj62S4bomZKLF4DPqW",
- "enabled": true,
- "metadata": {
- "id": "aea3c55dsz",
- "slug": "redshift",
- "name": "Redshift",
- "description": "Powered by Amazon Web Services",
- "logos": {
- "mark": "",
- "alt": ""
}, - "options": [
- {
- "name": "port",
- "required": true,
- "type": "string"
}, - {
- "name": "database",
- "required": true,
- "type": "string"
}, - {
- "name": "hostname",
- "required": true,
- "type": "string"
}, - {
- "name": "password",
- "required": true,
- "type": "string"
}, - {
- "name": "username",
- "required": true,
- "type": "string"
}, - {
- "name": "ciphertext",
- "required": true,
- "type": "string"
}
]
}, - "settings": { }
}
], - "pagination": {
- "current": "MA==",
- "totalEntries": 2
}
}
}
Retrieves the schema configuration settings for a Source. If Protocols is not enabled for the Source, the configurations specific to Protocols will have default values.
OK
Resource not found
Validation failure
Too many requests
import { configureApis, unwrap } from '@segment/public-api-sdk-typescript' const api = configureApis('/* Insert your Public API token here */') try { const result = await unwrap(api.sources.listSchemaSettingsInSource('qQEHquLrjRDN9j1ByrChyn')) console.log(JSON.stringify(result)) } catch (e) { console.log('ERROR:', e) }
{- "data": {
- "sourceId": "qQEHquLrjRDN9j1ByrChyn",
- "settings": {
- "track": {
- "allowUnplannedEvents": true,
- "allowUnplannedEventProperties": true,
- "allowEventOnViolations": false,
- "allowPropertiesOnViolations": true,
- "commonEventOnViolations": "ALLOW"
}, - "group": {
- "allowTraitsOnViolations": true,
- "allowUnplannedTraits": true,
- "commonEventOnViolations": "ALLOW"
}, - "identify": {
- "allowTraitsOnViolations": true,
- "allowUnplannedTraits": true,
- "commonEventOnViolations": "ALLOW"
}, - "forwardingBlockedEventsTo": "",
- "forwardingViolationsTo": ""
}
}
}
Updates the schema configuration for a Source. If Protocols is not enabled for the Source, any updates to Protocols-specific configurations will not be applied.
Config API omitted fields:
updateMask
OK
Resource not found
Validation failure
Too many requests
{- "group": {
- "allowTraitsOnViolations": false,
- "allowUnplannedTraits": false,
- "commonEventOnViolations": "ALLOW"
}, - "identify": {
- "allowTraitsOnViolations": true,
- "allowUnplannedTraits": true,
- "commonEventOnViolations": "BLOCK"
}, - "track": {
- "allowEventOnViolations": false,
- "allowPropertiesOnViolations": false,
- "allowUnplannedEventProperties": false,
- "allowUnplannedEvents": false,
- "commonEventOnViolations": "OMIT_PROPERTIES"
}, - "forwardingViolationsTo": "rh5BDZp6QDHvXFCkibm1pR",
- "forwardingBlockedEventsTo": "rh5BDZp6QDHvXFCkibm1pR"
}
{- "data": {
- "sourceId": "qQEHquLrjRDN9j1ByrChyn",
- "settings": {
- "track": {
- "allowUnplannedEvents": false,
- "allowUnplannedEventProperties": false,
- "allowEventOnViolations": false,
- "allowPropertiesOnViolations": false,
- "commonEventOnViolations": "OMIT_PROPERTIES"
}, - "group": {
- "allowTraitsOnViolations": false,
- "allowUnplannedTraits": false,
- "commonEventOnViolations": "ALLOW"
}, - "identify": {
- "allowTraitsOnViolations": true,
- "allowUnplannedTraits": true,
- "commonEventOnViolations": "BLOCK"
}, - "forwardingBlockedEventsTo": "rh5BDZp6QDHvXFCkibm1pR",
- "forwardingViolationsTo": "rh5BDZp6QDHvXFCkibm1pR"
}
}
}
Removes a Write Key from a Source.
• When called, this endpoint may generate the Source Modified
event in the audit trail.
OK
Resource not found
Validation failure
Too many requests
import { configureApis, unwrap } from '@segment/public-api-sdk-typescript' const api = configureApis('/* Insert your Public API token here */') try { const result = await unwrap(api.sources.removeWriteKeyFromSource('idR4zzU9iGcGJgoAX891nf', 'wk123')) console.log(JSON.stringify(result)) } catch (e) { console.log('ERROR:', e) }
{- "data": {
- "status": "SUCCESS"
}
}