ByteChef LogoByteChef
Embedded

Headless Embedding

Build your own connect UI against the embedded API when the React SDK does not fit, for example in a non-React frontend or a native app.

@bytechef/embedded is a React SDK. If your product is not built with React, or you need a different connect flow than the Connect dialog's, you can call the same public endpoints the dialog uses. The dialog holds no privileged state.

You implement the OAuth flow

Besides the form, the SDK handles the OAuth 2.0 popup, the state check and the code exchange. A headless implementation has to do this itself. For non-OAuth connections the work is mostly a form.

Which credential

Use a Signing Key JWT, the same one the SDK takes. It authenticates one of your end users directly from the browser, so the operations you call are the ones under Frontend in the API reference. They resolve the user from the token's sub claim and carry no user id in the path.

You can drive the same flow from your backend with an API Key against the {externalUserId} paths instead. Do that when the connect step is server-driven; use the JWT when the browser is making the calls, so your API Key never reaches the client.

Mint tokens as described in Installing the SDK. The private key stays on your server and the token is short-lived.

The flow

Fetch the integration

const response = await fetch(`${baseUrl}/api/embedded/v1/integrations/${integrationId}`, {
    headers: {
        Authorization: `Bearer ${jwtToken}`,
        'X-Environment': 'PRODUCTION',
    },
});

The payload describes what you need to render: the integration's workflows and the connection's connectionConfig, which holds the authorizationType, the inputs to collect and, for OAuth2 integrations, an oauth2 object with authorizationUrl, clientId, redirectUri, scopes and extraQueryParameters. The call returns 404 when the integration's permission expression hides it from the user.

For an Airtable integration, whose connection takes a bearer token, an abbreviated response looks like this:

{
  "id": 1050,
  "name": "Airtable",
  "componentName": "airtable",
  "multipleInstances": false,
  "connectionConfig": {
    "authorizationType": "BEARER_TOKEN",
    "inputs": [
      {"name": "token", "label": "Token", "type": "STRING", "required": true}
    ]
  },
  "workflows": [
    {"workflowUuid": "<workflow-uuid>", "label": "Sync new records", "inputs": []}
  ],
  "integrationInstances": []
}

Each entry in connectionConfig.inputs is one field to render. For an OAuth2 authorizationType, inputs is empty and oauth2 carries the authorization parameters instead.

Authorize

For an OAuth integration, send the user to the authorizationUrl with those parameters, in a popup or a redirect. The SDK also does the following, and so must your implementation:

  • Generate a state value and verify it on return. A mismatch means the response did not come from the flow you started, and must be rejected.
  • Match the response type to the grant. Authorization Code returns a code to exchange; implicit-style grants return a token directly.

For a non-OAuth integration there is nothing to authorize. Collect the inputs the payload described and continue with the next step.

Create the integration instance

Post the connection parameters. The body holds only the connection; workflows are enabled afterwards:

await fetch(`${baseUrl}/api/embedded/v1/integrations/${integrationId}/instances`, {
    method: 'POST',
    headers: {
        Authorization: `Bearer ${jwtToken}`,
        'Content-Type': 'application/json',
        'X-Environment': 'PRODUCTION',
    },
    body: JSON.stringify({connection: {parameters: {/* the collected inputs or OAuth2 tokens */}}}),
});

For the Airtable integration above, parameters is {"token": "<airtable-personal-access-token>"}: one key per connectionConfig.inputs entry, named by its name.

The response is the new integration instance id. ByteChef attaches it to the enabled instance configuration of the integration that admits the user through its permission expression, preferring the highest integration version (then the newest configuration). When none admits the user, the call fails. The Connected User record already exists at this point: it is created on the user's first authenticated request (see Syncing Connected Users).

Configure and toggle workflows

Afterwards, the instance's workflows are managed individually:

Method and pathDescription
PUT /api/embedded/v1/integration-instances/{id}/workflows/{workflowUuid}Set a workflow's inputs.
POST /api/embedded/v1/integration-instances/{id}/workflows/{workflowUuid}/enableEnable the workflow.
DELETE /api/embedded/v1/integration-instances/{id}/workflows/{workflowUuid}/enableDisable the workflow.
DELETE /api/embedded/v1/integration-instances/{id}Delete the instance. Its enabled workflows are disabled first.

For example, set a workflow's inputs and then enable it. Input names come from the workflow's inputs in the integration payload; both calls return 204:

const instanceWorkflowUrl = `${baseUrl}/api/embedded/v1/integration-instances/${integrationInstanceId}/workflows/${workflowUuid}`;

await fetch(instanceWorkflowUrl, {
    method: 'PUT',
    headers: {
        Authorization: `Bearer ${jwtToken}`,
        'Content-Type': 'application/json',
        'X-Environment': 'PRODUCTION',
    },
    body: JSON.stringify({inputs: {tableName: 'Leads'}}),
});

await fetch(`${instanceWorkflowUrl}/enable`, {
    method: 'POST',
    headers: {
        Authorization: `Bearer ${jwtToken}`,
        'X-Environment': 'PRODUCTION',
    },
});

See Instance Workflows for the exact bodies.

Dynamic dropdowns

Inputs whose options come from the user's own account, such as a list of their Salesforce objects, are resolved at render time:

POST /api/embedded/v1/integration-instances/{id}/component-input-options

The body names the component input group from the input's componentReference, the property to resolve, and the current values of the properties it depends on:

{
  "componentName": "<componentReference.componentName>",
  "componentVersion": 1,
  "groupName": "<componentReference.groupName>",
  "propertyName": "<property name in the group>",
  "lookupDependsOnValues": {},
  "searchText": ""
}

It runs the component's options function against that user's connection and returns the choices as a list of {"label": "...", "value": "..."} objects. Without this, any input backed by live provider data renders empty.

Reconnecting

To fix a connection whose credential has become INVALID, replace its credentials in place instead of creating a second instance: call POST /api/embedded/v1/connections/{id}/reauthorize with the complete set of authorization parameters. A parameter you leave out is cleared. See Connections for connected users for the endpoint rules and Troubleshooting for how an invalid credential presents.

What you give up

  • The Connect dialog's field rendering, including validation and the field mapping UI, which you would rebuild.
  • Updates. New input types and connection features arrive in the SDK; a headless implementation adopts them only when you implement them.

The workflow builder has no headless equivalent: it is an iframe, not a component library. To offer it, embed it.

How is this guide?

Last updated on

On this page