Functions

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.

Migrate from the Config API

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

Create Function

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.

Securitytoken
Request
Request Body schema:
required
code
required
string (code)

The Function code.

Array of objects (settings)

The list of settings for this Function.

displayName
required
string (displayName)

A display name for this Function.

Note that Destination Functions append the Workspace to the display name.

logoUrl
string (logoUrl)

The URL of the logo for this Function.

resourceType
required
string (resourceType)

The Function type.

Config API note: equal to type.

Enum: "DESTINATION" "INSERT_DESTINATION" "SOURCE"
description
string (description)

A description for this Function.

Responses
200

OK

404

Resource not found

422

Validation failure

429

Too many requests

post/functions
Request samples
{
  • "code": "// Learn more about source functions API at https://segment.com/docs/connections/sources/source-functions",
  • "settings": [
    ],
  • "displayName": "PAPI Source Function",
  • "resourceType": "SOURCE",
  • "description": "My source function"
}
Response samples
{
  • "data": {
    }
}

List Functions

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.

Securitytoken
Request
query Parameters
object (PaginationInput)

Pagination parameters.

This parameter exists in v1.

Example: pagination=pagination.count=10
resourceType
required
string (resourceType)

The Function type.

Config API note: equal to type.

This parameter exists in v1.

Enum: "DESTINATION" "INSERT_DESTINATION" "SOURCE"
Example: resourceType=SOURCE
Responses
200

OK

404

Resource not found

422

Validation failure

429

Too many requests

get/functions
Request samples
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)
}
Response samples
{
  • "data": {
    }
}

Create Function Deployment

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.

Securitytoken
Request
path Parameters
functionId
required
string [ 1 .. 255 ]
Example: sfn_rh5BDZp6QDHvXFCkibm1pR
Responses
200

OK

404

Resource not found

422

Validation failure

429

Too many requests

post/functions/{functionId}/deploy
Request samples
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)
}
Response samples
{
  • "data": {
    }
}

Create Insert Function Instance

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.

Securitytoken
Request
Request Body schema: application/vnd.segment.v1alpha+json
required
functionId
required
string (functionId)

Insert Function id to which this instance is associated.

integrationId
required
string (integrationId)

The Source or Destination id to be connected.

enabled
boolean (enabled)

Whether this insert Function instance should be enabled for the Destination.

name
required
string (name)

Defines the display name of the insert Function instance.

required
object (settings)

An object that contains settings for this insert Function instance based on the settings present in the insert Function class.

Responses
200

OK

404

Resource not found

422

Validation failure

429

Too many requests

post/insert-function-instances
Request samples
application/vnd.segment.v1alpha+json
{
  • "functionId": "76365637324e715a67535831",
  • "integrationId": "fP7qoQw2HTWt9WdMr718gn",
  • "name": "Example insert function instance",
  • "settings": {
    }
}
Response samples
application/vnd.segment.v1alpha+json
{
  • "data": {
    }
}

List Insert Function Instances

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.

Securitytoken
Request
query Parameters
object (PaginationInput)

Pagination parameters.

This parameter exists in alpha.

Example: pagination=pagination.count=10
functionId
required
string (functionId)

The insert Function class id to lookup.

This parameter exists in alpha.

Example: functionId=76365637324e715a67535831
Responses
200

OK

404

Resource not found

422

Validation failure

429

Too many requests

get/insert-function-instances
Request samples
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)
}
Response samples
application/vnd.segment.v1alpha+json
{
  • "data": {
    }
}

Delete Function

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.

Securitytoken
Request
path Parameters
functionId
required
string [ 1 .. 255 ]
Example: sfnc_wXzcDGFR3KmjLDrtSawNHf
Responses
200

OK

404

Resource not found

422

Validation failure

429

Too many requests

delete/functions/{functionId}
Request samples
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)
}
Response samples
{
  • "data": {
    }
}

Get Function

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.

Securitytoken
Request
path Parameters
functionId
required
string [ 1 .. 255 ]
Example: sfnc_wXzcDGFR3KmjLDrtSawNHf
Responses
200

OK

404

Resource not found

422

Validation failure

429

Too many requests

get/functions/{functionId}
Request samples
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)
}
Response samples
{
  • "data": {
    }
}

