ByteChef LogoByteChef
PlatformEmbeddedBuild
Enterprise Edition

Code Integrations

Build an embedded integration's workflows in JavaScript, Python or Java - create and edit it in ByteChef or deploy it from CI, then publish it to your connected users.

A code integration is an embedded integration whose workflows are written in code instead of on the canvas. Your connected users meet it exactly like any other integration - in the Integration Marketplace, the connect dialog and their instances - and its workflows run on the same engine. Only the authoring and the lifecycle differ.

It uses the code workflow contract: the same workflows, inputs, outputs, triggers, tasks, task context and type definitions. The one difference is how it is identified: a code integration is keyed by the component it integrates, so it declares componentName and componentVersion where a project declares name.

Enterprise Edition only

Code integrations require an Enterprise Edition deployment (bytechef.edition=ee).

The fastest way in is a sample integration: the Gmail integration below, in JavaScript, Python and Java, with a local check and deploy instructions.

The definition

MemberTypeRequired
componentNamestringYesThe component this integration is for. It must exist on the server.
componentVersionintegerYesThat component's version.
namestringNoThe integration's display name. Defaults to componentName.
versionstringNoDefaults to 0.0.1.
descriptionstringNo
workflowslist of workflowsNoWorkflows as in a code project.
({
    componentName: "googleMail",
    componentVersion: 1,
    version: "0.0.1",
    description: "A sample code integration built on the Gmail component.",
    workflows: [
        {
            name: "summarizeNewEmail",
            label: "Summarize New Email",
            description: "Runs for every new email in the connected user's inbox and logs who sent it.",
            triggers: [{name: "newEmail", type: "googleMail/v1/newEmailPolling", parameters: {format: "SIMPLE"}}],
            outputs: [{name: "summary", task: "summarize"}],
            tasks: [
                {
                    name: "summarize",
                    label: "Summarize",
                    description: "Builds a one-line summary of the new email.",
                    perform: function (input, context) {
                        const email = input.newEmail;

                        const summary = "New email from " + email.from + ": " + email.subject;

                        context.log("info", summary);

                        return summary;
                    }
                }
            ]
        },
        {
            name: "fetchRecentEmails",
            label: "Fetch Recent Emails",
            description: "Returns the connected user's most recent emails, optionally only those from one sender.",
            triggers: [{name: "request", type: "request/v1/awaitWorkflowAndRespond"}],
            outputs: [{name: "emails", task: "fetchEmails"}],
            tasks: [
                {
                    name: "fetchEmails",
                    label: "Fetch Emails",
                    description: "Searches the inbox with the Gmail Search Email action.",
                    perform: function (input, context) {
                        const request = input.request || {};
                        const body = request.body || {};

                        const result = context.component.googleMail.searchEmail(
                            {from: body.from, maxResults: body.maxResults || 10});

                        context.log("info", "Found " + (result.messages || []).length + " emails");

                        return result.messages || [];
                    }
                }
            ]
        },
        {
            name: "notifySlackOnNewEmail",
            label: "Notify Slack on New Email",
            description: "Posts every new email in the connected user's inbox to a Slack channel.",
            inputs: [
                {
                    name: "channel", label: "Slack Channel", type: "STRING", required: true,
                    componentName: "slack", componentVersion: 1, groupName: "channel"
                }
            ],
            triggers: [{name: "newEmail", type: "googleMail/v1/newEmailPolling", parameters: {format: "SIMPLE"}}],
            outputs: [{name: "message", task: "postToSlack"}],
            tasks: [
                {
                    name: "postToSlack",
                    label: "Post to Slack",
                    description: "Posts the sender and subject with the Slack Send Channel Message action.",
                    connections: [{componentName: "slack", name: "slack"}],
                    perform: function (input, context) {
                        const email = input.newEmail;

                        const text = "New email from " + email.from + ": " + email.subject;

                        const message = context.component.slack.sendChannelMessage(
                            {channel: input.channel, text: text}, "slack");

                        context.log("info", "Posted to Slack: " + text);

                        return message;
                    }
                }
            ]
        }
    ]
})

A Java code integration is a jar with an IntegrationHandler implementation from sdks/backend/java/embedded/integration-api, registered through ServiceLoader like a Java code project.

To type-check a JavaScript or Python integration, use ByteChef.IntegrationDefinition from @bytechef/workflow-api or IntegrationDefinition from bytechef-workflow-api; see Typed authoring.

Sample integrations

