API-Based Embedding

 

API based embedding enables our clients to seamlessly embed APIFuse workflow capabilities into their own SaaS products.

Broadly APIs are categorized into Connection APIs, Connector APIs & Workflow APIs.

Connection APIs let you handle user authentication for third-party applications, such as Salesforce, Quickbooks, etc.

Connector APIs let you fetch all the connectors, triggers & actions available for your account. 

Workflow APIs provide all the interfaces necessary to build your own Workflow/Integration builder.

APIs are secured using JWT tokens. You need to generate a JWT token for your end user to access API endpoints. 

Generating a JWT bearer token:

To generate an APIFuse JWT token, you need to create a user JWT token as described in the documentation https://docs.apifuse.io/user-authentication/, then you can exchange the user token for an APIFuse JWT token.

Sample curl call is given below for exchanging user JWT token for APIFuse JWT token.

curl –location –request POST ‘https://api.apifuse.io/auth/customer/login‘ \

–header ‘Content-Type: application/json’ \

–data-raw ‘{

“token”:”eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJvcmdJZCI6IjEyMjMyMzIiLCJ1c2VyIjp7ImV4dGVybmFsSWQiOiJ5b3VyX2N1c3RvbWVyX2lkIiwiZmlyc3RuYW1lIjoiYWJjIiwibGFzdG5hbWUiOiJ4eXoiLCJlbWFpbCI6ImFiY0B4eXouY29tIiwibW9uZXRpemF0aW9uUGxhbiI6ImZyZWVtaXVtIn0sImlhdCI6MTY2MDkwMzU5MX0.2DGzYYOiL15kTMOSUvCH-xaMSo552BWmEBi_JM4lFEY”

}

Response:

{ “status”: “success”, “message”: “”, “token“: “eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2NjA5NDY4MTUsInVzZXJJZCI6IjExMTExMS0xMTExMS00NTkyLTg0NmUtMTExMTExIiwic3ViIjoiMTExMTExLTExMTExLTQ1OTItODQ2ZS0xMTExMTEiLCJlbWFpbCI6ImFiY0B4eXouY29tIiwib3JnSWQiOiIxMjM0NTY3ODkiLCJyb2xlIjoiT1JHX0NVU1RPTUVSIiwib3JnUm9sZSI6bnVsbCwibW9uZXRpemF0aW9uUGxhbiI6ImZyZWVtaXVtIiwiZmVhdHVyZXMiOm51bGwsImlzU3VkbyI6ZmFsc2UsIm9yZ0FkbWluVXNlciI6bnVsbCwiYWRtaW5Vc2VyIjpudWxsLCJjb25uZWN0aW9uIjpudWxsLCJvcmdDb25uZWN0b3IiOiJhcHAtdjEiLCJpYXQiOjE2NjA5MDM2MTV9.gYS2LTT2JZMQUruprIv2slTuBaYEihJoG6Mo5Bbx7dM” }

APIFuse API Specification.docx

Workflow Code

Workflow code is a set of instructions in JSON format that instructs the APIFuse integration processor on triggering an event and acting upon the  triggered event.

The following JSON represents the basic structure of the workflow code:

{

“workflowName”: “”,

   “steps”: [],

   “trigger”: {

       “stepId”: “”,

       “triggerType”: “”

   }

}

workflowName – (string) A free text field to provide a unique name for the workflow.

steps – (array) An array of steps containing all the steps executed as part of a workflow, including triggers and actions.

trigger –   Trigger configuration specifying which step is a trigger step ( from the list of steps in the above steps array)

Trigger

“trigger”: {
    “stepId”: “”,
    “triggerType”: “”,
    “customSchedule”: true,
    “schedule”: {
        “scheduleType”: “REGULAR_INTERVAL”,
        “time”: “2023-11-15T00:24:27.241Z”,
        “interval”: 120,
        “daysOfWeek”: [],
        “daysOfMonth”: [],
        “months”: []
    }
}
stepId – (string) stepId of the trigger step.
triggerType – (enum) POLL or WEBHOOK.
                          POLL: Workflow executes based on the default polling interval (15 min) from the workflow’s publishing time.
                          WEBHOOK: Workflow executes upon incoming webhook events.
