Cómo agregar contacto en la lista usando (Enviar cuadrícula) php api
Estoy tratando de agregar contacto en la lista usando php api pero está arrojando un error de fragmento de abajo
cadena (51) "{" errores ": [{" mensaje ":" el cuerpo de la solicitud no es válido "}]}" {"correo electrónico": "[email protected]", "nombre_nombre": "hh", "apellido_" :"Usuario"}
Estoy usando el siguiente código de fragmento:
$url = 'https://api.sendgrid.com/v3';
$request = $url.'/contactdb/lists/12345/recipients'; //12345 is list_id
$params = array(
'email' => '[email protected]',
'first_name' => 'hh',
'last_name' => 'User'
);
$json_post_fields = json_encode($params);
// Generate curl request
$ch = curl_init();
$headers =
array("Content-Type: application/json",
"Authorization: Bearer SG.XXXXXXXX");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_URL, $request);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// Apply the JSON to our curl call
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_post_fields);
$data = curl_exec($ch);
if (curl_errno($ch)) {
print "Error: " . curl_error($ch);
} else {
// Show me the result
var_dump($data);
curl_close($ch);
}
echo $json_post_fields;
¿Alguien puede decirme cómo resolver este problema?