How to set up a Lambda function

To get your Lambda function up and running in Insightly, you'll need to create the function, then set the trigger for it. There are two types of triggers:

  • A timed trigger which runs the function every hour or every day.
  • A workflow action, which triggers the function when certain criteria that you specify are met in Insightly.

You may add up to 50 functions to your account.

A few things to note:

  • Handler names need to be prefixed by "index." to properly reference the dynamically generated document.
  • Console.log() doesn't write anywhere visible.
  • Although the package says it targets Node.js 18.x, the fetch API isn't available. Use the "https" module.

How to Create a Lambda Function

  1. Either prepare your code for manual entry or create a Lambda function deployment package written in one of the supported languages (JavaScript, C#, Java, or Python).
  2. Go to System Settings > Lambda Functions.
  3. Click New Function.
  4. Enter a name and description for the function.
  5. Choose the Runtime language you've used to write your code.
  6. Select the Invocation Payload.
  7. Enter the Handler Name.
  8. When you choose Node.js or Python, you can choose Edit Code Inline or Upload a .ZIP file. Java and C# only offer the upload option, so you'll skip the next step.

    If you set up the Lambda function to be triggered via a workflow automation, the function's input will be a JSON object with the structure below.

    The "newValue" field will contain the record that the workflow was triggered on and, if you selected "New and Old Field Value" for the "Invocation Payload" in your Lambda settings, the "oldEntity" field will contain the record's values before the edit that triggered the workflow.

    Here is an example of a Project record as the input:

     {  "insightly": {    "recordId": long,    "recordType": "Project",    "operation": "EDIT",    "newValue": {      "PROJECT_ID": long,      "PROJECT_NAME": "string",      "STATUS": "string",      "PROJECT_DETAILS": "string",      "STARTED_DATE": "2020-08-30T23:48:55.839Z",      "COMPLETED_DATE": "2020-08-30T23:48:55.839Z",      "OPPORTUNITY_ID": long,      "CATEGORY_ID": long,      "PIPELINE_ID": long,      "STAGE_ID": long,      "IMAGE_URL": "string",      "OWNER_USER_ID": long,      "DATE_CREATED_UTC": "2020-08-30T23:48:55.839Z",      "DATE_UPDATED_UTC": "2020-08-30T23:48:55.839Z",      "LAST_ACTIVITY_DATE_UTC": "2020-08-30T23:48:55.839Z",      "NEXT_ACTIVITY_DATE_UTC": "2020-08-30T23:48:55.839Z",      "CREATED_USER_ID": long,      "RESPONSIBLE_USER_ID": long,      "CUSTOMFIELDS": [        {          "FIELD_NAME": "string",          "FIELD_VALUE": "object",          "CUSTOM_FIELD_ID": "string"        }      ],      "TAGS": [          "TAG_NAME": "string"      ]    },    "oldEntity": {      "PROJECT_ID": long,      "PROJECT_NAME": "string",      "STATUS": "string",      "PROJECT_DETAILS": "string",      "STARTED_DATE": "DateTime",      "COMPLETED_DATE": "DateTime",      "OPPORTUNITY_ID": long,      "CATEGORY_ID": long,      "PIPELINE_ID": long,      "STAGE_ID": long,      "IMAGE_URL": "string",      "OWNER_USER_ID": long,      "DATE_CREATED_UTC": "2020-08-30T23:48:55.839Z",      "DATE_UPDATED_UTC": "2020-08-30T23:48:55.839Z",      "LAST_ACTIVITY_DATE_UTC": "2020-08-30T23:48:55.839Z",      "NEXT_ACTIVITY_DATE_UTC": "2020-08-30T23:48:55.839Z",      "CREATED_USER_ID": long,      "RESPONSIBLE_USER_ID": long,      "CUSTOMFIELDS": [        {          "FIELD_NAME": "string",          "FIELD_VALUE": "object",          "CUSTOM_FIELD_ID": "string"        }      ],      "TAGS": [          "TAG_NAME": "string"      ]    }  }}
  9. If you choose Edit Code Inline, write or copy your code in the field that appears further down the page.

    When your function references an Insightly object, structure the payload in the following way. Refer to our API documentation for all available fields and record types.

     { "entity": { "LEAD_ID": 45610, "SALUTATION": "Your Honor", "TITLE": "Judge", "FIRST_NAME": "Judy", "LAST_NAME": "Sheindlin", "ORGANIZATION_NAME": "The Court", "PHONE_NUMBER": "202-555-7845", "MOBILE_PHONE_NUMBER": "202-555-9552", "EMAIL_ADDRESS": "", "WEBSITE_URL": "", "OWNER_USER_ID": 1556, "DATE_CREATED_UTC": "2017-08-30T23:48:55.839Z", "DATE_UPDATED_UTC": "2017-08-30T23:48:55.839Z", "CONVERTED": true, "CONVERTED_DATE_UTC": "2017-08-30T23:48:55.839Z", }}
  10. If you choose Upload a .ZIP file, click Upload to select and upload your package file. The package must be less than 50MB in size.
  11. Enter Environment Variables. Click Add New Variableto add more than one.
    A few notes on variables:
    • The total size of your set of variables cannot exceed 4 KB
    • Package all dependencies into your Lambda function code
    • Each one must start with letters [a-zA-Z]
    • Fields can only contain alphanumeric characters and underscores ([a-zA-Z0-9_]
  12. Click Save Function.
  13. Your new function will now appear in the Lambda Functions list.
  14. Now that your function is active, you'll be able to select it from the Actions menu when creating a workflow.
  15. To add an hourly or daily timer, click the function's name.
  16. Click Add Scheduled Trigger for Function.
  17. Choose whether to run the function every hour or every day at a specific time and click Save Schedule.

When you view the function, you can see the workflows and schedules that trigger it. Functions will be set with a 30 second timeout. If a function fails to run 3 consecutive times, it will be automatically disabled.


Example Video

Currency Conversion:

Was this article helpful?