Functions let you create your own Sources and Destinations directly within your Workspace to bring new types of data into Segment and send data to new tools with JavaScript - no extra infrastructure required.
The getFunction endpoint returns the following fields:
Config API | Public API |
---|---|
id |
id |
type |
resourceType |
created_at |
createdAt |
created_by |
createdBy |
description |
description |
logo_url |
logoUrl |
catalog_id |
catalogId |
Creates a Function.
• In order to successfully call this endpoint, the specified Workspace needs to have the Functions feature enabled. Please reach out to your customer success manager for more information.
OK
Resource not found
Validation failure
Too many requests
{- "code": "// Learn more about source functions API at https://segment.com/docs/connections/sources/source-functions",
- "settings": [
- {
- "name": "apiKey",
- "label": "api key",
- "type": "STRING",
- "description": "api key",
- "required": false,
- "sensitive": false
}, - {
- "name": "mySecret",
- "label": "my secret key",
- "type": "STRING",
- "description": "secret key",
- "required": false,
- "sensitive": true
}
], - "displayName": "PAPI Source Function",
- "resourceType": "SOURCE",
- "description": "My source function"
}
{- "data": {
- "function": {
- "id": "sfnc_wXzcDGFR3KmjLDrtSawNHf",
- "workspaceId": "9aQ1Lj62S4bomZKLF4DPqW",
- "displayName": "PAPI Source Function",
- "description": "My source function",
- "code": "// Learn more about source functions API at https://segment.com/docs/connections/sources/source-functions",
- "createdAt": "2006-01-02T15:04:05.000Z",
- "createdBy": "sgJDWk3K21k6LE3tLU9nRK",
- "previewWebhookUrl": "",
- "settings": [
- {
- "name": "apiKey",
- "label": "api key",
- "description": "api key",
- "type": "STRING",
- "required": false,
- "sensitive": false
}, - {
- "name": "mySecret",
- "label": "my secret key",
- "description": "secret key",
- "type": "STRING",
- "required": false,
- "sensitive": true
}
], - "buildpack": "",
- "catalogId": "wXzcDGFR3KmjLDrtSawNHf",
- "batchMaxCount": 0,
- "resourceType": "SOURCE"
}
}
}
Lists all Functions in a Workspace.
• In order to successfully call this endpoint, the specified Workspace needs to have the Functions feature enabled. Please reach out to your customer success manager for more information.
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.functions.listFunctions('SOURCE')) console.log(JSON.stringify(result)) } catch (e) { console.log('ERROR:', e) }
{- "data": {
- "functions": [
- {
- "id": "sfnc_wXzcDGFR3KmjLDrtSawNHf",
- "displayName": "PAPI Source Function",
- "description": "My source function",
- "createdAt": "2006-01-02T15:04:05.000Z",
- "createdBy": "sgJDWk3K21k6LE3tLU9nRK",
- "catalogId": "wXzcDGFR3KmjLDrtSawNHf",
- "resourceType": "SOURCE"
}
], - "pagination": {
- "current": "MQ=="
}
}
}
Deploys a Function. Only applicable to Source Function instances.
• In order to successfully call this endpoint, the specified Workspace needs to have the Functions feature enabled. Please reach out to your customer success manager for more information.
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.functions.createFunctionDeployment('sfn_rh5BDZp6QDHvXFCkibm1pR')) console.log(JSON.stringify(result)) } catch (e) { console.log('ERROR:', e) }
{- "data": {
- "functionDeployment": {
- "status": "SUCCESS"
}
}
}
Creates an insert Function instance connected to the given Destination.
• In order to successfully call this endpoint, the specified Workspace needs to have the Functions feature enabled. Please reach out to your customer success manager for more information.
OK
Resource not found
Validation failure
Too many requests
{- "functionId": "76365637324e715a67535831",
- "integrationId": "fP7qoQw2HTWt9WdMr718gn",
- "name": "Example insert function instance",
- "settings": {
- "apiKey": "XYZ"
}
}
{- "data": {
- "insertFunctionInstance": {
- "id": "65c2bdbade6f2d8297f943d5",
- "name": "Example insert function instance",
- "integrationId": "fP7qoQw2HTWt9WdMr718gn",
- "classId": "76365637324e715a67535831",
- "enabled": true,
- "createdAt": "2006-01-02T15:04:05.000Z",
- "updatedAt": "2006-01-02T15:04:05.000Z",
- "settings": {
- "apiKey": "XYZ"
}, - "encryptedSettings": { }
}
}
}
Lists all insert Function instances connected to the given insert Function.
• In order to successfully call this endpoint, the specified Workspace needs to have the Functions feature enabled. Please reach out to your customer success manager for more information.
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.functions.listInsertFunctionInstances('76365637324e715a67535831')) console.log(JSON.stringify(result)) } catch (e) { console.log('ERROR:', e) }
{- "data": {
- "instances": [
- {
- "id": "65c2bdbbde6f2d8297f943d6",
- "name": "Example insert function instance",
- "integrationId": "fP7qoQw2HTWt9WdMr718gn",
- "classId": "76365637324e715a67535831",
- "enabled": true,
- "createdAt": "2006-01-02T15:04:05.000Z",
- "updatedAt": "2006-01-02T15:04:05.000Z",
- "settings": {
- "apiKey": "XYZ"
}, - "encryptedSettings": { }
}
], - "pagination": {
- "current": "MA==",
- "totalEntries": 1
}
}
}
Deletes a Function.
• In order to successfully call this endpoint, the specified Workspace needs to have the Functions feature enabled. Please reach out to your customer success manager for more information.
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.functions.deleteFunction('sfnc_wXzcDGFR3KmjLDrtSawNHf')) console.log(JSON.stringify(result)) } catch (e) { console.log('ERROR:', e) }
{- "data": {
- "status": "SUCCESS"
}
}
Gets a Function.
• In order to successfully call this endpoint, the specified Workspace needs to have the Functions feature enabled. Please reach out to your customer success manager for more information.
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.functions.getFunction('sfnc_wXzcDGFR3KmjLDrtSawNHf')) console.log(JSON.stringify(result)) } catch (e) { console.log('ERROR:', e) }
{- "data": {
- "function": {
- "id": "sfnc_wXzcDGFR3KmjLDrtSawNHf",
- "workspaceId": "9aQ1Lj62S4bomZKLF4DPqW",
- "displayName": "PAPI Source Function",
- "description": "My source function",
- "code": "// Learn more about source functions API at https://segment.com/docs/connections/sources/source-functions",
- "createdAt": "2006-01-02T15:04:05.000Z",
- "createdBy": "sgJDWk3K21k6LE3tLU9nRK",
- "previewWebhookUrl": "",
- "settings": [
- {
- "name": "apiKey",
- "label": "api key",
- "description": "api key",
- "type": "STRING",
- "required": false,
- "sensitive": false
}, - {
- "name": "mySecret",
- "label": "my secret key",
- "description": "secret key",
- "type": "STRING",
- "required": false,
- "sensitive": true
}
], - "buildpack": "",
- "catalogId": "wXzcDGFR3KmjLDrtSawNHf",
- "batchMaxCount": 0,
- "resourceType": "SOURCE"
}
}
}
Updates a Function.
• In order to successfully call this endpoint, the specified Workspace needs to have the Functions feature enabled. Please reach out to your customer success manager for more information.
Config API omitted fields:
updateMask
OK
Resource not found
Validation failure
Too many requests
{- "code": "// Learn more about source functions API at https://segment.com/docs/connections/sources/source-functions",
}
{- "data": {
- "function": {
- "id": "sfnc_wXzcDGFR3KmjLDrtSawNHf",
- "workspaceId": "9aQ1Lj62S4bomZKLF4DPqW",
- "displayName": "PAPI Source Function",
- "description": "My source function",
- "code": "// Learn more about source functions API at https://segment.com/docs/connections/sources/source-functions",
- "createdAt": "2006-01-02T15:04:05.000Z",
- "createdBy": "sgJDWk3K21k6LE3tLU9nRK",
- "previewWebhookUrl": "",
- "settings": [
- {
- "name": "apiKey",
- "label": "api key",
- "description": "api key",
- "type": "STRING",
- "required": false,
- "sensitive": false
}, - {
- "name": "mySecret",
- "label": "my secret key",
- "description": "secret key",
- "type": "STRING",
- "required": false,
- "sensitive": true
}
], - "buildpack": "",
- "catalogId": "wXzcDGFR3KmjLDrtSawNHf",
- "batchMaxCount": 0,
- "resourceType": "SOURCE"
}
}
}
Deletes an insert Function instance.
• In order to successfully call this endpoint, the specified Workspace needs to have the Functions feature enabled. Please reach out to your customer success manager for more information.
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.functions.deleteInsertFunctionInstance('65c2bdbdde6f2d8297f943da')) console.log(JSON.stringify(result)) } catch (e) { console.log('ERROR:', e) }
{- "data": {
- "status": "SUCCESS"
}
}
Gets an insert Function instance.
• In order to successfully call this endpoint, the specified Workspace needs to have the Functions feature enabled. Please reach out to your customer success manager for more information.
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.functions.getInsertFunctionInstance('65c2bdbcde6f2d8297f943d7')) console.log(JSON.stringify(result)) } catch (e) { console.log('ERROR:', e) }
{- "data": {
- "insertFunctionInstance": {
- "id": "65c2bdbcde6f2d8297f943d7",
- "name": "Example insert function instance",
- "integrationId": "fP7qoQw2HTWt9WdMr718gn",
- "classId": "76365637324e715a67535831",
- "enabled": true,
- "createdAt": "2006-01-02T15:04:05.000Z",
- "updatedAt": "2006-01-02T15:04:05.000Z",
- "settings": {
- "apiKey": "XYZ"
}, - "encryptedSettings": { }
}
}
}
Updates an insert Function instance connected to the given Destination.
• In order to successfully call this endpoint, the specified Workspace needs to have the Functions feature enabled. Please reach out to your customer success manager for more information.
OK
Resource not found
Validation failure
Too many requests
{- "enabled": false,
- "settings": {
- "apiKey": "XYZ-new"
}
}
{- "data": {
- "insertFunctionInstance": {
- "id": "65c2bdbcde6f2d8297f943d8",
- "name": "Example insert function instance",
- "integrationId": "fP7qoQw2HTWt9WdMr718gn",
- "classId": "76365637324e715a67535831",
- "enabled": false,
- "createdAt": "2006-01-02T15:04:05.000Z",
- "updatedAt": "2006-01-02T15:04:05.000Z",
- "settings": {
- "apiKey": "XYZ-new"
}, - "encryptedSettings": { }
}
}
}
Gets a Function version.
• In order to successfully call this endpoint, the specified Workspace needs to have the Functions feature enabled. Please reach out to your customer success manager for more information.
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.functions.getFunctionVersion('sfnc_wXzcDGFR3KmjLDrtSawNHf', '2Ma03fahSqLoEzQfV5o2aSfVEHs')) console.log(JSON.stringify(result)) } catch (e) { console.log('ERROR:', e) }
{- "data": {
- "version": {
- "author": "",
- "code": "async function onTrack(event, settings) {console.log('Test')}"
}
}
}
Lists versions for a Function in a Workspace.
• In order to successfully call this endpoint, the specified Workspace needs to have the Functions feature enabled. Please reach out to your customer success manager for more information.
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.functions.listFunctionVersions('sfnc_wXzcDGFR3KmjLDrtSawNHf')) console.log(JSON.stringify(result)) } catch (e) { console.log('ERROR:', e) }
{- "data": {
- "versions": [
- {
- "author": "",
- "code": "async function onTrack(event, settings) {console.log('Test')}"
}, - {
- "author": "",
- "code": "async function onTrack(event, settings) {console.log('Test')}"
}, - {
- "author": "",
- "code": "async function onTrack(event, settings) {console.log('Test')}"
}
], - "pagination": {
- "current": "MQ=="
}
}
}
Restore an old Function version as the latest version.
• In order to successfully call this endpoint, the specified Workspace needs to have the Functions feature enabled. Please reach out to your customer success manager for more information.
OK
Resource not found
Validation failure
Too many requests
{- "versionId": "2Ma03fahSqLoEzQfV5o2aSfVEHs"
}
{- "data": {
- "version": {
- "author": "",
- "code": "async function onTrack(event, settings) {console.log('Test')}"
}
}
}