ServerConnect: splitting a post value for API action

Hi everyone,

I’m not experienced with arrays on the server side, I have a use case where I’m posting a number of email addresses separated by a comma (to1@email.com, to2@email.com, to3@email.com):
image

I then need to break down the array, and for eah, generate a json portion of code:

 {
        "emailAddress": {
          "address": "to1@email.com"
        }
      },

So that it fits the requirements of a graph API action:

  "message": {
    "subject": "Multiple recipients test",
    "body": {
      "contentType": "Text",
      "content": "Test."
    },
    "toRecipients": [
      {
        "emailAddress": {
          "address": "to1@email.com"
        }
      },
      {
        "emailAddress": {
          "address": "to2@email.com"
        }
      }
    ],
    "ccRecipients": [
      {
        "emailAddress": {
          "address": "cc1@email.com"
        }
      },
      {
        "emailAddress": {
          "address": "cc2@email.com"
        }
      }
    ]
  },
  "saveToSentItems": "true"
}

I’d appreciate any guidance.

The POST value coming over is a string, so you can start by creating an array in a set value action:

$_POST.es_to.replace(' ', '').split(',')

Then you can repeat on that array to build up your json.

Thanks for your suggestion @mebeingken,

I apologize as arrays have always eluded me and therefore have little experience to help me undertstand. Here is a test api action where I just want to navigate through the array and display individual email addresses (if I get that, I can build the json comfortably):

However, this is the output I get:
image

What am I getting wrong? I’ve tried defining the values as arrays rather than strings, the outcome is the same.

It looks like you renamed the POST input. The “es_to” in the set value should now be “to”.

Thanks very much Ken - I think I’ve got enough to take it from here. Your help has been invaluable @mebeingken

1 Like