I have this json but it does not reach the controller I am using POSTMAN
Select POST as sending method, in body use raw and json format but it does not arrive tells me that there is no data
url http://codeignitertuto.test/Register/segmentob_208
{"datos":"
{"id":"11421",
"nombre":"jghhj",
"correo":"[email protected]",
"telefono":"4444557671",
"estado":"1",
"modelo":"301",
"id_modelo":"2",
"tipo_ldp": "",
"aviso_privacidad":"1",
"utm": "",
"utm_campaign":"ghjhgj-ghj",
"utm_source":"ghj",
"utm_medium":"hj-hj",
"utm_content":"hj",
"utm_term":"",
"utm_completa":"",
"cotizacion":"0",
"prueba_manejo":"1",
"lead":""}"}
and i want to send it to my php controller in codeigniter
public function segmentob_208(){
if(!$_POST){
echo "No existen datos que insertar";
return;
}
$data = json_decode($_POST['datos']);
$estado = $data->estado;
if( $estado==12 ){
$estado=52;
}
if( $estado==18 ){
$estado=58;
}
if( $estado==57 ){
$estado=32;
}
if( $estado==35 ){
$estado=34;
}
$correo_nuevo = $data->correo;
$datos = array(
'nombre' => $data->nombre,
'telefono' => $data->telefono,
'correo' => $correo_nuevo,
'consesionaria_id' => $estado,
'status' => 1,
'tipo_contacto' => '',
'update_status' => date('Y-m-d H:i:s'),
'origen' => 'segmentob_208',
'modelo' => $data->id_modelo,
'color_interes' => '',
'silueta' => $data->id_modelo,
'id_havas' => $data->id,
'fecha_havas' => date('Y-m-d H:i:s'),
'modelo_havas' => $data->id_modelo,
'utm_text' => $data->utm,
'utm_term' => $data->utm_term,
'utm_campaign' => $data->utm_campaign,
'utm_source' => $data->utm_source,
'utm_medium' => $data->utm_medium,
'utm_content' => $data->utm_content,
'califica_cotizacion' => 1,
'califica_prueba' => 1,
'comentario_calificacion'=>'',
'digital' => 1
);
}
I hope to help, I think I know why the data is not collected by PHP.
JSON, I saw that you have double quotes on the object inside "data", I removed them as follows:
In the PHP file, in the json_decode function I put the true option that makes the returned objects become an associative array and to access the collected array, you access as in a normal array:
In the postman try the x-www-form-urlencoded section (Expand the img if it doesn't look right): NOTE: I hope this is useful for you.