Update Function
PATCH {{host}}/{{version}}/{{workspace_id}}/{{function_id}}
Field | Subfield | Description | Required? |
---|---|---|---|
update_mask | paths | array of paths to update | required |
function | functions object | required |
updatemask paths
may contain: function.code
, function.settings
, `functions.displayname,
functions.logo_url,
functions.description`
Destination Function code updates will immediately be deployed to all destination instances.
Source Function code updates do not immediately get deployed to all source instances. You will need to call deploy
on each source function instance for code changes to take effect. See the Sources API IsLatestVersion
and Deploy
endpoints.
Request Body
{"function"=>{"code"=>"// Learn more about source functions API at\n// https://segment.com/docs/connections/sources/source-functions\n\n/**\n * Handle incoming HTTP request\n *\n * @param {FunctionRequest} request\n * @param {FunctionSettings} settings\n */\nasync function onRequest(request, settings) {\n\tconst body = request.json();\n\tconsole.log(body);\n\n\t// See https://segment.com/docs/connections/spec/track/\n\tSegment.track({\n\t\tevent: 'Test Event',\n\t\tuserId: 'user_id',\n\t\tproperties: {\n\t\t\ttestProperty: 'testValue'\n\t\t}\n\t});\n\n\t// See https://segment.com/docs/connections/spec/identify/\n\tSegment.identify({\n\t\tuserId: 'user_id',\n\t\ttraits: {\n\t\t\tuserName: 'Unicorn'\n\t\t}\n\t});\n\n\t// See https://segment.com/docs/connections/spec/group/\n\tSegment.group({\n\t\tgroupId: 'group_id',\n\t\tuserId: 'user_id',\n\t\ttraits: {\n\t\t\tgroupName: 'Unicorn'\n\t\t}\n\t});\n\n\t// See https://segment.com/docs/connections/spec/page/\n\tSegment.page({\n\t\tname: 'Home page',\n\t\tuserId: 'user_id',\n\t\tproperties: {\n\t\t\turl: 'https://mywebsite.com/about'\n\t\t}\n\t});\n\n\t// See https://segment.com/docs/connections/spec/screen/\n\tSegment.screen({\n\t\tname: 'Test Screen',\n\t\tuserId: 'user_id',\n\t\tproperties: {\n\t\t\turl: 'https://mywebsite.com/about'\n\t\t}\n\t});\n\n\t// See https://segment.com/docs/connections/sources/catalog/libraries/server/object-api/\n\tSegment.set({\n\t\tcollection: 'users',\n\t\tid: 'user_id',\n\t\tproperties: {\n\t\t\tuserName: 'Unicorn'\n\t\t}\n\t});\n}\n"}, "update_mask"=>{"paths"=>["function.code"]}}
HEADERS
Key | Datatype | Required | Description |
---|---|---|---|
Content-Type | string |
RESPONSES
status: OK
{"code":"// Learn more about source functions API at\n// https://segment.com/docs/connections/sources/source-functions\n\n/**\n * Handle incoming HTTP request\n *\n * @param {FunctionRequest} request\n * @param {FunctionSettings} settings\n */\nasync function onRequest(request, settings) {\n\tconst body = request.json();\n\tconsole.log(body);\n\n\t// See https://segment.com/docs/connections/spec/track/\n\tSegment.track({\n\t\tevent: 'Test Event',\n\t\tuserId: 'user_id',\n\t\tproperties: {\n\t\t\ttestProperty: 'testValue'\n\t\t}\n\t});\n\n\t// See https://segment.com/docs/connections/spec/identify/\n\tSegment.identify({\n\t\tuserId: 'user_id',\n\t\ttraits: {\n\t\t\tuserName: 'Unicorn'\n\t\t}\n\t});\n\n\t// See https://segment.com/docs/connections/spec/group/\n\tSegment.group({\n\t\tgroupId: 'group_id',\n\t\tuserId: 'user_id',\n\t\ttraits: {\n\t\t\tgroupName: 'Unicorn'\n\t\t}\n\t});\n\n\t// See https://segment.com/docs/connections/spec/page/\n\tSegment.page({\n\t\tname: 'Home page',\n\t\tuserId: 'user_id',\n\t\tproperties: {\n\t\t\turl: 'https://mywebsite.com/about'\n\t\t}\n\t});\n\n\t// See https://segment.com/docs/connections/spec/screen/\n\tSegment.screen({\n\t\tname: 'Test Screen',\n\t\tuserId: 'user_id',\n\t\tproperties: {\n\t\t\turl: 'https://mywebsite.com/about'\n\t\t}\n\t});\n\n\t// See https://segment.com/docs/connections/sources/catalog/libraries/server/object-api/\n\tSegment.set({\n\t\tcollection: 'users',\n\t\tid: 'user_id',\n\t\tproperties: {\n\t\t\tuserName: 'Unicorn'\n\t\t}\n\t});\n}\n","deployed_at":"2020-06-02T21:04:00Z","settings":[{"name":"myapiKey","label":"my api key","type":"string"},{"name":"mySecret","label":"my secret key","type":"string","sensitive":true}],"id":"sfnc_1234","workspace_id":"workspace_id","display_name":"my test source function","created_at":"2020-07-30T19:15:26.660Z","created_by":"user_id","logo_url":"https://logo-url","type":"SOURCE","catalog_id":"1234"}