Update Function

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
Securitytoken
Request
path Parameters
functionId
required
string [ 1 .. 255 ]
Example: sfnc_wXzcDGFR3KmjLDrtSawNHf
Request Body schema:
required
code
string (code)

The Function code.

Array of objects (settings)

The list of settings for this Function.

displayName
string (displayName)

A display name for this Function.

logoUrl
string (logoUrl)

A logo for this Function.

description
string (description)

A description for this Function.

Responses
200

OK

404

Resource not found

422

Validation failure

429

Too many requests

patch/functions/{functionId}
Request samples
{
  • "code": "// Learn more about source functions API at https://segment.com/docs/connections/sources/source-functions",
}
Response samples
{
  • "data": {
    }
}

Delete Insert Function Instance

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.

Securitytoken
Request
path Parameters
instanceId
required
string [ 1 .. 255 ]
Example: 65c2bdbdde6f2d8297f943da
Responses
200

OK

404

Resource not found

422

Validation failure

429

Too many requests

delete/insert-function-instances/{instanceId}
Request samples
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)
}
Response samples
application/vnd.segment.v1alpha+json
{
  • "data": {
    }
}

Get Insert Function Instance

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.

Securitytoken
Request
path Parameters
instanceId
required
string [ 1 .. 255 ]
Example: 65c2bdbcde6f2d8297f943d7
Responses
200

OK

404

Resource not found

422

Validation failure

429

Too many requests

get/insert-function-instances/{instanceId}
Request samples
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)
}
Response samples
application/vnd.segment.v1alpha+json
{
  • "data": {
    }
}

Update Insert Function Instance

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.

Securitytoken
Request
path Parameters
instanceId
required
string [ 1 .. 255 ]
Example: 65c2bdbcde6f2d8297f943d8
Request Body schema: application/vnd.segment.v1alpha+json
required
enabled
boolean (enabled)

Whether this insert Function instance should be enabled for the Destination.

name
string (name)

Defines the display name of the insert Function instance.

required
object (settings)

An object that contains settings for this insert Function instance based on the settings present in the insert Function class.

Responses
200

OK

404

Resource not found

422

Validation failure

429

Too many requests

patch/insert-function-instances/{instanceId}
Request samples
application/vnd.segment.v1alpha+json
{
  • "enabled": false,
  • "settings": {
    }
}
Response samples
application/vnd.segment.v1alpha+json
{
  • "data": {
    }
}

Get Function Version

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.

Securitytoken
Request
path Parameters
functionId
required
string [ 1 .. 255 ]
Example: sfnc_wXzcDGFR3KmjLDrtSawNHf
versionId
required
string [ 1 .. 255 ]
Example: 2Ma03fahSqLoEzQfV5o2aSfVEHs
Responses
200

OK

404

Resource not found

422

Validation failure

429

Too many requests

get/functions/{functionId}/versions/{versionId}
Request samples
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)
}
Response samples
application/vnd.segment.v1alpha+json
{
  • "data": {
    }
}

List Function Versions

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.

Securitytoken
Request
path Parameters
functionId
required
string [ 1 .. 255 ]
Example: sfnc_wXzcDGFR3KmjLDrtSawNHf
query Parameters
object (PaginationInput)

Pagination parameters.

This parameter exists in alpha.

Example: pagination=pagination.count=10
Responses
200

OK

404

Resource not found

422

Validation failure

429

Too many requests

get/functions/{functionId}/versions
Request samples
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)
}
Response samples
application/vnd.segment.v1alpha+json
{
  • "data": {
    }
}

Restore Function Version

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.

Securitytoken
Request
path Parameters
functionId
required
string [ 1 .. 255 ]
Example: sfnc_wXzcDGFR3KmjLDrtSawNHf
Request Body schema: application/vnd.segment.v1alpha+json
required
versionId
required
string (versionId)

An identifier for this version.

Responses
200

OK

404

Resource not found

422

Validation failure

429

Too many requests

post/functions/{functionId}/versions
Request samples
application/vnd.segment.v1alpha+json
{
  • "versionId": "2Ma03fahSqLoEzQfV5o2aSfVEHs"
}
Response samples
application/vnd.segment.v1alpha+json
{
  • "data": {
    }
}