customSchedule – (boolean) Flag to customize the default polling interval with the provided schedule configuration.
schedule – (object) Parameters for customizing the polling interval.
scheduleType – (enum) REGULAR_INTERVAL, EVERY_DAY, DAYS_OF_WEEK, DAYS_OF_MONTH, SPECIFIED_DATE, CRON.
Examples:
“schedule”: {
    “scheduleType”: “REGULAR_INTERVAL”,
    “time”: “2023-11-15T00:24:27.241Z”,
    “interval”: 120,
    “daysOfWeek”: [],
    “daysOfMonth”: [],
    “months”: []
}
REGULAR_INTERVAL: Increase the interval between polling.
“schedule”: {
    “scheduleType”: “EVERY_DAY”,
    “time”: “2023-11-15T00:26:22.349Z”,
    “interval”: 30,
    “daysOfWeek”: [],
    “daysOfMonth”: [],
    “months”: []
}
EVERY_DAY: Schedule a workflow run every day at a specified time.
“schedule”: {
    “scheduleType”: “DAYS_OF_WEEK”,
    “time”: “2023-11-15T00:27:57.630Z”,
    “interval”: 30,
    “daysOfWeek”: [
        “SUN”
    ],
    “daysOfMonth”: [],
    “months”: []
}
DAYS_OF_WEEK: Schedule a workflow run at a specified time on specific days of the week.
“schedule”: {
    “scheduleType”: “DAYS_OF_MONTH”,
    “time”: “2023-11-15T00:32:09.823Z”,
    “interval”: 30,
    “daysOfWeek”: [],
    “daysOfMonth”: [
            5
    ],
    “months”: []
}
DAYS_OF_MONTH: Schedule a workflow run at a specified time on specific days of the month.
“schedule”: {
    “scheduleType”: “SPECIFIED_DATE”,
    “time”: “2023-11-15T00:33:07.447Z”,
    “interval”: 30,
    “daysOfWeek”: [],
    “daysOfMonth”: [
        15
    ],
    “months”: [
        “FEB”
    ]
}
SPECIFIED_DATE: Schedule a workflow on a specific date and time.
“schedule”: {
    “scheduleType”: “CRON”,
    “time”: “2023-03-09T06:38:26.094Z”,
    “interval”: 30,
    “daysOfWeek”: [],
    “daysOfMonth”: [],
    “months”: [],
    “cron”: “0 0/15 * ? * * *”
}
CRON: Schedule a workflow based on a required cron expression.

Step Object

The step JSON object represents the step configuration in the workflow builder UI (https://docs.apifuse.io/configuring-a-trigger/). Steps can be triggers, actions or functions. Below are the common step object configurations.

stepId – (string) Unique identifier for the step within the workflow (preferably a GUID).

stepType – (object) Instructs the workflow processor on which connector to use for execution.Details can be retrieved from the connector API.

“stepType”: {
    “application”: “salesforce-v1”,
    “appVersion”: 1,
    “isFunction”: false,
    “connectionRequired”: true,
    “runtime”: “legacy”,
    “typeId”: “action upsert object”
}
application – (string) app_id corresponding to connector API mapping.
appVersion – (integer) app_version corresponding to connector API mapping.
isFunction – (boolean) is_function corresponding to connector API mapping.
connectionRequired – (boolean) connection_required corresponding to connector API mapping.
runtime – (enum) legacy, sdk, nodejs. runtime corresponding to connector API mapping.
typeId – (string) Trigger/action name. name corresponding to connector API mapping.

connectionId (string) The Connection ID obtained from connection API. You need to pass the connection ID of the application you are using in the stepType.

nextStepId – (string) Defines the next step to be executed after the current step execution completed.

Schema – (object) Defines the input & output schema of the current step. APIFuse uses schema to parse the stepConfig & produce the output. Every connector triggers/actions have their own input and output schema. Connector schema should be dynamically fetched at the run time using Schema API.

stepConfig – (object) Input mapping fields. This object configuration depends on the step type, application and action type. Inputs fields that needed for current step are defined in the schema.

“stepConfig”: {
    “conditionTrigger”: [
        “{{d359e042-eb51-47d3-8ff9-ecf191914325.event.attendees}}.size() > 2”
    ],
    “triggerSinceDate”: 1698796800000
}
conditionTrigger – (array) This configuration is applicable only for triggers when additional checks need to be added for the triggered event. For instance, in the case of Google Calendar’s “Trigger New Event,” the workflow will be triggered when new events are identified between the polling intervals. However, if we need to add an additional check to trigger only when the number of attendees is more than 2.
triggerSinceDate – (time in milliseconds) This configuration is applicable only for polling triggers. By default, the workflow triggers events from the time it is published. However, in the case of triggering past events, this parameter can be used. This parameter will be considered only for the first time when the workflow is published and is not applicable for subsequent amendments in the existing workflow.
Input fields for the current step can be mapped from the previous step, provided with a default value, or selected from a dropdown.
Sample data illustrated for each case.
1) Mapped from previous step
    “Last_Name”:”{{dfde1bd2-0246-4f1b-af15-996c4b7a15b1.payload}}”,
