Zipato API with PHP integration
Hi Zipato Community,
I am trying to use the Zipato rest API in PHP. I have created an php rest client to call "https://my.zipato.com/zipato-web/rest/user/init". This request is giving me response in JSON format like this.
(
[success] => 1
[jsessionid] => 780B5469850ABFE4B9E0243A1A28A741.frontend2
[nonce] => FVeErTtzoPXAPMCp
)
After this I am using nonce from above request to generate token for next login request(https://my.zipato.com/zipato-web/rest/user/login?username=[MYUSERNAME]&token=[ sha1 ( ABOVE-NONCE . sha1(MYPASSWORD) ) ] ).But this request always giving me response that "Provide username is not exist or password is wrong".(
[success] =>
[error] => User "MYUSERNAME" not found or wrong password.
[jsessionid] => 3C21DB5538404E88F8012109C2C0D953.frontend2
[nonce] => VhrSXUBUeloAFURM
) Please let me what I am doing wrong. I need to sort this out asap.
Thanks & Best Regards,Aman
Did you put the jsessionid inside the 'Cookie' HTTP header, retrieve from the user/init call, when calling user/login?
Did you put the jsessionid inside the 'Cookie' HTTP header, retrieve from the user/init call, when calling user/login?
Step 1:
{
global $username,$password,$url,$url_base;
$json = json_decode(file_get_contents($url));
$sid = 'jsessionid';
$none = 'nonce';
$id = $json->{$sid};
$nonce = $json->{$none};
$temp = sha1 ($password);
$temp2 = $nonce.$temp;
$pass = sha1($temp2);
$data = array("username" => "$username", "password" => "$pass", "method" => "SHA1" );
$data_url = "username=$username&password=$pass&method=SHA1";
$ch = curl_init($url_base.'/json/Login');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_COOKIE, 'JSESSIONID='.$id);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
$rr = json_decode ($output,true);
return array ($id,$rr['success'],$rr['error']);
}
with :
$url_base = 'http://my.zipato.com:8080/zipato-web';
$url = $url_base.'/json/Initialize';
Step 2 : Get some Info
$c = curl_init();
curl_setopt($c, CURLOPT_URL, $url_base.'/rest/meters/');
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_COOKIE, 'JSESSIONID='.$id.'; Path=/zipato-web/; HttpOnly');
curl_setopt($c, CURLOPT_HEADER, false);
$output = curl_exec($c);
$json = json_decode ($output,true);
Step 1:
{
global $username,$password,$url,$url_base;
$json = json_decode(file_get_contents($url));
$sid = 'jsessionid';
$none = 'nonce';
$id = $json->{$sid};
$nonce = $json->{$none};
$temp = sha1 ($password);
$temp2 = $nonce.$temp;
$pass = sha1($temp2);
$data = array("username" => "$username", "password" => "$pass", "method" => "SHA1" );
$data_url = "username=$username&password=$pass&method=SHA1";
$ch = curl_init($url_base.'/json/Login');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_COOKIE, 'JSESSIONID='.$id);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
$rr = json_decode ($output,true);
return array ($id,$rr['success'],$rr['error']);
}
with :
$url_base = 'http://my.zipato.com:8080/zipato-web';
$url = $url_base.'/json/Initialize';
Step 2 : Get some Info
$c = curl_init();
curl_setopt($c, CURLOPT_URL, $url_base.'/rest/meters/');
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_COOKIE, 'JSESSIONID='.$id.'; Path=/zipato-web/; HttpOnly');
curl_setopt($c, CURLOPT_HEADER, false);
$output = curl_exec($c);
$json = json_decode ($output,true);
Replies have been locked on this page!