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:
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
required
object (PaginationInput)

Pagination parameters.

This parameter exists in v1.

Example: 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:
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({ count: 10 }, '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": {
    }
}

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:
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": {
    }
}

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
required
object (PaginationInput)

Pagination parameters.

This parameter exists in alpha.

Example: 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', { count: 10 }))
  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 a 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
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": {
    }
}