Chilkat Online Tools

Node.js / Zoho CRM REST APIs / Send GDPR-related data

Back to Collection Items

var os = require('os');
if (os.platform() == 'win32') {  
    if (os.arch() == 'ia32') {
        var chilkat = require('@chilkat/ck-node21-win-ia32');
    } else {
        var chilkat = require('@chilkat/ck-node21-win64'); 
    }
} else if (os.platform() == 'linux') {
    if (os.arch() == 'arm') {
        var chilkat = require('@chilkat/ck-node21-arm');
    } else if (os.arch() == 'x86') {
        var chilkat = require('@chilkat/ck-node21-linux32');
    } else {
        var chilkat = require('@chilkat/ck-node21-linux64');
    }
} else if (os.platform() == 'darwin') {
    if (os.arch() == 'arm64') {
        var chilkat = require('@chilkat/ck-node21-mac-m1');
    } else {
        var chilkat = require('@chilkat/ck-node21-macosx');
    }
}


function chilkatExample() {

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    var http = new chilkat.Http();
    var success;

    // Use this online tool to generate code from sample JSON: Generate Code to Create JSON

    // The following JSON is sent in the request body.

    // {
    //   "data": [
    //     {
    //       "from": {
    //         "user_name": "Patricia Boyle",
    //         "email": "p.boyle@abc.com"
    //       },
    //       "to": [
    //         {
    //           "user_name": "user1",
    //           "email": "user1email@zoho.com"
    //         }
    //       ],
    //       "subject": "Mail subject",
    //       "content": "<br><a href=\"${ConsentForm.en_US}\" id=\"ConsentForm\" class=\"en_US\" target=\"_blank\">Consent form link</a><br><br><br><br><br><h3><span style=\"background-color: rgb(254, 255, 102)\">REGARDS,</span></h3><div><span style=\"background-color: rgb(254, 255, 102)\">AZ</span></div><div><span style=\"background-color: rgb(254, 255, 102)\">ADMIN</span></div> <div></div>",
    //       "consent_email": true,
    //       "mail_format": "html",
    //       "data_subject_request": {
    //         "id": "{{data_subject_request_id}}",
    //         "type": "access"
    //       }
    //     }
    //   ]
    // }

    var json = new chilkat.JsonObject();
    json.UpdateString("data[0].from.user_name","Patricia Boyle");
    json.UpdateString("data[0].from.email","p.boyle@abc.com");
    json.UpdateString("data[0].to[0].user_name","user1");
    json.UpdateString("data[0].to[0].email","user1email@zoho.com");
    json.UpdateString("data[0].subject","Mail subject");
    json.UpdateString("data[0].content","<br><a href=\"${ConsentForm.en_US}\" id=\"ConsentForm\" class=\"en_US\" target=\"_blank\">Consent form link</a><br><br><br><br><br><h3><span style=\"background-color: rgb(254, 255, 102)\">REGARDS,</span></h3><div><span style=\"background-color: rgb(254, 255, 102)\">AZ</span></div><div><span style=\"background-color: rgb(254, 255, 102)\">ADMIN</span></div> <div></div>");
    json.UpdateBool("data[0].consent_email",true);
    json.UpdateString("data[0].mail_format","html");
    json.UpdateString("data[0].data_subject_request.id","{{data_subject_request_id}}");
    json.UpdateString("data[0].data_subject_request.type","access");

    // Adds the "Authorization: Bearer <access_token>" header.
    http.AuthToken = "<access_token>";

    // resp: HttpResponse
    var resp = http.PostJson3("https://domain.com/crm/v2.1/Leads/{{record_id}}/actions/send_mail","application/json",json);
    if (http.LastMethodSuccess == false) {
        console.log(http.LastErrorText);
        return;
    }

    console.log(resp.StatusCode);
    console.log(resp.BodyStr);


}

chilkatExample();

Curl Command

curl -X POST
	-H "Authorization: Bearer <access_token>"
	-d '{
    "data": [
        {
            "from": {
                "user_name": "Patricia Boyle",
                "email": "p.boyle@abc.com"
            },
            "to": [
                {
                    "user_name": "user1",
                    "email": "user1email@zoho.com"
                }
            ],
            "subject": "Mail subject",
            "content": "<br><a href=\"${ConsentForm.en_US}\" id=\"ConsentForm\" class=\"en_US\" target=\"_blank\">Consent form link</a><br><br><br><br><br><h3><span style=\"background-color: rgb(254, 255, 102)\">REGARDS,</span></h3><div><span style=\"background-color: rgb(254, 255, 102)\">AZ</span></div><div><span style=\"background-color: rgb(254, 255, 102)\">ADMIN</span></div> <div></div>",
            "consent_email": true,
            "mail_format": "html",
            "data_subject_request": {
                "id": "{{data_subject_request_id}}",
                "type": "access"
            }
        }
    ]
}'
https://domain.com/crm/v2.1/Leads/{{record_id}}/actions/send_mail

