A sample ByteChef automation code project written in JavaScript. The whole project is one file,
src/sample_code_project.js, and that file is what you deploy - there is no build step.
The file is a single parenthesized object expression, ({ ... }). The server evaluates it and reads the object's
name, description, version and workflows, then calls each task's perform(context) when the workflow runs.
Keep it a bare expression: a bundler or module wrapper hides the object from the server.
The project, "Sample Code Project JavaScript", has four workflows:
sampleWorkflow1takes anameinput, runs one task,greet, that logs and returnsHello, <name>!, and exposes that as thegreetingoutput.summarizeNewEmailstarts with the Gmail New Email polling trigger (googleMail/v1/newEmailPolling). It runs once for every new email and returns a one-line summary as thesummaryoutput.fetchRecentEmailstakes an optionalfrominput, calls the Gmail Search Email action and returns the matching messages as theemailsoutput.notifySlackOnNewEmailstarts with the Gmail New Email trigger and takes a requiredchannelinput; its options come from Slack's ownchannelinput (componentName,componentVersionandgroupNameon the input), so it is picked from the Slack workspace's channels. ItspostToSlacktask calls the Slack Send Channel Message action, so it declares aslackconnection and passes its name: pick a Slack connection for it in the test configuration or when deploying the project.
A task names the connections it uses and calls a component action through one of them:
connections: [{componentName: "googleMail", name: "gmail"}],
perform: function (context) {
return context.component.googleMail.searchEmail({maxResults: 10}, "gmail");
}The declared connection, and the Gmail trigger, show up in the workflow's test configuration and in the project
deployment like any other workflow connection: pick a Gmail connection for gmail there. Nothing in the source names a
specific account.
Inside perform, context.input() returns the workflow inputs plus the output of every task that already ran (under
the task's name), context.input("name") returns one of them, and context.log(level, message) writes to the
execution log.
npm run checkEvaluates the file the same way the server does, checks its shape and runs each task once with a stub context. It needs only Node.js; the JavaScript file has no dependencies to install.
src/sample_code_project.ts is the same project written in TypeScript. It takes its types
from @bytechef/workflow-api through a
/// <reference types="@bytechef/workflow-api" /> directive and ends in satisfies ByteChef.ProjectDefinition, so
context is typed inside every perform and a missing name or a misspelled perform fails the build. The server
runs only JavaScript, so compile the file and deploy the output:
npm install
npm run check:tscheck:ts compiles the file to dist/sample_code_project.js and runs the same check on it. Deploy
dist/sample_code_project.js in place of src/sample_code_project.js; the directive and satisfies leave nothing
behind, so the output is the same bare ({ ... }) expression. Don't import or export anything in the .ts file:
either one turns it into a module, the output stops being a bare expression and the check fails. It is named "Sample
Code Project TypeScript", so deploying it creates a project of its own next to the JavaScript one.
Upload src/sample_code_project.js. Deploying a project with the same name again deploys a new version of that
project instead of creating a second one.
Automation → Projects → the arrow next to New Project → Import Code Project, then pick the file.
POST /api/automation/v1/projects/deploy with a multipart/form-data body:
| Part | Value |
|---|---|
workspaceId (query parameter) |
The workspace the project belongs to. Send it - the upload fails without it. |
projectFile (file part) |
The .js file. The file name must end in .js; the server picks the language from the extension. |
Authenticate with Authorization: Bearer <API key>, using a workspace API key (Settings → Current Workspace →
API Keys) that belongs to an administrator - deploying requires the admin role. The key is looked up in the
environment named by the X-ENVIRONMENT header (DEVELOPMENT, STAGING or PRODUCTION; PRODUCTION when the
header is absent), so send the environment the key was created in. A successful deploy returns 204 No Content.
curl -X POST "$BYTECHEF_URL/api/automation/v1/projects/deploy?workspaceId=1" \
-H "Authorization: Bearer $BYTECHEF_API_KEY" \
-H "X-ENVIRONMENT: DEVELOPMENT" \
-F "projectFile=@src/sample_code_project.js"BYTECHEF_URL is the server's base URL, for example http://localhost:9555 for a local development server.