Each sample is the Gmail integration above (the JavaScript and Python files are exactly the listings on this page), with a local check that evaluates the file the way the server does and runs each task once against a stub that returns a sample email:

SampleLocal checkFile to deploy
JavaScriptnpm run checksrc/sample_code_integration.js
Pythonpython3 scripts/check.py src/sample_code_integration.pysrc/sample_code_integration.py
Java./gradlew build (JDK 25)build/libs/sample-code-integration-java-1.0.0.jar

The JavaScript and Python checks need only Node.js or Python 3.9 or later. The JavaScript sample also has a TypeScript version, src/sample_code_integration.ts, typed with ByteChef.IntegrationDefinition; npm run check:ts compiles and checks it, but needs the type package, which is not published yet. The Java sample compiles against integration-api-1.0.jar and workflow-api-1.0.jar in its libs/ folder, built from sdks/backend/java/embedded/integration-api and sdks/backend/java/workflow-api in the ByteChef repository; they are compileOnly, because the server provides them.

Deploy the file through Import Code Integration (see Creating a code integration) or the deploy endpoint. Once a connected user has connected the integration and enabled fetchRecentEmails on their instance, call it with their JWT:

curl -X POST "$BYTECHEF_URL/api/embedded/v1/workflows/$WORKFLOW_UUID" \
  -H "Authorization: Bearer $CONNECTED_USER_JWT" \
  -H "X-ENVIRONMENT: DEVELOPMENT" \
  -H "Content-Type: application/json" \
  -d '{"from": "ada@example.com", "maxResults": 5}'

The body is optional. summarizeNewEmail needs no call: once enabled, it runs whenever a new email arrives.

Connections

A Gmail trigger in a Gmail integration runs on the connection the connected user created when they connected the integration. A task calls component actions with context.component.<componentName>.<actionName>(input, connectionName), and what it declares depends on the component:

  • The integration's own component - googleMail above - needs no declaration and no connection name: context.component.googleMail.searchEmail({maxResults: 10}) runs on the connected user's integration connection. When the integration is saved or deployed, ByteChef adds that connection to every code task under the component's name, pinned to the integration's component version, unless the task already declares one on that component. A three-parameter perform(input, connection, context) therefore finds that connection's parameters under the component's name, connection["googleMail"].
  • Any other component - slack in notifySlackOnNewEmail - is declared on the task and its name passed to the call. An administrator picks that connection when enabling the workflow in the integration's instance configuration, and every connected user's run uses it. A deploy with enable=true leaves such a workflow disabled until an administrator has picked the connection.

See Declaring connections for the syntax in each language.

Component tasks

A task in a code integration can run a component action directly instead of calling it from a perform: give it a type of the form <component>/v<version>/<action> and the action's inputs as parameters. It takes the same ${...} expressions and follows the same rules as in an automation project; see Component tasks.

tasks: [
    {name: "fetch_emails", perform: (input, context) => context.component.googleMail.searchEmail({maxResults: 10})},
    {
        name: "notify",
        type: "slack/v1/sendChannelMessage",
        parameters: {channel: "${channel}", text: "${fetch_emails}"}
    }
]

A component task declares no connections and doesn't receive the integration's implicit connection the way a perform task does. It is stored as an ordinary workflow task, so its connection is wired as the same task's would be in a visual integration workflow.

Inputs with component options

An input can take its options from an input a component declares, so the connected user picks a value from a list instead of typing it. notifySlackOnNewEmail's channel input points at Slack's channel input with componentName, componentVersion and groupName, so the connect dialog lists the channels of the Slack workspace:

inputs: [
    {
        name: "channel", label: "Slack Channel", type: "STRING", required: true,
        componentName: "slack", componentVersion: 1, groupName: "channel"
    }
]

The options load through the same connection a task uses for that component: the connected user's integration connection for the integration's own component, and the connection an administrator picked in the instance configuration for any other. Until that connection is picked, the list is empty. See Inputs, outputs and triggers for the syntax in each language.

Internal-only inputs

Set internalOnly: true on an input that an administrator sets once for every connected user, such as a fixed redirect URL. The input then appears in the integration configuration's workflow settings instead of the connect dialog, and connected users can neither see nor override its value:

inputs: [
    {name: "contactPageUrl", label: "Contact Page URL", type: "STRING", required: true, internalOnly: true}
]

Creating a code integration

On Embedded → Integrations, the arrow next to New Integration opens a menu with New Code Integration and Import Code Integration.

  • New Code Integration asks for a Language (JavaScript or Python), the Component, a Name, and an optional Description, Category, Permission Expression and Tags. ByteChef creates the integration as an unpublished draft from a starter source and opens it in the code editor.
  • Import Code Integration uploads a .js, .py or .jar file and publishes it, like the deploy endpoint without enable. The dialog offers .jar only while Java uploads are allowed.

