Sample code for 30+ languages & platforms
Visual FoxPro Requires Chilkat v11.0.0+

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.

Personalizations

Chilkat Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loHttp
LOCAL loResp
LOCAL loMessage

lnSuccess = 0

*  Assumes Chilkat is unlocked. See Global Unlock Sample.
lnSuccess = 0
loHttp = CreateObject('Chilkat.Http')
loHttp.RequireSslCertVerify = 1
*  Supply your API key from protected configuration; AuthToken adds the Bearer prefix.
loHttp.AuthToken = "SENDGRID_API_KEY"
loResp = CreateObject('Chilkat.HttpResponse')

loMessage = CreateObject('Chilkat.JsonObject')
loMessage.UpdateString("from.email","sender@example.com")
loMessage.UpdateString("template_id","d-YOUR_ACTIVE_TEMPLATE_ID")
*  Each recipient gets a separate envelope and a private appointment time.
loMessage.UpdateString("personalizations[0].to[0].email","avery@example.com")
loMessage.UpdateString("personalizations[0].dynamic_template_data.first_name","Avery")
loMessage.UpdateString("personalizations[0].dynamic_template_data.appointment_time","Tuesday at 9:30 AM Central")
loMessage.UpdateString("personalizations[1].to[0].email","robin@example.com")
loMessage.UpdateString("personalizations[1].dynamic_template_data.first_name","Robin")
loMessage.UpdateString("personalizations[1].dynamic_template_data.appointment_time","Wednesday at 2:00 PM Central")

lnSuccess = loHttp.HttpJson("POST","https://api.sendgrid.com/v3/mail/send",loMessage,"application/json",loResp)
IF (lnSuccess <> 1) THEN
    IF (loResp.StatusCode = 0) THEN
        ? loHttp.LastErrorText
    ELSE
        ? "HTTP " + STR(loResp.StatusCode) + ": " + loResp.BodyStr
    ENDIF

    RELEASE loHttp
    RELEASE loResp
    RELEASE loMessage
    CANCEL
ENDIF

IF (loResp.StatusCode <> 202) THEN
    ? "HTTP " + STR(loResp.StatusCode) + ": " + loResp.BodyStr
    RELEASE loHttp
    RELEASE loResp
    RELEASE loMessage
    CANCEL
ENDIF

? "Accepted for delivery (HTTP 202)."

RELEASE loHttp
RELEASE loResp
RELEASE loMessage