I
I
IT-sorce2020-11-03 15:44:14
PHP
IT-sorce, 2020-11-03 15:44:14

How can I login using c api php?

Request to EWA for authentication
Authentication - https://api.ewa.ua/#api-/user/login . It will be necessary to add a user to Eva, under which calls to the system will be made.

Authentication request example:

curl -v --request POST \
--url https://web.ewa.ua/ewa/api/v9/user/login \
--header 'content-type: application/x-www- form-urlencoded' \
--data [email protected] \
--data password=9b5b9d4fdcd4a2ece5400fa994a54665ceb522bb The
password must be sent in hashed form. Generate a password hash via www.sha1-online.com or using the command in the Linux/Mac console:
echo -n Your_Password | sha1sum

From the response json, you need to take the value of the SESSIONID parameter, create a cookie with the
JSESSIONID parameter and the value that is passed to SESSIONID. In subsequent requests, you must add a cookie with the appropriate value.
For example, if a POST request received json:
. . .
"SESSIONID":"D5A2ED4E36A46538FD3516F85C18XXXX"
. . .

then the cookie will be
JSESSIONID=D5A2ED4E36A46538FD3516F85C18ХХХХ

Session lifetime 15 minutes!
If more time has passed since the last call to the server, then the JSESSION is invalid.

Does not work

<?php
$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://web.ewa.ua/ewa/api/v12/user/login",
  CURLOPT_HTTPHEADER => "content-type: application/x-www-form-urlencoded", 
  CURLOPT_EMAIL => "pocta",
  CURLOPT_PASSWORD => "pass",
  CURLOPT_CUSTOMREQUEST => "POST",
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2020-11-03
@IT-sorce

And it doesn't work correctly.
CURLOPT_CUSTOMREQUEST - not needed here, use CURLOPT_POST.
CURLOPT_HTTPHEADER - optional, this value is set by default for POST requests.
CURLOPT_EMAIL - There is no such option at all.
CURLOPT_PASSWORD - this option is related to HTTP authorization and is not needed here at all.
Instead of these two, the CURLOPT_POSTFIELDS option must be correctly set.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question