Workflows

Workflows

sendEmail Function via API

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)

```

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

I'm getting the following error:

  1. {
  2. "executionId": "",
  3. "packageId": "this matches the input - redacted for the question",
  4. "version": "matches input",
  5. "functionName": "sendEmail",
  6. "status": "FAILED",
  7. "settings": {
  8. "getLogs": false
  9. },
  10. "startedOn": "2025-02-26T20:29:32.665Z",
  11. "startedBy": "user_id matched",
  12. "completedOn": "2025-02-26T20:29:33Z",
  13. "result": null,
  14. "stdout": null,
  15. "stderr": {
  16. "log": [
  17. "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"
  18. ]
  19. },
  20. "errorInformation": null
  21. }

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

Welcome!

It looks like you're new here. Members get access to exclusive content, events, rewards, and more. Sign in or register to get started.
Sign In

Best Answer

  • 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

    1. {
    2. "inputVariables": {
    3. "subject": "My Subject",
    4. "body": "My Email Body",
    5. "personRecipients": ["{userId}"],
    6. "groupRecipients": [],
    7. "attachments": []
    8. },
    9. "settings": {
    10. "getLogs": true
    11. }
    12. }
    • 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

  • 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

    1. {
    2. "inputVariables": {
    3. "subject": "My Subject",
    4. "body": "My Email Body",
    5. "personRecipients": ["{userId}"],
    6. "groupRecipients": [],
    7. "attachments": []
    8. },
    9. "settings": {
    10. "getLogs": true
    11. }
    12. }
    • 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.

  • 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!

  • 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

    1. Full authentication is required to access this resource

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

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

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

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

    1. semi-psuedo:
    2.  
    3. "shareCardWithPerson":
    4. "version":"3.0.1",
    5. "function_name": "shareCardWithPerson"
    6.  

    7. https://company.domo.com/api/codeengine/v2/packages/{package_id}/versions/{version}/functions/{function_name}"
    8.  
    9. body = {
    10. "inputVariables": {
    11. "person": person,
    12. "card_id": card_id,
    13. },
    14. "settings": { "getLogs": True
    15. }
    16. }

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

Welcome!

It looks like you're new here. Members get access to exclusive content, events, rewards, and more. Sign in or register to get started.
Sign In