Add contact in SendGrid via API

Following curl script will add the contact in your send grid via API.

$curl = curl_init();
    curl_setopt_array($curl, array(
        CURLOPT_URL => "https://api.sendgrid.com/v3/contactdb/recipients",
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => "",
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_SSL_VERIFYPEER=>0,
        CURLOPT_SSL_VERIFYHOST=>0,
        CURLOPT_TIMEOUT => 30,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => "POST",
        CURLOPT_POSTFIELDS => "[\r\n  {\r\n    \"email\": \"abcd@gmail.com\"\r\n  }\r\n]\r\n",
        CURLOPT_HTTPHEADER => array(
            "authorization: Bearer SG.{TOKEN}",
            "cache-control: no-cache",
            "content-type: application/json",
            "postman-token: ce876e9f-0062-43ac-4915-5d17c8cde680"
        ),
    ));

    $response = curl_exec($curl);
    $err = curl_error($curl);

    curl_close($curl);

    if ($err) {
        return "cURL Error #:" . $err;
    } else {
        return $response;
    }