2) Provided a default value
    “Company”:”\”Example.com\””
3) Selected from dropdown
    “object”:”Lead”,
The stepConfig will be also used when working with functions and script steps, which are covered as special cases later in the document.

stepImports – (array) Some steps may be depend on the output of the previously executed steps. Include the stepIds that the current step depends on.

visibleOptionalFields – (array) This field is only applicable if the workflow needs to be viewed in the APIFuse UI. By default, the APIFuse UI displays only the mandatory attributes. However, if any optional field needs to be displayed, then the field name should be included in the array.
userSchema – (object) This field is applicable when the user wants to customize the input and/or output schema in scriptStep or when the data type of the input field is a schema.
ignoreError – (boolean) The workflow will stop its execution if any of the steps fail. However, if you want to proceed with the rest of the steps in the workflow even if a step fails, you can enable this flag in the corresponding steps.
parentId – (string) parentId defines the previous step that has been executed before the current step. This is mandatory for branching and loop cases.

{

   “stepId”: “3d5c2f8b-d044-487b-b01f-7949fd4cd236”,

   “stepType”: {

       “application”: “hubspot-v1”,

       “appVersion”: 1,

       “isFunction”: false,

       “connectionRequired”: true,

       “runtime”: “legacy”,

       “typeId”: “trigger hubspot contact add”

   },

   “stepImports”: [ ],

   “stepConfig”: {

       “conditionTrigger”: []

   },

   “connectionId”: “abcdefg-11111-1111-1111-abcdefg”,

   “nextStepId”: “eb60b395-6615-4427-9a9b-3be069905cc9”,

   “schema”: {

       “input”: [],

       “output”: {}

   }

}

Schema Objects

Schema objects define the inputs needed for a step to successfully execute and what will be produced after successful execution.

The below example shows the hubspot trigger input/output schema.

{

               “input”: [

                   {

                       “name”: “properties”,

                       “displayName”: “Properties Required”,

                       “description”: “Select Properties”,

                       “controlType”: “multiselect”,

                       “extendedSchema”: “true”,

                       “type”: “TEXT”,

                       “dynamic”: “true”,

                       “picklistValue”: null,

                       “pickList”: “hubspot_properties_picklist”,

                       “linkedPickList”: {}

                   }

               ],

               “output”: {

                   “contact”: {

                       “name”: “contact”,

                       “displayName”: “contact”,

                       “type”: “OBJECT”,

                       “value”: {

                           “id”: {

                               “name”: “id”,

                               “displayName”: “id”,

                               “type”: “TEXT”,

                               “value”: “”

                           },

                           “createdAt”: {

                               “name”: “createdAt”,

                               “displayName”: “createdAt”,

                               “type”: “TEXT”,

                               “value”: “”

                           },

                           “updatedAt”: {

                               “name”: “updatedAt”,

                               “displayName”: “updatedAt”,

                               “type”: “TEXT”,

                               “value”: “”

                           },

                           “firstname”: {

                               “name”: “firstname”,

                               “displayName”: “firstname”,

                               “type”: “TEXT”,

                               “value”: “”

                           },

                           “lastname”: {

                               “name”: “lastname”,

                               “displayName”: “lastname”,

                               “type”: “TEXT”,

                               “value”: “”

                           }

                       }

                   }

               }

           }

