Problem with ushahidi api


#1

Hi there!

I created this script:

<html>
<head>
	<title>Uso de API de Ushahidi</title>

	<meta charset="UTF-8">	
</head>
<body>

	<?php
	
	$session = curl_init('http://smart.parquesoftpasto.com/api?task=newuser');
	curl_setopt ($session, CURLOPT_POST,1);
	//le decimos qué parametros enviamos 
	curl_setopt ($session, CURLOPT_POSTFIELDS, "email=JoseO@gmail.com&password=123456&name=Jose&apellido=Ojeda&identificacion=123456");
	curl_setopt($session,CURLOPT_RETURNTRANSFER,1);

	$respuesta = curl_exec($session);

	if($respuesta != 0)
	{
		echo "<br>Usuario creado exitosamente en Ushahidi!!!!";
		print_r($respuesta);
		curl_close ($session);
	}
	else
	{
		echo "<br>Imposible crear usuario en base de datos de ushahidi<br>";
		
		print_r($respuesta);
		/*print_r(curl_getinfo($session));
		curl_close ($session);*/
	}

	?>

</body>
</html>

To connect with this function inside the ushahidi Api:

public function new_user()
    {  

        if(isset($_POST['name']) AND isset($_POST['apellido']) AND isset($_POST['email']) AND isset($_POST['identificacion']) AND isset($_POST['password']))
        {
            echo "El usuario que intenta ingresar en la BD de Ushahidi es:";
            echo "<br>Nombre: ".$_POST['name'];
            echo "<br>Apellido: ".$_POST['apellido'];
            echo "<br>Email: ".$_POST['email'];
            echo "<br>Identificacion: ".$_POST['identificacion'];
            echo "<br>Contraseña: ".$_POST['password'];

            return 0;
        }
        else
        {
            echo "No se ha ingresado algún usuario.";
            return 1;
        }
        
    }

The function is inside of: My_private_func_api_object.php file, and it is charged on api.php like this:

"newuser" => array("System", "new_user")

when i run my scrip i get this error that i can not find the solution:

{"code":"001","message":"Falta un par\u00e1metro - task."}

I hope you can give me a hand.


#2

It seems your curl call is not sending the task variable as part of the Post variables

Try

curl_setopt ($session, CURLOPT_POSTFIELDS, "email=JoseO@gmail.com&password=123456&name=Jose&apellido=Ojeda&identificacion=123456&task=newuser");

#3

You were right, it works now. Thank you for your help.