The project sidebar of a code integration hides New Workflow and the workflow item actions, because its workflows come from the source.

Editing in ByteChef

A JavaScript or Python code integration opens in a source editor instead of the canvas.

  • Save checks the source before storing it: source that fails to load is rejected with the loader's error and the draft stays as it was. The componentName declared in the source must stay the integration's component. The display name stays in sync with the source: change name in the source and saving renames the integration; rename the integration and the name in the draft source is rewritten to match. A source that declares no name keeps the integration's name as it is.
  • Saves change the draft only. Connected users keep running the last published version until you publish the integration, exactly like a visual integration.
  • A workflow keeps its identity across saves, uploads and publishes as long as its name doesn't change, so instance configurations and connected users' instances keep pointing at the right workflow.

Java code integrations are uploaded only; the editor does not open them.

Deploying through the API

POST /api/embedded/v1/integration-code-workflows/deploy

A multipart/form-data request:

Parameter
integrationFile (file part)Required. The .js, .py or .jar file. The file name's extension picks the language.
enable (query parameter)Optional, false by default. See below.
X-ENVIRONMENT (header)Optional. DEVELOPMENT, STAGING or PRODUCTION (case-insensitive); PRODUCTION when absent.

Authenticate with an Embedded API key (Embedded → Settings → API Keys) that belongs to an administrator - deploying requires the admin role. Only an Embedded API key is accepted: an automation workspace key or an organization admin key (Settings → Organization → Admin API Keys) is rejected with 401. The key is looked up in the environment named by X-ENVIRONMENT, so send the environment the key was created in; the same header picks the environment enable acts on. The request runs as the key's own ByteChef user, not as a connected user.

curl -X POST "$BYTECHEF_URL/api/embedded/v1/integration-code-workflows/deploy?enable=true" \
  -H "Authorization: Bearer $BYTECHEF_EMBEDDED_API_KEY" \
  -H "X-ENVIRONMENT: DEVELOPMENT" \
  -F "integrationFile=@src/sample_code_integration.py"

What the endpoint does:

  • It saves and publishes. The upload is saved as the integration's draft and published in the same call. An upload replaces any unpublished editor changes.
  • It upserts by component. The first deploy for a component creates the integration; every deploy after that publishes a new version of it. If more than one code integration is built on the same component (possible when they were created in ByteChef), an upload can't tell which one to update and is refused - edit the one you mean in the source editor instead.
  • Without enable, instance configurations don't move. Connected users keep the version their environment's instance configuration points at.
  • enable=true makes it live in the request's environment. When the integration has no instance configuration there, ByteChef creates one at the published version and enables it. When it has one, ByteChef moves it to the published version and enables it if it was disabled. With several instance configurations in that environment, it moves the one that is enabled; when none or more than one is enabled, the deploy is refused as ambiguous.

With enable=true, a workflow whose tasks or trigger need a connection to a component other than the integration's own stays disabled until an administrator picks that connection in the instance configuration and enables the workflow; in the sample that is notifySlackOnNewEmail. Every other workflow is enabled. On a move to a new version this applies to workflows the version adds; workflows that were already configured keep their connections, inputs and enabled state.

Creating the instance configuration is refused when the component authorizes only through OAuth2 with client credentials that an administrator registers (the Gmail sample needs them unless ByteChef has a predefined OAuth app for Gmail): create the instance configuration on its page first, with those credentials, and later deploys with enable=true move it.

Responses:

StatusWhen
204 No ContentThe integration was saved and published, and enabled when enable=true.
400 Bad RequestThe file is missing or fails to load, its language is unsupported or Java uploads are disabled, the component is ambiguous, or enable=true can't create or pick the instance configuration. The body names the reason.
401 UnauthorizedThe API key is unknown in that environment, is not an Embedded API key, or X-ENVIRONMENT is not a valid environment.
403 ForbiddenThe key's user is not an administrator.

Java uploads follow the BYTECHEF_WORKFLOW_CODE_WORKFLOW_JAVA_ENABLED switch.

See also

  • Code Workflows - the full contract: task context, inputs, outputs, triggers, concurrency, connections and typed authoring.
  • Integrations - how an integration reaches your connected users.
  • Automation Code Workflows - catalog code projects, run by reference.

How is this guide?

Last updated on

On this page