javascriptarraysjsonmicrosoft-graph-apiservicenow

How to send email more than one "cc Recipients" using rest api v1.0 in JavaScript


I am working with Microsoft graph api. Just need to know that how i can send email more than one recipient using below code. I am trying with attached code but giving the below error in response body.

test 1 {"error":{"code":"BadRequest","message":"Property ccRecipients in payload has a value that does not match schema.","innerError":{"date":"2023-09-05T19:14:25","request-id":"4786cf69-9ef9-4d9b-83c4-8db8a1005291","client-request-id":"4786cf69-9ef9-4d9b-83c4-8db8a1005291"}}}
var ccaddresses = current.getValue('copied').split(',');
var ccRe = [];

for (i = 0; i < ccaddresses.length; i++) {
    ccRe.push({
        "emailAddress": {
            "addresss": ccaddresses[i]+''
        }
    });
}



// Set the request body
var requestBody = {

    "message": {
        "subject": current.getValue('subject'),
        "body": {
            "contentType": "html",
            "content": current.getValue('body')
        },
        "toRecipients": [{
            "emailAddress": {
                "address": current.getValue('direct')
            }
        }],
        "ccRecipients": JSON.stringify(ccRe)
    },
    "saveToSentItems": "true"
};

I am getting email id in cc like below.

"toRecipients":[{"emailAddress":{"address":"brijmohan.kushwaha@test.co.in"}}],"ccRecipients":"[{\"emailAddress\":{\"addresss\":\"vipul.kush@test.com\"}},{\"emailAddress\":{\"addresss\":\" deepak.kushwaha@test.com\"}}]"},"saveToSentItems":"true"}

Solution

  • You have a mistake in the property name eg

    "addresss": ccaddresses[i]+''
    

    should be

    "address": ccaddresses[i]+''
    

    eg one too many s, that seems to be what the error is complaining about the rest looks okay.