sendEmail Function via API

NateBI
NateBI Contributor
edited February 26 in Workflows

Hi Team.

I'm using this method: https://developer.domo.com/portal/bb75ce8b1c00f-code-engine-api#run-function

With the below details from postman (replaced inputs{} for this question)

```

POST https://{company}.domo.com/api/codeengine/v2/packages/{package_id_found_in_url}/versions/{version_integers}/functions/sendEmail
Authorization: Token (generated via Admin > Access Tokens)
body (JSON)
{
"inputVariables": {
"subject": "This is a test",
"text": "Hi there - I'm checking this lands in the body of the email",
"recipientsUserIds": [integer]
},
"settings": { "getLogs": false
}

I'm getting the following error:

{
"executionId": "",
"packageId": "this matches the input - redacted for the question",
"version": "matches input",
"functionName": "sendEmail",
"status": "FAILED",
"settings": {
"getLogs": false
},
"startedOn": "2025-02-26T20:29:32.665Z",
"startedBy": "user_id matched",
"completedOn": "2025-02-26T20:29:33Z",
"result": null,
"stdout": null,
"stderr": {
"log": [
"TypeError: Cannot read properties of null (reading 'length')\n at sendEmail (/var/task/function.js:63:45)\n at execute (/var/task/executor.js:47:44)\n at Object.<anonymous> (/var/task/executor.js:77:1)\n at Module._compile (node:internal/modules/cjs/loader:1469:14)\n at Module._extensions..js (node:internal/modules/cjs/loader:1548:10)\n at Module.load (node:internal/modules/cjs/loader:1288:32)\n at Module._load (node:internal/modules/cjs/loader:1104:12)\n at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:174:12)\n at node:internal/main/run_main_module:28:49"
]
},
"errorInformation": null
}

Please can someone advise (it's a response status of 200 so blackbox from there for me.

Best Answer

  • jaden.hoenes
    jaden.hoenes Domo Employee
    edited February 26 Answer ✓

    Hi!

    The CodeEngine API will always return a 200 with information about your function execution.

    You can read into the stdout, stderr, status, and errorInformation fields for more information. To retrieve the stdout logs (console.log in JavaScript or print in python) you can call the API with the getLogs setting as true in the request body.

    In this case it looks like an array isn't being passed into the inputVariables, yet on line 63 of your package it tries to access the length of that variable. Is this the globally available sendEmail function from the DOMO Notifications package? If so, what version?

    I believe the body should look like

    {
      "inputVariables": {
    "subject": "My Subject", "body": "My Email Body", "personRecipients": ["{userId}"], "groupRecipients": [], "attachments": [] }, "settings": { "getLogs": true } }
    • You can also open your package, and then open your dev tools and look at the network request made when you start your function and it works successfully. This should give you a working request body you can use in postman.
    • Any additional information you have would be great in helping get this working!

Answers

  • jaden.hoenes
    jaden.hoenes Domo Employee
    edited February 26 Answer ✓

    Hi!

    The CodeEngine API will always return a 200 with information about your function execution.

    You can read into the stdout, stderr, status, and errorInformation fields for more information. To retrieve the stdout logs (console.log in JavaScript or print in python) you can call the API with the getLogs setting as true in the request body.

    In this case it looks like an array isn't being passed into the inputVariables, yet on line 63 of your package it tries to access the length of that variable. Is this the globally available sendEmail function from the DOMO Notifications package? If so, what version?

    I believe the body should look like

    {
      "inputVariables": {
    "subject": "My Subject", "body": "My Email Body", "personRecipients": ["{userId}"], "groupRecipients": [], "attachments": [] }, "settings": { "getLogs": true } }
    • You can also open your package, and then open your dev tools and look at the network request made when you start your function and it works successfully. This should give you a working request body you can use in postman.
    • Any additional information you have would be great in helping get this working!
  • We discovered this problem in our sendEmail() function in CodeEngine. We have a fix ready and will be pushing it out soon.

  • NateBI
    NateBI Contributor

    Hi @jaden.hoenes thanks :

    Yes it's the sendEmail function from Domo notifications version 2.1.6

    You're right, it was the params name, I interpreted "any // these should match your function input parameters" from the documentation to mean the names of the variables the .js params get passed to (code engine fuction).

    Thanks!

  • NateBI
    NateBI Contributor
    edited February 27

    While I'm here @jaden.hoenes I'm now looking to access the share content functions (to share a card) and getting a

    Full authentication is required to access this resource
    

    I've seen the authentication documentation and I'm doing this:

    full_auth = "https://api.domo.com/oauth/token"
    data = {
    "grant_type": "client_credentials",
    "scope": "data dashboard workflow user"
    }
    response = requests.post(full_auth, data=data, auth=client_id, secret")))
    if response.status_code == 200:

    access_token = response.json().get("access_token")

    This returns an access token, that I feed into this:

    semi-psuedo: 
    
    "shareCardWithPerson":
    "version":"3.0.1",
    "function_name": "shareCardWithPerson"
    https://company.domo.com/api/codeengine/v2/packages/{package_id}/versions/{version}/functions/{function_name}" body = {
    "inputVariables": {
    "person": person,
    "card_id": card_id,
    },
    "settings": { "getLogs": True
    }
    }

    I'm wondering if by "full auth" it means including "account", "audit" and the other scope option (I don't recall now)