Chilkat Online Tools

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

Back to Collection Items

integer li_rc
oleobject loo_Http
integer li_Success
oleobject loo_Json
oleobject loo_Resp

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

loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
    destroy loo_Http
    MessageBox("Error","Connecting to COM object failed")
    return
end if

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

loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")

loo_Json.UpdateString("data[0].from.user_name","Patricia Boyle")
loo_Json.UpdateString("data[0].from.email","p.boyle@abc.com")
loo_Json.UpdateString("data[0].to[0].user_name","user1")
loo_Json.UpdateString("data[0].to[0].email","user1email@zoho.com")
loo_Json.UpdateString("data[0].subject","Mail subject")
loo_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>")
loo_Json.UpdateBool("data[0].consent_email",1)
loo_Json.UpdateString("data[0].mail_format","html")
loo_Json.UpdateString("data[0].data_subject_request.id","{{data_subject_request_id}}")
loo_Json.UpdateString("data[0].data_subject_request.type","access")

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

loo_Resp = create oleobject
li_rc = loo_Resp.ConnectToNewObject("Chilkat.HttpResponse")

li_Success = loo_Http.HttpJson("POST","https://domain.com/crm/v2.1/Leads/{{record_id}}/actions/send_mail",loo_Json,"application/json",loo_Resp)
if li_Success = 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_Json
    destroy loo_Resp
    return
end if

Write-Debug string(loo_Resp.StatusCode)
Write-Debug loo_Resp.BodyStr


destroy loo_Http
destroy loo_Json
destroy loo_Resp

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