API: PHP Try to connect via RPC

More
9 months 2 weeks ago #148885 by sarah_w
sarah_w created the topic: API: PHP Try to connect via RPC
Hello :)

I try to connect via RPC to LimeSurvey and followed the PHP example from here: manual.limesurvey.org/RemoteControl_2_API#PHP_Example

include_once 'vendor/autoload.php';

define( 'LS_BASEURL', 'myurl'); // adjust this one to your actual LimeSurvey URL
define( 'LS_USER', 'myuser' );
define( 'LS_PASSWORD', 'mypassword');

// the survey to process
$survey_id=12345678;

// instanciate a new client
$myJSONRPCClient = new \org\jsonrpcphp\JsonRPCClient( LS_BASEURL );

// receive session key
$sessionKey= $myJSONRPCClient->get_session_key( LS_USER, LS_PASSWORD );

// release the session key
//$myJSONRPCClient->release_session_key( $sessionKey );


When executing the script, the following error occurs:
"Fatal error: Uncaught exception 'Exception' with message 'Unable to connect to MYURL' in E:\project\vendor\weberhofer\jsonrpcphp\src\org\jsonrpcphp\JsonRPCClient.php:155 Stack trace: #0 E:\project\cronjobs.php(17): org\jsonrpcphp\JsonRPCClient->__call('get_session_key', Array) #1 E:\msf\benteler\cronjobs.php(17): org\jsonrpcphp\JsonRPCClient->get_session_key('myuser', 'mypassword') #2 {main} thrown in E:\project\vendor\weberhofer\jsonrpcphp\src\org\jsonrpcphp\JsonRPCClient.php on line 155"


The Username and password and the URL are correct. Also I can connect to the API with "R" (the statistic programming language) and with my login data. Just in PHP this error occurs and so far I found nothing that helps me out.

Any help is really appreciated.

Please Log in to join the conversation.

More
9 months 2 weeks ago #148905 by DenisChenu
DenisChenu replied the topic: API: PHP Try to connect via RPC
myurl is an example , you must set the real url , seems the issue is here. Or your server broke web access (firewall issue).

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .

Please Log in to join the conversation.

More
9 months 2 weeks ago #148924 by sarah_w
sarah_w replied the topic: API: PHP Try to connect via RPC
Hey,

thanks for your answer. I set an real URL, just commented all sensitve data out and replaced it with dummy data.

I tested yesterday and the issue was that I tried to connect to my URL via https: under Windows. After some time of searching i found out that curl under Windows needs to set SSL_VERIFYPEER set to FALSE.

So for my locale maschine I had to set
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
inside class "JsonRPCClient". Afterwards it works well.

Please Log in to join the conversation.

More
9 months 2 weeks ago #148925 by jelo
jelo replied the topic: API: PHP Try to connect via RPC

sarah_w wrote: I tested yesterday and the issue was that I tried to connect to my URL via https: under Windows. After some time of searching i found out that curl under Windows needs to set SSL_VERIFYPEER set to FALSE.

Which is depending on how and what certs you installed. I don't think you have to disable SSL_VERIFYPEER always when Windows is involved. You would end up with a potential unsecure connection. curl.haxx.se/libcurl/c/CURLOPT_SSL_VERIFYPEER.html

Please Log in to join the conversation.

More
9 months 2 weeks ago #148929 by DenisChenu
DenisChenu replied the topic: API: PHP Try to connect via RPC
@jelo : yes, but if you use self-signed certificate : you NEED SSL_VERIFYPEER to false.

Else @sarah_w : if you have some times (or some people with time) : letsencrypt.org/ can help you to have a valid certificate (and it's better to verify peer). BTW : not limesurvey related.

Denis
PS : maybe we need to update pour manual about this 'issue'

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .

Please Log in to join the conversation.

More
9 months 2 weeks ago #148930 by sarah_w
sarah_w replied the topic: API: PHP Try to connect via RPC
@jelo: It's only my development laptop with its Windows. Just needed to test my code, therefore I think it's okay to set SSL_VERIFYPEER to false. On the live system it didn't adapt the code.

@DenisChenu: Sorry just turned out now that it was not LimeSurvey related. But maybe someone has the same problem and this can help.

Please Log in to join the conversation.

More
9 months 2 weeks ago #148932 by DenisChenu
DenisChenu replied the topic: API: PHP Try to connect via RPC

sarah_w wrote: @DenisChenu: Sorry just turned out now that it was not LimeSurvey related. But maybe someone has the same problem and this can help.

Ogh think it's partially LimeSurvey manual related

If you can found time to add a 'warning : if you don't use a valid SSL .... ' something here : manual.limesurvey.org/RemoteControl_2_API :)/

I say make a ssl valid key ios not LS related ;) (and letsencrypt is great to have SSL validkey)

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .

Please Log in to join the conversation.

More
9 months 2 weeks ago #148937 by LouisGac
LouisGac replied the topic: API: PHP Try to connect via RPC
also, I would recommend to use a Virtual Machine with LAMP stack rather than using the windows solutions.

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!