RevCent Functions allows you to run your own custom JavaScript code based on triggers that occur related to your RevCent account. The code is hosted and run by RevCent when specific triggers match your function(s) settings.
Note: Functions are an advanced feature in RevCent and an understanding of the JavaScript programming language is required. A function should be set up by someone who is familiar and/or regularly works with JavaScript, i.e. a developer.
View your functions by clicking Tools > Functions > All Functions in the sidebar, or go to https://revcent.com/user/functions
If you have not requested access to RevCent Functions, you will need to do so.
Create a new function by clicking the Create New Function button when viewing all functions or go to https://revcent.com/user/new-function
Enter a name for the function. Required.
Enter a description for the function.
Once the function is created you will be forwarded to the Edit Function Page for the new function. Continue to the Edit A Function section below.
Edit an existing function by clicking the edit icon when viewing all functions.
Enter a name for the function. Required.
Enter a description for the function.
Set the status for the function.
The function trigger is what initiates a function run. Please read the Function Trigger section for details on each trigger.
Select the function trigger.
Options:
The language used is JavaScript, and the code is run within a NodeJS 20.x runtime. Write your own custom JavaScript code that will execute based on the trigger that occurred. Please read the sections below on the Execution Environment and Execution Handler for information on how your function code is ultimately run.
The RevCent Functions code editor is Monaco, the same editor that powers VS Code. Type checking, error detection and more are built into the editor.
You have the ability to add environment variables which are specific to the function and are accessible via the process.env
object within your code.
Note: Environment variables added within the function take precedence over Function Values. If an environment variable within a function shares the same name as a Function Value, then the functions' environment variable will replace the Function Value for the same name.
Click the Add Environment Variable button to create a new variable for the specific function. You have the option to encrypt an environment variable for sensitive data.
Note: Remember to save your function after adding or encrypting variables.
The function trigger is what causes the function run, and determines the event.data
property within the function execution. There are key differences in each trigger option.
Trigger Options:
The Account Event trigger allows you to have RevCent automatically run a function when a specific event occurs. Extremely useful for processing an item when created or updated. For example, you can run custom logic when a sale is created, a subscription renewed, etc.
The event.data
property will contain details on the specific item related to the event, in JSON format.
Important: Please view the Events page for more information on what item type is associate for each event notation, and a description of each as well.
When editing a function and selecting Account Event as the Trigger, additional options will appear.
Select one or more campaign(s) to filter only triggers from originating campaign(s). If a campaign(s) is selected, the function will trigger only from the campaign(s) selected. If none selected, the function will trigger regardless of originating campaign. Optional.
Select one or more shops(s) to filter only triggers from originating shops(s). If a shops(s) is selected, the function will trigger only from the shops(s) selected. If none selected, the function will trigger regardless of originating shop. Optional.
Select one or more Account Event(s), any of which will trigger the function. Please view the Events page for more information on what an event is, event notations and examples.
The Flow trigger allows you to execute the function as an action within a Flow. The event.data
property will contain details on the specific item related to the flow, in JSON format. The items' details is contained in the event.data.item_details
object.
A Customer Lifecycle flow type will contain a customer event object.
A Sale Lifecycle flow type will contain a sale event object.
The Email Template trigger allows you to execute the function during the compilation of an Email Template to generate a custom_data object. The function will receive the details of the item specific to the email template triggered at time of compilation. The items' details is contained in the event.data.item_details
object. View the email template trigger list to see the event.item_details that corresponds to each.
Important: The function must return a valid JSON object in order to be amended to the email templates' input data as custom_data, i.e. callback(null, {"custom_property": “custom value”});
The Auto Query trigger allows you to execute the function after a query has completed. The function will receive the query results, contained in the event.data.query_results
array. Read more about Auto Query feature in RevCent.
The Payment Profile trigger allows you to execute the function during the processing of a Next-Gen payment profile flow. The function will receive the specific flow request object, and allows you to run it separately or return a response. Read more about the Next-Gen Run Function node, including the item details object and response object requirements.
The AI Assistant trigger allows you to execute the function as a part of an AI Assistant action. The function will receive the AI details, contained in the event.data.item_details.ai_data
object. Read more about the AI Assistant feature including an example ai_data object.
The schedule trigger allows you to execute the function on a fixed schedule using a cron expression. The event.data
property will be an empty string.
When editing a function, if you select Schedule as the Trigger, you must select a timezone and enter a valid cron expression.
Select a timezone for the cron expression. The timezone will determine the time when the function is triggered.
The cron expression is the most important part of a Schedule trigger. You must enter a standard five-part cron expression:
We recommend using the validate feature before attempting to save the function. The next 5 run dates will be displayed when validating.
0 8 * * *
. The @ syntax is not supported.
The URL trigger allows you to execute the function immediately using the functions' URL, with either a GET or POST request, and receive a response determined by the function. Useful for performing immediate operations or requesting data.
The event.data
property will be the body of the URL request, if present. The body will be in string format, allowing you to process any content type.
When editing a function, if you select URL as the Trigger, you have the option to create a new function URL if one has not been created. If already created, the function URL will appear.
If you have not created a URL for the function, the Create New URL button will appear. Click the button and RevCent will create a custom URL to be used for triggering the function.
After creating a URL for the function, the URL will appear. This URL is what will immediately trigger the function without delay.
Important: When a request is sent to the function URL, RevCent will return the response from the function execution. The URL trigger is meant as a request > function execution > function response. Therefore, you should consider implementing some form of authentication if returning sensitive data.
Your function URL is publicly accessible. Other than IP restrictions, RevCent does not provide any authentication methods for function URL requests. You should always verify that the request to your function URL came from an authorized source. We recommend verifying requests by having a form of authentication built into your function code. You can utilize the request body or the headers and url parameters provided in the functions' context object for authentication.
The Webhook trigger allows the execution of the function using the functions' webhook URL. You can perform actions and parse a webhook requests' body when a POST request is sent to the functions' webhook URL.
The event.data
property will be the body of the webhook POST. It will be in string format, allowing you to process any content type.
When editing a function, if you select Webhook as the Trigger, you have the option to create a new webhook URL for the function if one has not been created. If already created, the webhook URL will appear.
If you have not created the webhook within the function, the Create New Webhook button will appear. Click the button and RevCent will create a custom webhook endpoint to be used for triggering the function.
After creating a webhook for the function, the webhook URL will appear. This URL is what will trigger the function. Note: only POST requests to the webhook URL will be processed.
Important: When a request is sent to the webhook URL, RevCent does not return a response from the function execution. With the webhook trigger, RevCent will always reply with status 200 OK and a static response acknowledging the POST request. This allows third parties to POST data to your webhook without receiving a response containing sensitive data.
Static Response:
Status 200 OK
{
"result": "OK"
}
Your webhook URL is publicly accessible. Other than IP restrictions, RevCent does not provide any authentication methods for Webhook requests. You should always verify that the message posted to your webhook is authentic. We recommend verifying requests by having a form of authentication built into your function code. You can utilize the request body or the headers and url parameters provided in the functions' context object for authentication.
By default, functions are executed immediately when the trigger occurs. However, you have the option to delay the function execution by a specified period of time.
Note: Trigger timing is only applicable for Account Event and Webhook triggers. The URL, Schedule and Email Template triggers execute immediately without delay.
The default setting for Timing is immediate. This means when the trigger occurs, the function is executed without delay.
You can set a delay on the function execution for a minimum of 5 minutes to a maximum of 48 hours. Enter the amount of time and select the time unit. Unit can be minutes, hours or days.
You can restrict triggering a function to specific IP address. If enabled, only IP addresses listed will be able to post to the function Webhook or Function URL.
Note: IP restriction is only applicable to Webhook and URL triggers.
Indicate whether to implement IP restrictions.
If IP restricted is true, enter allowed IPv4 address on a new line. IP ranges are not supported.
Note: RevCent IP's are 52.3.146.218 and 34.224.171.255 if you are performing cross function execution.
Securely store values for use throughout all of your RevCent Functions. The values are turned into environment variables when the function is executed, and are accessible via the process.env
object within your code. Function Values are intended as a way to share common values for use throughout all functions. Use function environment variables to store function specific values and sensitive data.
Note: Environment variables added within a specific function take precedence over Function Values. If an environment variable within a function shares the same name as a Function Value, then the function environment variable will replace the Function Value for the same name during code execution.
View your function values by clicking Integrations > Functions > Values in the sidebar, or go to https://revcent.com/user/function-values
Create a function value by clicking the Create New Function Value button when viewing all function values.
Enter the name for the value. The name is what you will use to access the value within the process.env object. For example, if the name is “my value”, you would access it in your code by using process.env['my value']
The actual value. Values are securely stored by RevCent and are decrypted when the function is run.
Write an optional description to remind yourself what the value is for.
Each function is run (executed) in a secure virtual environment, using NodeJS 20.x. Functions do not share/store data or state across function runs. There are several important things to note regarding the function, including the handler, dependencies and limitations.
All external requests sent from a RevCent Function will have the following IP address: 52.3.146.218
The process.env
object is where function environment variables and Function Values are stored for use within a function. Before execution, your secure Function Values are decrypted and set as individual environment variables. Environment variables added within a specific function take precedence over Function Values. If an environment variable within a function shares the same name as a Function Value, then the functions' environment variable will replace the Function Value for the same name.
For example, if you have a Function Value named “My Value”, you would access it via process.env['My Value']
. However, if you had a function environment variable with the same name “My Value”, then the function environment variable will take precedence.
Below are the limitations with RevCent Functions.
The global object is accessible within your function code using the global
variable. The global object contains your functions' dependencies and pre-built RevCent tools.
RevCent Functions does not support require('module'). Instead, dependencies are made available within the global object. All installed dependencies listed in the functions' package.json are accessible using global['module_name']
.
Each function has a specific package.json, allowing whitelisted dependencies to be installed for use within a function. When you modify a functions' package.json, RevCent will bundle the dependencies specific to the function. Once the new bundle has been built, the dependencies will be available for use within the functions' code via the global object, i.e. global['module_name']
.
Note: When modifying the package.json, allow up to 2 minutes for the new dependencies to be bundled and available for use.
When modifying your function, click the Dependencies tab to view the functions' package.json. Modify the package.json dependencies directly, or select from the whitelisted dependencies dropdown. You can modify a dependencies' version within the package editor if necessary, including setting the version to “latest”.
Examples:
If you wanted to use the @slack/web-api module, you would use global['@slack/web-api']
If you wanted to use the request module, you would use global['request']
The current list of allowed dependencies. If you need a dependency not listed, please contact us.
[
'@mailchimp/mailchimp_marketing',
'@mailchimp/mailchimp_transactional',
'@sendgrid/mail',
'@slack/web-api',
'activecampaign',
'ajv',
'ascii-table',
'axios',
'crypto-js',
'facebook-nodejs-business-sdk',
'google-ads-api',
'google-libphonenumber',
'handlebars',
'html-to-text',
'input',
'json2csv',
'jsonwebtoken',
'klaviyo-sdk',
'lodash',
'mathjs',
'moment',
'moment-timezone',
'mongodb',
'mysql',
'nodemailer',
'openai',
'pg',
'qs',
'redis',
'request',
'shippo',
'superagent',
'twilio',
'uuid',
'validator',
'xml2js'
]
The global object also includes the “revcent” property, i.e. global['revcent']
, which contains tools, i.e. functions, for quickly accessing or modifying select RevCent items. All global['revcent']
functions return a callback, so you must use a callback when calling the global['revcent']
property.
Get a specific Key Value. The GetKeyValue function requires two arguments, the key and a callback function.
In the example below we are requesting the Key Value “my_key”. If an error, the error is returned, else the key value object for “my_key” is returned.
global['revcent'].GetKeyValue('my_key', function(error, key_value) {
if (error) {
console.log(error); // An error occurred, such as a non-existent key value.
} else {
console.log(key_value);
// Successful response will return the current key value object:
// {
// "key": "my_key",
// "value": "Some string",
// "key_type": "string",
// "updated": 1718051486
// }
}
});
Update the value of an existing Key Value. The UpdateKeyValue function requires three arguments: the key, the new value, and a callback function. The key argument is the Key Value you wish to update, and the value argument is the new value you wish the update. Note: you can only update a Key Value with key type of string. Pointer key types cannot be updated within a function.
In the example below we are updating the value for the Key Value with key “my_key”, with the new string “Updated string”. If an error, the error is returned, else the error is null and the updated “my_key” is returned.
global['revcent'].UpdateKeyValue('my_key', 'Updated string', function(error, key_value) {
if (error) {
console.log(error); // An error occurred, such as a non-existent key value.
} else {
console.log(key_value);
// Successful response will return the updated key value object:
// {
// "key": "my_key",
// "value": "Updated string",
// "key_type": "string",
// "updated": 1718051486
// }
}
});
When RevCent runs your function, your code is executed within a predefined handler. The handler has three arguments: event, context and callback.
Note: Do not include the handler in your code, your code is run within the handler by RevCent. See code examples.
function(event, context, callback) {
// your code ends up here
}
The event
argument is an object containing the data object.
The event.data
object is the actual data specific to trigger that executed the function. Refer to the table below as to the contents of the event.data object.
Trigger | context.source.trigger | event.data | Format |
---|---|---|---|
Account Event | account_event | Information specific to the account event, including the event date and item details. The items' details is contained in the event.data.item_details object. View the Events page for more information. |
JSON |
Schedule | schedule | A schedule trigger has an empty event.data string. | String |
Webhook | webhook | Webhook request body, as a string. Parse the request body based on the context.source.content_type . |
String |
URL | function_url | Function URL request body, as a string. Parse the request body based on the context.source.content_type . |
String |
Flow | flow | Information specific to the flow. The items' details is contained in the event.data.item_details object. A Customer Lifecycle flow will contain a customer event object. A Sale Lifecycle flow will contain a sale event object. |
JSON |
Email Template | email_template |
Information specific to the compilation of the email template. The items' details is contained in the Important: The function must return a valid JSON object in order to be amended to the input data as custom_data, i.e. |
JSON |
Auto Query | auto_query | The Auto Query results will be an array, accessible via event.data.query_results |
JSON |
AI Assistant | ai_assistant | The AI details will be contained within the event.data.ai_data object. View an example ai_data object. |
JSON |
Payment Profile | payment_profile | Please read the details on the Next-Gen Payment Profile event data. | JSON |
Below is an example event
argument object for an Account Event trigger. View examples of the event.data
object for all account event item types on the Events Page.
{
"data": {
"event_date": "2022-05-26T17:28:28.598Z", // Date the event took place
"event_id": "vE0Wk9omQPHRo5RMRXvK", // The account event ID
"event_notations": [ // All event notation(s).
"sale.created.success"
],
"event_trigger": "sale.created.success", // Notation which triggered the function.
"item_type": "sale", // The item type related to the event
"item_id": "nbO1jv0On1ukzvdg1lNz", // The ID of the item
"item_event": "created", // The item event
"item_details": {} // The details of the item, corresponds to the item_type. Would be sale details in this example.
}
}
Below is an example event
object for a Schedule trigger.
{
"data": "" // Schedule trigger data is always an empty string.
}
Below is an example event
object for a Webhook trigger.
{
"data": "{\"test\": \"webhooktest\"}" // Webhook trigger data is always a string. Parse string according to context.source.content_type
}
Below is an example event
object for a URL trigger.
{
"data": "{\"test\": \"urltest\"}" // URL trigger data is always a string. Parse string according to context.source.content_type
}
Below is an example event
object for a Flow trigger.
{
"data": {
"item_type": "customer",
"item_id": "Q4nGRNpLgpS92QqGLwlX",
"item_details": { // The details of the item, corresponds to the item_type. Would be customer details in this example.
"address_line_1": "1600 Pennsylvania Ave",
"address_line_2": "",
...
}
}
}
Below is an example event
object for an Email Template trigger.
{
"data": {
"item_type": "customer",
"item_id": "Q4nGRNpLgpS92QqGLwlX",
"item_details": { // The details of the item, corresponds to the item_type. Would be customer details in this example.
"address_line_1": "1600 Pennsylvania Ave",
"address_line_2": "",
...
}
}
}
Below is an example event
object for an Auto Query trigger.
{
"data": {
"query_results": [
{
"group_by_value": "Bundle Product",
"sale_sum_amount_gross": 625.92
},
{
"group_by_value": "Subscription Product",
"sale_sum_amount_gross": 208.64
}
]
}
}
Below is an example event
object for an AI Assistant custom action. Notice the ai_data object, specifically the custom_arguments object.
{
"data": {
"item_type": "customer",
"item_id": "Q4nGRNpLgpS92QqGLwlX",
"item_details": { // The details of the item, corresponds to the item_type. Would be customer details in this example.
"address_line_1": "1600 Pennsylvania Ave",
"address_line_2": "",
...
},
"ai_data": {
"custom_arguments": {
"customer_card_id": "XKob65Bn8qfqmWggp99B",
"customer_card_type": "VISA"
},
"assistant": {
"id": "asst_304kIxIGvO6JcJ4X9u9smGOY",
"object": "assistant",
"name": "Trigger Assistant",
"model": "gpt-4-turbo",
"top_p": 1,
"temperature": 0.2,
"metadata": {
"revcent_ai_assistant": "yRdBXQMj82T9Vrn8RpBE"
}
},
"thread": {
"id": "thread_ntI40nT1mwLwMrhDCdH58uAj",
"object": "thread",
"created_at": 1714575558,
"metadata": {
"revcent_ai_assistant_id": "yRdBXQMj82T9Vrn8RpBE",
"revcent_ai_assistant_name": "Trigger Assistant",
"revcent_item_type": "sale",
"revcent_item_id": "1RoNP4nAr0f6vk22lAAq"
}
},
"thread_messages": [
{
"id": "msg_0xkrYried4JVnZL7eHnSIk8w",
"object": "thread.message",
"created_at": 1714575804,
"thread_id": "thread_ntI40nT1mwLwMrhDCdH58uAj",
"run_id": null,
"role": "user",
"content": [
{
"type": "text",
"text": {
"value": "If a laptop was purchased run the following action: Assistant Data Function.",
"annotations": []
}
}
]
}
],
"thread_run": {
"id": "run_LKnxWPMnpNAvOUvkipshS8DG",
"object": "thread.run",
"created_at": 1714575805,
"assistant_id": "asst_304kIxIGvO6JcJ4X9u9smGOY",
"thread_id": "thread_ntI40nT1mwLwMrhDCdH58uAj",
"status": "requires_action",
"started_at": 1714575805,
"expires_at": 1714576405,
"required_action": {
"type": "submit_tool_outputs",
"submit_tool_outputs": {
"tool_calls": [
{
"id": "call_NeXFEOm6vANc1NoDUj1reK0V",
"type": "function",
"function": {
"name": "assistantDataFunction_Action",
"arguments": ""
}
}
]
}
},
"model": "gpt-4-turbo",
"tool_resources": {},
"metadata": {
"revcent_ai_request": "yRdWbvEzYVCVVbJW0mdJ",
"revcent_ai_assistant_id": "yRdBXQMj82T9Vrn8RpBE",
"revcent_ai_assistant_name": "Trigger Assistant",
"revcent_item_type": "sale",
"revcent_item_id": "1RoNP4nAr0f6vk22lAAq"
},
"temperature": 1,
"top_p": 1
}
}
}
}
Please read the Next-Gen Payment Profile section on function event data when triggered via a payment flow.
The context
argument is an object containing data related to the function run.
context. |
Description |
---|---|
source | The source object containing details on the source of the function execution. |
source.id | The ID of the source. I.e. the ID of the event, webhook, function, flow, AI assistant or email template |
source.name | The name of the source. [1] |
source.trigger | The function trigger. Values: account_event, webhook, function_url, flow, ai_assistant, email_template. |
source.method | The originating request method, GET or POST. [2] |
source.content_type | The originating request content type, useful for parsing event.data. [2] |
source.ip_address | The originating request IP address. [2] |
source.headers | An objecting containing the originating request headers. [2] |
source.url_params | An objecting containing the originating request URL parameters. [2] |
source.run_id | The flow run ID. [3] |
source.node_id | The ID of the node that triggered the function. [3] |
source.process_id | The flow process ID. [3] |
function | The function object containing details of the function being run. |
function.id | The ID of the function being run. |
function.name | The name of the function being run |
function_run | The function_run object containing details on the individual function run |
function_run.id | The ID of the individual function run. |
dependencies | An object containing the list of dependencies available, to use as a reference. |
1 Applicable to webhook, flow, AI assistant and email template triggers only.
2 Applicable to webhook and function URL triggers only.
3 Applicable to flow triggers only.
Below is an example context
object for an Account Event trigger.
{
"source": {
"id": "Q4l5oV0nvdt9ERJYLgGb",
"name": "Account Event",
"trigger": "account_event"
},
"function": {
"id": "Wm4noL2AEji2PolWo6qK",
"name": "Account Event Function"
},
"function_run": {
"id": "Q4l5oWG9rMuJAQkz0NzR"
},
"dependencies": {}
}
Below is an example context
object for a Schedule trigger.
{
"source": {
"id": "MWOKkZlYNKCwnZLqALbr",
"name": "Schedule Function",
"trigger": "schedule"
},
"function": {
"id": "MWOKkZlYNKCwnZLqALbr",
"name": "Schedule Function"
},
"function_run": {
"id": "Knl51G4Rdgs54VBJRpJ9"
},
"dependencies": {}
}
Below is an example context
object for a Webhook trigger.
{
"source": {
"id": "p2VEMp6REbvngimR2jvE",
"name": "Webhook Function",
"trigger": "webhook",
"method": "POST",
"content_type": "application/json",
"ip_address": "1.2.3.4",
"headers": {},
"url_params": {}
},
"function": {
"id": "vEgimR2jv6REbp2VEMpn",
"name": "Webhook Function"
},
"function_run": {
"id": "2rWZ9oMgYGsLvAnNKpy2"
},
"dependencies": {}
}
Below is an example context
object for a URL trigger.
{
"source": {
"id": "8rbjNL9rbkC8gw2OAa6k",
"name": "Get Subscription",
"trigger": "function_url",
"method": "POST",
"content_type": "application/json",
"ip_address": "1.2.3.4",
"headers": {},
"url_params": {}
},
"function": {
"id": "8rbjNL9rbkC8gw2OAa6k",
"name": "Get Subscription"
},
"function_run": {
"id": "6rlg462oL0HBbbW5wO95"
},
"dependencies": {}
}
Below is an example context
object for a Flow trigger.
{
"source": {
"id": "ajwG07KPAyFLPp10ny2V",
"name": "New Customer Flow",
"trigger": "flow",
"run_id": "5r71M2ZXP6TwVR2bpE68",
"node_id": "d514636e-b81b-4153-8382-5937109924c8",
"process_id": "5f48caaf-7952-40f0-b96a-667a6de14e50",
"prior_process_id": "a87174fd-9275-4111-b773-8dd57e103fcd"
},
"function": {
"id": "ZV1AEbRNO5HMlybdWYzQ",
"name": "Flow Function"
},
"function_run": {
"id": "l402L1qBy7CRZX2P7APL"
},
"dependencies": {}
}
Below is an example context
object for an Email Template trigger.
{
"source": {
"id": "ajzW4V4l8vtYWlqOoKj1",
"name": "New Sale Email",
"trigger": "email_template"
},
"function": {
"id": "6rQ24og16BuJgmdqyqVq",
"name": "Email Template Function"
},
"function_run": {
"id": "l402L1qBy7CRZX2P7APL"
},
"dependencies": {}
}
Below is an example context
object for an Auto Query trigger.
{
"source": {
"id": "ajzW4V4l8vtYWlqOoKj1",
"name": "My Auto Query",
"trigger": "auto_query"
},
"function": {
"id": "6rQ24og16BuJgmdqyqVq",
"name": "Auto Query Function"
},
"function_run": {
"id": "l402L1qBy7CRZX2P7APL"
},
"dependencies": {}
}
Below is an example context
object for an AI Assistant trigger.
{
"source": {
"id": "Q4l5oV0nvdt9ERJYLgGb",
"name": "My AI Assistant",
"trigger": "ai_assistant"
},
"function": {
"id": "Wm4noL2AEji2PolWo6qK",
"name": "AI Response Function"
},
"function_run": {
"id": "Q4l5oWG9rMuJAQkz0NzR"
},
"dependencies": {}
}
The callback
argument is a function which should be called when you wish to end the function run.
Important: In order to avoid timeout errors and automatic function disabling, you should always have a callback within your code to end the function run.
The callback function contains two arguments, error
and response
.
callback(error, response);
Will end the function with the error
returned.
let error = 'Something went wrong.';
callback(error);
Will end the function as successful with the response
returned. Notice the error argument is NULL.
let response = 'OK';
callback(null, response);
View our function examples repository on Github: https://github.com/RevCent/function-examples
If you are a third party and wish to offer users an easy method of connecting RevCent with your app, you can create a function import file which your users can import into RevCent without having to copy and paste code. If you are creating an import file we highly recommend you read this entire page, as well as the Events page thoroughly.
RevCent will not lint or validate the function_code string provided in the JSON. It is important that the code does not contain errors as this will cause the function to be automatically disabled when run.
Note: The RevCent user will need to manually enable the function after importing. Imported functions are initially disabled by default.
The file should be a JSON file, with the properties listed below.
Property | Format | Description | Required |
---|---|---|---|
name | string | The name of the function. | Yes |
description | string | A brief description of the function. | |
author | string | Let's the user know who created the import file. | |
trigger | string | The function trigger. Either “account_event", “webhook”, “schedule”, “ai_assistant”, “payment_profile” or “function_url”. Webhook and function URL's are automatically generated for the respective trigger. | Yes |
process_env | array | An array of function environment variables, each being an object containing a name and value property. These are specific to the function being imported and are not available for all functions within the users' RevCent account. | |
process_env.name | string | Individual environment variable name, used for accessing the value via process.env object. I.e. process.env[name]. | |
process_env.description | string | Individual environment variable description. Shown to the user when importing. | |
process_env.value | string | Individual environment variable value. The actual value when accessing the variable via process.env[name]. | |
process_env.required | boolean | Whether you want the variable value to not be empty when importing. Useful when you want the user to manually input a value. | |
ip_restricted | boolean | Indicated whether or not accessing/triggering the function via URL or Webhook should be IP restricted. More info. | |
ip_whitelist | array | An array of strings, each string being an individual IPv4 address. IP ranges are not supported. | |
timing_options | object | The timing options specific to the function. Only applicable for “account_event” and “webhook” triggers. More info. | |
timing_options.option | string | Either “immediate” or “delay”. Default is “immediate”. | |
timing_options.time_unit | string | If timing is “delay”, the time unit. Either “minutes” or “hours” | |
timing_options.time_value | integer | The integer value corresponding to the timing_options.time_unit. I.e. if timing_options.time_unit is “hours” and timing_options.time_value is 2, then the function execution is delayed for 2 hours. | |
cron_expression | string | If the trigger is “schedule”, a valid five-part cron expression is required. | |
cron_timezone | string | If the trigger is “schedule”, an optional timezone, i.e. “US/Eastern”. Default is “UTC”. | |
event_filter | array | If the trigger is “account_event", at least one account event notation is required. | |
function_code | string | The actual function code to be run when the function is triggered. More info. | Yes |
Below is an example JSON import file for a function which will be triggered on an account_event. View the Events page thoroughly for information on what is provided.
{
"name": "Acme Inc. Event Function",
"description": "Description of function.",
"author": "Acme Inc.", // Lets the user know who made the import file.
"trigger": "account_event", // Function will run based on the event_filter.
"event_filter": ["sale.created.success.paid"], // Function will run when a sale is created and paid successfully.
"process_env": [ // Custom environment variables to access in function code via process.env
{
"name": "api_key", // The process.env property
"description": "Acme API key found in Acme UI settings.", // A description of the variable.
"value": "1235", // process.env.api_key = "1235"
"required": true // Prevents value from being empty.
},
{
"name": "api_secret", // The process.env property
"description": "Acme API secret found in Acme UI settings.", // A description of the variable.
"value": "", // Leave empty if you want to require user to provide a value before importing.
"required": true // Prevents value from being empty.
}
],
"timing": { // Applicable to Account Event and Webhook triggers. Option to delay function from running. Default is immediate.
"option": "immediate",
"time_unit": "minutes",
"time_value": 0
},
"function_code": "// code comment \nconsole.log('This is an account event function.'); \ncallback(null, 'Account event function done!');"
}
Below is an example JSON import file for a function which will be triggered via a webhook URL. The webhook URL specific to the function will be generated after import.
{
"name": "Acme Inc. Webhook Function",
"description": "Description of function.",
"author": "Acme Inc.", // Lets the user know who made the import file.
"trigger": "webhook", // Function will run when the function webhook URL is called.
"process_env": [ // Custom environment variables to access in function code via process.env
{
"name": "api_key", // The process.env property
"description": "Acme API key found in Acme UI settings.", // A description of the variable.
"value": "1235", // process.env.api_key = "1235"
"required": true // Prevents value from being empty.
},
{
"name": "api_secret", // The process.env property
"description": "Acme API secret found in Acme UI settings.", // A description of the variable.
"value": "", // Leave empty if you want to require user to provide a value before importing.
"required": true // Prevents value from being empty.
}
],
"ip_restricted": false, // If you want to restrict by IP.
"ip_whitelist": [], // If IP restricted, provide addresses. Ranges not supported.
"timing": { // Applicable to Account Event and Webhook triggers. Option to delay function from running. Default is immediate.
"option": "immediate",
"time_unit": "minutes",
"time_value": 0
},
"function_code": "// code comment \nconsole.log('This is a webhook function.'); \ncallback(null, 'Webhook function complete!');"
}
Below is an example JSON import file for a function which will be triggered when accessing a function_url. The function URL specific to the function will be generated after import.
{
"name": "Acme Inc. URL Function",
"description": "Description of function.",
"author": "Acme Inc.", // Lets the user know who made the import file.
"trigger": "function_url", // Function will run when the function URL is called.
"process_env": [ // Custom environment variables to access in function code via process.env
{
"name": "api_key", // The process.env property
"description": "Acme API key found in Acme UI settings.", // A description of the variable.
"value": "1235", // process.env.api_key = "1235"
"required": true // Prevents value from being empty.
},
{
"name": "api_secret", // The process.env property
"description": "Acme API secret found in Acme UI settings.", // A description of the variable.
"value": "", // Leave empty if you want to require user to provide a value before importing.
"required": true // Prevents value from being empty.
}
],
"ip_restricted": false, // If you want to restrict by IP.
"ip_whitelist": [], // If IP restricted, provide addresses. Ranges not supported.
"function_code": "// code comment \nconsole.log('This is a function URL.'); \ncallback(null, 'Function complete!');"
}
The screenshot below shows the form the user will see when loading an import file in the RevCent web app. This form is presented to allow the user to make changes, including providing required environment variables specific to the function. Any required fields which are empty will prevent the function from being created.
Notice how each Environment Variable, taken from the example process_env array, displays the description associated with the value. This allows you to distribute the function import to users, with instructions on how to retrieve user specific values for each variable.