Chilkat Online Tools

VBScript / Zoho CRM REST APIs / Send GDPR-related data

Back to Collection Items

Dim fso, outFile
Set fso = CreateObject("Scripting.FileSystemObject")
'Create a Unicode (utf-16) output text file.
Set outFile = fso.CreateTextFile("output.txt", True, True)

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

' For versions of Chilkat < 10.0.0, use CreateObject("Chilkat_9_5_0.Http")
set http = CreateObject("Chilkat.Http")

' 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"
'       }
'     }
'   ]
' }

' For versions of Chilkat < 10.0.0, use CreateObject("Chilkat_9_5_0.JsonObject")
set json = CreateObject("Chilkat.JsonObject")
success = json.UpdateString("data[0].from.user_name","Patricia Boyle")
success = json.UpdateString("data[0].from.email","p.boyle@abc.com")
success = json.UpdateString("data[0].to[0].user_name","user1")
success = json.UpdateString("data[0].to[0].email","user1email@zoho.com")
success = json.UpdateString("data[0].subject","Mail subject")
success = 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>")
success = json.UpdateBool("data[0].consent_email",1)
success = json.UpdateString("data[0].mail_format","html")
success = json.UpdateString("data[0].data_subject_request.id","{{data_subject_request_id}}")
success = json.UpdateString("data[0].data_subject_request.type","access")

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

' resp is a Chilkat.HttpResponse
Set resp = http.PostJson3("https://domain.com/crm/v2.1/Leads/{{record_id}}/actions/send_mail","application/json",json)
If (http.LastMethodSuccess = 0) Then
    outFile.WriteLine(http.LastErrorText)
    WScript.Quit
End If

outFile.WriteLine(resp.StatusCode)
outFile.WriteLine(resp.BodyStr)


outFile.Close

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}"
    }
  ]
}