{"method":"POST","path":"https://api.revcent.com/v2/functions/{function_id}","summary":"Edit A Function","description":"Edit a previously created Function using the Function ID. Only include the properties you wish to modify. For example, if you only want to modify the name of the Function, then only include the name property in the request body. Before making changes to a function you must read more about functions at https://kb.revcent.com/en/integrations/functions to understand how to properly set up and configure a function, including the function code, event source settings and execution environment. View markdown documentation at https://revcent.com/documentation/markdown/mcp/operation/EditFunction.md for an in-depth overview of this operation.","operationId":"EditFunction","parameters":[{"in":"path","name":"function_id","description":"The Function ID","required":true,"schema":{"type":"string","title":"Function ID","description":"A 20 character Function ID.","minLength":20,"maxLength":20}}],"requestBody":{"content":{"application/json":{"schema":{"additionalProperties":false,"properties":{"name":{"type":"string","description":"The Function name. Must be unique from other Function names."},"description":{"type":"string","description":"The Function description."},"enabled":{"type":"boolean","description":"Whether the Function is enabled."},"function_code":{"description":"The JavaScript code of the Function.<br><br>Important: A callback must be provided within the function code to end each invocation. Please read more about the execution handler at <a href=\"https://kb.revcent.com/en/integrations/functions#execution-handler\" target=\"_blank\">https://kb.revcent.com/en/integrations/functions#execution-handler</a> to understand how to end a function invocation using the callback(error, response) method.","type":"string"},"event_source":{"description":"The event source setting determines how the Function will be triggered, a.k.a. code executed.<br><br>Trigger Options:<br>Account Event: Function is triggered by RevCent automatically when a specific event occurs.<br>Schedule: Function is triggered by RevCent on a fixed schedule using a cron expression.<br>URL: Trigger the function using a HTTP GET or POST request with a response determined by the function. Useful for performing immediate operations or requesting data.<br>Webhook: Send a notification to the function with an empty response using a HTTP POST request. Useful for allowing third parties to post data.<br>API/AI: Trigger the function using the RevCent API, as an AI System Tool, as a Filter Function or as a Pre-Agent function.<br>Email Template: Generate custom data for an Email Template<br>Payment Profile: Run a function during the processing of a Next-Gen payment profile.","type":"string","enum":["account_event","api_direct","email_template","payment_profile","function_url","schedule"]},"account_event_notations":{"type":"array","description":"If the event_source is set to 'account_event', you can specify one or more account event notations to trigger the function when those specific account events occur. An account event notation is a string that represents a specific account event. When the specified account event(s) occur, the system will trigger the function to run the associated code.","items":{"type":"string","description":"The notation for the account event trigger. Read more at https://kb.revcent.com/en/revcent-account/events to understand notation formatting and their associated event data.","enum":["ai_memo.created","chargeback.created","check_direct.created","customer.created","customer.updated.add_card","customer.updated.address","customer.updated.customer_group","customer.updated.customer_group.added","customer.updated.customer_group.removed","customer.updated.disabled","customer.updated.enabled","discount.created","fraud_detection.created","fraud_detection.updated.false_positive","invoice.created","note.created","offline_payment.created","paypal_dispute.created","paypal_transaction.created","pending_refund.created","pending_refund.created.product_sale","pending_refund.created.product_sale.full","pending_refund.created.product_sale.partial","pending_refund.created.shipping","pending_refund.created.shipping.full","pending_refund.created.shipping.full.has_fulfillment","pending_refund.created.shipping.full.no_fulfillment","pending_refund.created.shipping.has_fulfillment","pending_refund.created.shipping.no_fulfillment","pending_refund.created.shipping.partial","pending_refund.created.shipping.partial.has_fulfillment","pending_refund.created.shipping.partial.no_fulfillment","pending_refund.created.subscription_renewal","pending_refund.created.subscription_renewal.full","pending_refund.created.subscription_renewal.partial","pending_refund.created.tax","pending_refund.created.tax.full","pending_refund.created.tax.partial","product.created","product.deleted","product.updated","product_sale.created","sale.created","sale.created.failed","sale.created.failed.declined","sale.created.failed.error","sale.created.failed.no_gateway","sale.created.failed.fraud_detected","sale.created.failed.merchant_error","sale.created.failed.merchant_hold","sale.created.success","sale.created.success.has_salvage","sale.created.success.is_upsell","sale.created.success.paid","sale.created.success.paid.has_salvage","sale.created.success.paid.is_upsell","sale.created.success.pending","sale.created.success.pending.is_upsell","sale.updated.fraud_alert.added","sale.updated.fraud_alert.removed","salvage_transaction.created","salvage_transaction.updated.processed","salvage_transaction.updated.processed.failed","salvage_transaction.updated.processed.success","sentinel.alert","sentinel.alert.fraud_detected","sentinel.alert.firewall_block","shipping.created","shipping.created.has_fulfillment","shipping.created.no_fulfillment","shipping.updated.delivered","shipping.updated.ship_to","shipping.updated.shipped","subscription.created","subscription.updated.renewed","subscription.updated.renewed.failed","subscription.updated.renewed.success","subscription.updated.status","subscription.updated.status.active","subscription.updated.status.cancelled","subscription.updated.status.occurrence_limit","subscription.updated.status.overdue","subscription.updated.status.suspended","subscription_renewal.updated.failed","subscription_renewal.updated.success","tax.created","transaction.created","trial.created","trial.updated.cancelled","trial.updated.expired","trial.updated.expired.failed","trial.updated.expired.success","trial.updated.extended","trial.updated.shortened"]}},"account_event_filters":{"type":"object","additionalProperties":false,"description":"If the event_source is set to 'account_event', filters can be applied to account events to determine whether the function should be triggered when the specified account event(s) occur. For example, if you only want a function to trigger when a sale is made for a specific campaign, you can set up a filter for one or more campaign ID's. When the account event occurs, the system will check if the filters are met before triggering the function to run the associated code.","properties":{"campaign_filter":{"description":"The campaign filter checks for the presence of one or more campaign ID's in the related event, and if present whether it matches the specified value.","type":"array","items":{"type":"string","description":"A 20 character campaign ID to filter for."}}}},"timing_options":{"type":"object","additionalProperties":false,"description":"Timing options determine when the function runs after being triggered. If not provided, the function will run immediately after being triggered. Only applies to functions with an event_source set to 'account_event'.","properties":{"timing":{"description":"The timing setting determines when the function runs after being triggered. Default is immediate. If set to 'delay', the function will run after the specified delay time has passed.","type":"string","enum":["immediate","delay"]},"time_unit":{"description":"The time unit for the delay. This is required if timing is set to 'delay'.","type":"string","enum":["minutes","hours"]},"time_value":{"description":"The time value for the delay. This is required if timing is set to 'delay'. For example, if you want the function to run 2 hours after being triggered, you would set timing to 'delay', time_unit to 'hours', and time_value to 2.","type":"integer"}}},"cron_expression":{"type":"string","description":"The cron expression that determines when the function will be triggered. Applies only to functions with an event source set to 'schedule'. The cron expression must be a valid 5 part cron expression."},"cron_timezone":{"type":"string","description":"The timezone for the cron expression. Applies only to functions with an event source set to 'schedule'. If not provided, UTC will be used. The timezone must be a valid IANA timezone string."},"dependencies":{"description":"A list of dependencies required for the Function. Only specific dependencies are supported. Dependencies are accessed within the function code using the 'global[\"<dependency_name>\"]' syntax. Do not use require(), import, or any other module loading mechanism as dependencies are already available via the global object.<br><br>Note: When modifying dependencies it may take up to 2 minutes for the dependencies to properly update in the functions provisioned environment.<br><br>Important: If providing the dependencies object, any existing dependencies will be replaced with those submitted. To ensure any previous dependencies are preserved, please use the GetFunction operation and include existing dependencies as well.","type":"array","items":{"type":"object","additionalProperties":false,"properties":{"name":{"description":"The name of the dependency.","type":"string","enum":["@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"]},"version":{"description":"The version of the dependency. Please ensure that the version exists and is valid to prevent errors when triggering the function.","type":"string"}}}},"environment_variables":{"description":"A list of environment variables that are available to the Function when it is triggered. Environment variables are accessed within the function code using the 'process.env[\"<env_variable_name>\"]' syntax. When a function is triggered, encrypted environment variables are decrypted and provided to the function, but when retrieving function details via the API, encrypted environment variable values are hidden and not provided. This allows you to have sensitive information such as API keys stored as encrypted environment variables, which can be used by the function when triggered, but are not exposed when retrieving function details.<br><br>Important: When editing a function, if you include the environment_variables property in the request body, RevCent will only upsert environment variables, i.e. existing environment variables will be left intact, new ones will be added/encrypted, and any matching environment variable names will have their value replaced. Providing the environment variables array will not overwrite all existing environment variables for the function. Only include the environment_variables property if you wish to add new environment variables or update existing ones.","type":"array","items":{"type":"object","additionalProperties":false,"properties":{"name":{"description":"The name of the environment variable, which would be accessed within the function code using the 'process.env[\"<env_variable_name>\"]' syntax.","type":"string"},"value":{"description":"The value of the environment variable.","type":"string"}}}},"ip_restricted":{"description":"Whether the function is IP restricted. If true, only requests originating from allowed IP addresses will be able to trigger the function. This only applies to functions with the event_source set to 'function_url' or 'webhook'.","type":"boolean"},"ip_whitelist":{"description":"If the function is IP restricted, the IP whitelist is the list of allowed IPv4 addresses that can trigger the function. Each entry should be a valid IPv4 IP address. Ranges are not supported. This only applies to functions with the event_source set to 'function_url' or 'webhook'.","type":"array","items":{"type":"string","description":"A valid IPv4 address."}},"custom_arguments":{"description":"A list of custom arguments which should be provided as a name value object within the custom_arguments array when triggering the Function using the TriggerFunction operation. Only available for functions with an event source set to 'api_direct'.<br><br>Custom arguments are intended to be used by AI to infer values when triggering the Function. For example, if you have a custom argument with the description 'Parse the campaign ID from the sale item details.', when triggering the Function using the TriggerFunction operation, you can have AI read the custom argument description and infer a value for the custom argument based on the sale item details.<br><br>Important: If providing the custom_arguments array, any existing custom_arguments will be replaced with those submitted. To ensure any previous custom_arguments are preserved, please use the GetFunction operation and include existing custom arguments in the EditFunction request.","type":"array","items":{"type":"object","additionalProperties":false,"properties":{"name":{"description":"The name of the custom argument, which should be the name within the custom_arguments array object when triggering a Function using the TriggerFunction operation.<br><br>Note: Custom argument names should contain letters and underscores only, with no spaces.","type":"string"},"description":{"description":"The description of the custom argument determines what the inferred value should be when triggering the function. When triggering the Function using the TriggerFunction operation, you should: Read the custom arguments' description, then provide the inferred value when triggering the function.","type":"string"}}}}},"type":"object"}}},"required":true},"responses":{"200":{"content":{"application/json":{"schema":{"description":"","properties":{"api_call_id":{"type":"string","description":"A 20 character API call ID.","minLength":20,"maxLength":20},"api_call_unix":{"description":"Unix timestamp of when the API call was initiated.","type":"integer","format":"unix-time"},"code":{"description":"API call response code.","type":"integer","format":"int32","enum":[1]},"function_id":{"type":"string","title":"Function ID","description":"A 20 character Function ID.","minLength":20,"maxLength":20},"result":{"type":"string"}},"type":"object","additionalProperties":false}}},"description":"Successful response."},"default":{"content":{"application/json":{"schema":{"description":"","properties":{"api_call_id":{"type":"string","description":"A 20 character API call ID.","minLength":20,"maxLength":20},"api_call_unix":{"description":"Unix timestamp of when the API call was initiated.","type":"integer","format":"unix-time"},"code":{"description":"This value indicates that there is an error. Will always be 0.","type":"integer","enum":[0]},"error_code":{"description":"The specific error code.","type":"string"},"message":{"description":"A human readable description of the error.","type":"string"},"result":{"description":"A description of the API call result.","type":"string"}},"title":"APIStandardErrors","type":"object","additionalProperties":false}}},"description":"Error response."}}}