Postman Collection Item JSON

{
  "name": "Send GDPR-related data",
  "request": {
    "auth": {
      "type": "bearer",
      "bearer": [
        {
          "key": "token",
          "value": "{{access-token}}",
          "type": "string"
        }
      ]
    },
    "method": "POST",
    "header": [
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"data\": [\n        {\n            \"from\": {\n                \"user_name\": \"Patricia Boyle\",\n                \"email\": \"p.boyle@abc.com\"\n            },\n            \"to\": [\n                {\n                    \"user_name\": \"user1\",\n                    \"email\": \"user1email@zoho.com\"\n                }\n            ],\n            \"subject\": \"Mail subject\",\n            \"content\": \"<br><a href=\\\"${ConsentForm.en_US}\\\" id=\\\"ConsentForm\\\" class=\\\"en_US\\\" target=\\\"_blank\\\">Consent form link</a><br><br><br><br><br><h3><span style=\\\"background-color: rgb(254, 255, 102)\\\">REGARDS,</span></h3><div><span style=\\\"background-color: rgb(254, 255, 102)\\\">AZ</span></div><div><span style=\\\"background-color: rgb(254, 255, 102)\\\">ADMIN</span></div> <div></div>\",\n            \"consent_email\": true,\n            \"mail_format\": \"html\",\n            \"data_subject_request\": {\n                \"id\": \"{{data_subject_request_id}}\",\n                \"type\": \"access\"\n            }\n        }\n    ]\n}",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{api-domain}}/crm/v2.1/Leads/{{record_id}}/actions/send_mail",
      "host": [
        "{{api-domain}}"
      ],
      "path": [
        "crm",
        "v2.1",
        "Leads",
        "{{record_id}}",
        "actions",
        "send_mail"
      ]
    },
    "description": "Use the following keys when you have enabled GDPR compliance settings, and want to send an email asking for the user's consent or request data. Note that it is mandatory to send the consent form in the email's \"content\" key, when you ask for the lead's/contact's consent.\n\n"
  },
  "response": [
    {
      "name": "OAUTH_SCOPE_MISMATCH",
      "originalRequest": {
        "method": "POST",
        "header": [
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"data\": [\n        {\n            \"from\": {\n                \"user_name\": \"Patricia Boyle\",\n                \"email\": \"p.boyle@abc.com\"\n            },\n            \"to\": [\n                {\n                    \"user_name\": \"user1\",\n                    \"email\": \"user1email@zoho.com\"\n                }\n            ],\n            \"subject\": \"Mail subject\",\n            \"content\": \"<br><a href=\\\"${ConsentForm.en_US}\\\" id=\\\"ConsentForm\\\" class=\\\"en_US\\\" target=\\\"_blank\\\">Consent form link</a><br><br><br><br><br><h3><span style=\\\"background-color: rgb(254, 255, 102)\\\">REGARDS,</span></h3><div><span style=\\\"background-color: rgb(254, 255, 102)\\\">AZ</span></div><div><span style=\\\"background-color: rgb(254, 255, 102)\\\">ADMIN</span></div> <div></div>\",\n            \"consent_email\": true,\n            \"mail_format\": \"html\",\n            \"data_subject_request\": {\n                \"id\": \"{{data_subject_request_id}}\",\n                \"type\": \"access\"\n            }\n        }\n    ]\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{api-domain}}/crm/v2.1/Leads/{{record_id}}/actions/send_mail",
          "host": [
            "{{api-domain}}"
          ],
          "path": [
            "crm",
            "v2.1",
            "Leads",
            "{{record_id}}",
            "actions",
            "send_mail"
          ]
        }
      },
      "status": "Unauthorized",
      "code": 401,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Thu, 13 May 2021 08:21:44 GMT"
        },
        {
          "key": "Content-Type",
          "value": "application/json;charset=utf-8"
        },
        {
          "key": "Content-Length",
          "value": "113"
        },
        {
          "key": "Connection",
          "value": "keep-alive"
        },
        {
          "key": "Referrer-Policy",
          "value": "strict-origin"
        },
        {
          "key": "X-Content-Type-Options",
          "value": "nosniff"
        },
        {
          "key": "X-XSS-Protection",
          "value": "1; mode=block"
        },
        {
          "key": "Pragma",
          "value": "no-cache"
        },
        {
          "key": "Cache-Control",
          "value": "no-cache"
        },
        {
          "key": "Expires",
          "value": "Thu, 01 Jan 1970 00:00:00 GMT"
        },
        {
          "key": "X-Frame-Options",
          "value": "SAMEORIGIN"
        },
        {
          "key": "X-Download-Options",
          "value": "noopen"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"code\": \"OAUTH_SCOPE_MISMATCH\",\n    \"details\": {},\n    \"message\": \"invalid oauth scope to access this URL\",\n    \"status\": \"error\"\n}"
    }
  ]
}