Input Schema

Input schema defines 

name – (string) Name of the input field. stepConfig should include this name

displayName – (string) Name to display on the workflow builder UI.

type – (enum) Input field type. Valid values are TEXT, NUMBER INTEGER, OBJECT, LIST, FILE, DATETIME.

controlType – (enum) Control type defines how to render the input field in the UI. For example you can render the input field as a text box or dropdown based on controlType value. Text box is the default render type. Valid values are select, multiselect, schema

extendedSchema – (boolean) In some cases, the entire input schema cannot be obtained in a single extended API call. For example, in the case of the Google Sheet connector, only after selecting the file name, sheet information can be retrieved. Similarly, only after selecting the sheet, columns for input can be retrieved. For such input fields, if the flag is enabled, the system will re-render the UI based on the selected value.

required (boolean) if true, the input field is mandatory.

dynamic – (boolean) This field is used only if the control type is select or multiselect. This field indicates if the dropdown list value should be dynamically fetched.

picklistValue – (object) This field is used only if the control type is select or multiselect. It provides the list of values to display in the dropdown. This is a static list.

picklist – (string) If the dropdown list is dynamic, this field provides the name using which you can fetch the dynamic list of values for the dropdown.

Sample Multi Select field for the input schema object given above.

Ouput Schema

APIFuse uses output schema to produce the step output. You can use the output schema for field mapping. The image below illustrates APIFuse workflow builder input mapping. APIFuse builder uses output schema to display available fields for input field mapping ( Hubspot output fields shown on the right side).


The JSON schema below corresponds to the mapping fields shown in the screenshot above.

“output”: {

                   “contact”: {

                       “name”: “contact”,

                       “displayName”: “contact”,

                       “type”: “OBJECT”,

                       “value”: {

                           “id”: {

                               “name”: “id”,

                               “displayName”: “id”,

                               “type”: “TEXT”,

                               “value”: “”

                           },

                           “createdAt”: {

                               “name”: “createdAt”,

                               “displayName”: “createdAt”,

                               “type”: “TEXT”,

                               “value”: “”

                           },

                           “updatedAt”: {

                               “name”: “updatedAt”,

                               “displayName”: “updatedAt”,

                               “type”: “TEXT”,

                               “value”: “”

                           },

                           “firstname”: {

                               “name”: “firstname”,

                               “displayName”: “firstname”,

                               “type”: “TEXT”,

                               “value”: “”

                           },

                           “lastname”: {

                               “name”: “lastname”,

                               “displayName”: “lastname”,

                               “type”: “TEXT”,

                               “value”: “”

                           }

                       }

                   }

               }

User Schema
The JSON below represents a sample userSchema from a scriptStep.
“userSchema” : {
    “output”: {
        “output”: {
            “name”: “output”,
            “displayName”: “output”,
            “type”: “OBJECT”,
            “value”: {
                “company”: {
                    “name”: “company”,
                    “displayName”: “Company”,
                    “type”: “TEXT”,
                    “value”: “”,
                    “required”: true
                 },
            “lastName”: {
                “name”: “lastName”,
                “displayName”: “LastName”,
                “type”: “TEXT”,
                “value”: “”,
                “required”: true
                }
            }
        }
    },
    “input”: {
        “input”: {
            “name”: “input”,
            “displayName”: “input”,
            “type”: “OBJECT”,
            “required”: true,
            “value”: {
                “payload”: {
                    “name”: “payload”,
                    “displayName”: “payload”,
                    “type”: “TEXT”,
                    “value”: “”,
                    “required”: true
                    }
                }
            }
        }
}