Unicode C Requires Chilkat v11.0.0+
Unicode C
SendGrid: Send two private appointment reminders in one request
See more SendGrid Examples
Create an active reminder template with subject Appointment reminder and body Hello {{first_name}}, your appointment is {{appointment_time}}. Use your template ID, verified sender and two test addresses. Each recipient has a separate personalization; placing both addresses in a single To array would expose them to one another and share the same template data.
Chilkat Unicode C Downloads
#include <C_CkHttpW.h>
#include <C_CkHttpResponseW.h>
#include <C_CkJsonObjectW.h>
void ChilkatSample(void)
{
BOOL success;
HCkHttpW http;
HCkHttpResponseW resp;
HCkJsonObjectW message;
success = FALSE;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
success = FALSE;
http = CkHttpW_Create();
CkHttpW_putRequireSslCertVerify(http,TRUE);
// Supply your API key from protected configuration; AuthToken adds the Bearer prefix.
CkHttpW_putAuthToken(http,L"SENDGRID_API_KEY");
resp = CkHttpResponseW_Create();
message = CkJsonObjectW_Create();
CkJsonObjectW_UpdateString(message,L"from.email",L"sender@example.com");
CkJsonObjectW_UpdateString(message,L"template_id",L"d-YOUR_ACTIVE_TEMPLATE_ID");
// Each recipient gets a separate envelope and a private appointment time.
CkJsonObjectW_UpdateString(message,L"personalizations[0].to[0].email",L"avery@example.com");
CkJsonObjectW_UpdateString(message,L"personalizations[0].dynamic_template_data.first_name",L"Avery");
CkJsonObjectW_UpdateString(message,L"personalizations[0].dynamic_template_data.appointment_time",L"Tuesday at 9:30 AM Central");
CkJsonObjectW_UpdateString(message,L"personalizations[1].to[0].email",L"robin@example.com");
CkJsonObjectW_UpdateString(message,L"personalizations[1].dynamic_template_data.first_name",L"Robin");
CkJsonObjectW_UpdateString(message,L"personalizations[1].dynamic_template_data.appointment_time",L"Wednesday at 2:00 PM Central");
success = CkHttpW_HttpJson(http,L"POST",L"https://api.sendgrid.com/v3/mail/send",message,L"application/json",resp);
if (success != TRUE) {
if (CkHttpResponseW_getStatusCode(resp) == 0) {
wprintf(L"%s\n",CkHttpW_lastErrorText(http));
}
else {
wprintf(L"HTTP %d: %s\n",CkHttpResponseW_getStatusCode(resp),CkHttpResponseW_bodyStr(resp));
}
CkHttpW_Dispose(http);
CkHttpResponseW_Dispose(resp);
CkJsonObjectW_Dispose(message);
return;
}
if (CkHttpResponseW_getStatusCode(resp) != 202) {
wprintf(L"HTTP %d: %s\n",CkHttpResponseW_getStatusCode(resp),CkHttpResponseW_bodyStr(resp));
CkHttpW_Dispose(http);
CkHttpResponseW_Dispose(resp);
CkJsonObjectW_Dispose(message);
return;
}
wprintf(L"Accepted for delivery (HTTP 202).\n");
CkHttpW_Dispose(http);
CkHttpResponseW_Dispose(resp);
CkJsonObjectW_Dispose(message);
}