- Posts: 55
- Thank you received: 2
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
API where to start?
- jltrussart11
- Topic Author
- Offline
- Senior Member
Less
More
7 years 2 weeks ago #149535
by jltrussart11
API where to start? was created by jltrussart11
Hi,
I'm starting to look at the API and i mess around.
I'm trying to connect to the API, without success. I always got a http error 500.
My limesurvey installation is locate at vecteursleviers.com/conseil/index.php?r=admin
I also got an http error 500 when I try do display the /conseil/ folder.
The jsonrpcphp library from github is intalled in a folder name api on my web server. The client can be found at the url vecteursleviers.com/conseil/api/jsonrpcp...r/src/org/jsonrpcphp
I've create a php file at this location vecteursleviers.com/conseil/api/API-Lime-JLT.php and add this code.
The *** are my my verified login infos.
Can you help me find where I got wrong?
Thanks for your precious help!
<?php
// without composer this line can be used
// require_once 'jsonrpcphp-master\src\org\jsonrpcph\jsonRPCClient.php';
// with composer support just add the autoloader
include_once 'vendor/autoload.php';
define( 'LS_BASEURL', ' vecteursleviers.com/conseil/ '); // adjust this one to your actual LimeSurvey URL DONE
define( 'LS_USER', '***' );
define( 'LS_PASSWORD', '***' );
// the survey to process
$survey_id=374699;
// instanciate a new client
$myJSONRPCClient = new \org\jsonrpcphp\JsonRPCClient( LS_BASEURL.'/admin/remotecontrol' );
// receive session key
$sessionKey= $myJSONRPCClient->get_session_key( LS_USER, LS_PASSWORD );
// receive all ids and info of groups belonging to a given survey
$groups = $myJSONRPCClient->list_groups( $sessionKey, $survey_id );
print_r($groups, null );
// release the session key
$myJSONRPCClient->release_session_key( $sessionKey );
add_participants
/**
* RPC Routine to add participants to the tokens collection of the survey.
* Returns the inserted data including additional new information like the Token entry ID and the token string.
*
* @access public
* @param string $sSessionKey Auth credentials
* @param int $iSurveyID ID of the Survey
* @param struct $aParticipantData Data of the participants to be added
* @param bool Optional - Defaults to true and determins if the access token automatically created
* @return array The values added
*/
php?>
I'm starting to look at the API and i mess around.
I'm trying to connect to the API, without success. I always got a http error 500.
My limesurvey installation is locate at vecteursleviers.com/conseil/index.php?r=admin
I also got an http error 500 when I try do display the /conseil/ folder.
The jsonrpcphp library from github is intalled in a folder name api on my web server. The client can be found at the url vecteursleviers.com/conseil/api/jsonrpcp...r/src/org/jsonrpcphp
I've create a php file at this location vecteursleviers.com/conseil/api/API-Lime-JLT.php and add this code.
The *** are my my verified login infos.
Can you help me find where I got wrong?
Thanks for your precious help!
<?php
// without composer this line can be used
// require_once 'jsonrpcphp-master\src\org\jsonrpcph\jsonRPCClient.php';
// with composer support just add the autoloader
include_once 'vendor/autoload.php';
define( 'LS_BASEURL', ' vecteursleviers.com/conseil/ '); // adjust this one to your actual LimeSurvey URL DONE
define( 'LS_USER', '***' );
define( 'LS_PASSWORD', '***' );
// the survey to process
$survey_id=374699;
// instanciate a new client
$myJSONRPCClient = new \org\jsonrpcphp\JsonRPCClient( LS_BASEURL.'/admin/remotecontrol' );
// receive session key
$sessionKey= $myJSONRPCClient->get_session_key( LS_USER, LS_PASSWORD );
// receive all ids and info of groups belonging to a given survey
$groups = $myJSONRPCClient->list_groups( $sessionKey, $survey_id );
print_r($groups, null );
// release the session key
$myJSONRPCClient->release_session_key( $sessionKey );
add_participants
/**
* RPC Routine to add participants to the tokens collection of the survey.
* Returns the inserted data including additional new information like the Token entry ID and the token string.
*
* @access public
* @param string $sSessionKey Auth credentials
* @param int $iSurveyID ID of the Survey
* @param struct $aParticipantData Data of the participants to be added
* @param bool Optional - Defaults to true and determins if the access token automatically created
* @return array The values added
*/
php?>
The topic has been locked.
- Ben_V
- Offline
- Platinum Member
Less
More
- Posts: 1223
- Thank you received: 351
7 years 2 weeks ago #149547
by Ben_V
Benoît
EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)
Replied by Ben_V on topic API where to start?
If it can helps you, please find a piece of working code to perform some connection tests...
1) Create a file & place it at your root limesurvey folder (same level as index.php)
2) edit the first block (url + user+ passw + survey ID)
3) call the file
You will also find some useful info at:
code.uoa.gr/p/limesurvey/test_scenarios.php
1) Create a file & place it at your root limesurvey folder (same level as index.php)
2) edit the first block (url + user+ passw + survey ID)
3) call the file
You will also find some useful info at:
code.uoa.gr/p/limesurvey/test_scenarios.php
Code:
<?php /* * * * * * * * * * * * * * * * * * * * * * * Start Edit * * * * * * * * * * * * * * * * * * * * * */ define( 'LS_BASEURL', 'http://www.example.org' ); // if subbfolder => http://localhost/MyFolder define( 'LS_USER', 'admin' ); define( 'LS_PASSWORD', 'password' ); $iSurveyId = 1234; // survey ID /* * * * * * * * * * * * * * * * * * * * * * * End Edit * * * * * * * * * * * * * * * * * * * * * */ /* using LimeSurvey (LS) RemoteControly API version 2's JSON-RPC method */ include "application/libraries/jsonRPCClient.php"; /* instantiate a new client */ $lsJSONRPCClient = new jsonRPCClient( LS_BASEURL.'/index.php/admin/remotecontrol' ); /* receive session key */ $sessionKey = $lsJSONRPCClient->get_session_key(LS_USER, LS_PASSWORD); /* receive all ids and info of query belonging to a given survey */ $properties = array('template','datecreated','showwelcome','bounce_email'); $result = $lsJSONRPCClient->call('get_survey_properties', array($sessionKey,$iSurveyId,$properties)); /* output */ print_r($result, null ); /* release the session key */ $lsJSONRPCClient->release_session_key($sessionKey); ?>
Benoît
EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)
The following user(s) said Thank You: jltrussart11
The topic has been locked.
- jltrussart11
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 55
- Thank you received: 2
7 years 2 weeks ago #149548
by jltrussart11
Replied by jltrussart11 on topic API where to start?
Thanks for your precious help!
I still get a HTTP ERROR 500
vecteursleviers.com/conseil/api-test.php
The JSON-RPC API is enable and it's published on admin/remotecontrol.
Any idea?
Thanks again!
I still get a HTTP ERROR 500
vecteursleviers.com/conseil/api-test.php
The JSON-RPC API is enable and it's published on admin/remotecontrol.
Any idea?
Thanks again!
The topic has been locked.
- Ben_V
- Offline
- Platinum Member
Less
More
- Posts: 1223
- Thank you received: 351
7 years 2 weeks ago #149552
by Ben_V
Benoît
EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)
Replied by Ben_V on topic API where to start?
I would:
1) check server error logs about this error 500
2) turn debug mode on in application/config/config.php
1) check server error logs about this error 500
2) turn debug mode on in application/config/config.php
Benoît
EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)
The following user(s) said Thank You: jltrussart11
The topic has been locked.
- jltrussart11
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 55
- Thank you received: 2
7 years 2 weeks ago #149629
by jltrussart11
Replied by jltrussart11 on topic API where to start?
Thanks again for your precious help.
Here's the logs. I've changed my password to ***.
[03-Mar-2017 11:11:24 UTC] PHP Fatal error: Uncaught exception 'Exception' with message 'Unable to connect to www.vecteursleviers.com/conseil/index.php/admin/remotecontrol ' in /home/vecteursleviers/public_html/conseil/application/libraries/jsonRPCClient.php:141
Stack trace:
#0 /home/vecteursleviers/public_html/conseil/api-test.php(28): jsonRPCClient->__call('get_session_key', Array)
#1 /home/vecteursleviers/public_html/conseil/api-test.php(28): jsonRPCClient->get_session_key('admin', '***')
#2 {main}
thrown in /home/vecteursleviers/public_html/conseil/application/libraries/jsonRPCClient.php on line 141
[03-Mar-2017 11:17:35 UTC] PHP Warning: fopen( www.vecteursleviers.com/conseil/index.php/admin/remotecontrol ): failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request
in /home/vecteursleviers/public_html/conseil/application/libraries/jsonRPCClient.php on line 132
[03-Mar-2017 11:17:35 UTC] PHP Fatal error: Uncaught exception 'Exception' with message 'Unable to connect to www.vecteursleviers.com/conseil/index.php/admin/remotecontrol ' in /home/vecteursleviers/public_html/conseil/application/libraries/jsonRPCClient.php:141
Stack trace:
#0 /home/vecteursleviers/public_html/conseil/api-test.php(28): jsonRPCClient->__call('get_session_key', Array)
#1 /home/vecteursleviers/public_html/conseil/api-test.php(28): jsonRPCClient->get_session_key('admin', '***')
#2 {main}
thrown in /home/vecteursleviers/public_html/conseil/application/libraries/jsonRPCClient.php on line 141
Here's the logs. I've changed my password to ***.
[03-Mar-2017 11:11:24 UTC] PHP Fatal error: Uncaught exception 'Exception' with message 'Unable to connect to www.vecteursleviers.com/conseil/index.php/admin/remotecontrol ' in /home/vecteursleviers/public_html/conseil/application/libraries/jsonRPCClient.php:141
Stack trace:
#0 /home/vecteursleviers/public_html/conseil/api-test.php(28): jsonRPCClient->__call('get_session_key', Array)
#1 /home/vecteursleviers/public_html/conseil/api-test.php(28): jsonRPCClient->get_session_key('admin', '***')
#2 {main}
thrown in /home/vecteursleviers/public_html/conseil/application/libraries/jsonRPCClient.php on line 141
[03-Mar-2017 11:17:35 UTC] PHP Warning: fopen( www.vecteursleviers.com/conseil/index.php/admin/remotecontrol ): failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request
in /home/vecteursleviers/public_html/conseil/application/libraries/jsonRPCClient.php on line 132
[03-Mar-2017 11:17:35 UTC] PHP Fatal error: Uncaught exception 'Exception' with message 'Unable to connect to www.vecteursleviers.com/conseil/index.php/admin/remotecontrol ' in /home/vecteursleviers/public_html/conseil/application/libraries/jsonRPCClient.php:141
Stack trace:
#0 /home/vecteursleviers/public_html/conseil/api-test.php(28): jsonRPCClient->__call('get_session_key', Array)
#1 /home/vecteursleviers/public_html/conseil/api-test.php(28): jsonRPCClient->get_session_key('admin', '***')
#2 {main}
thrown in /home/vecteursleviers/public_html/conseil/application/libraries/jsonRPCClient.php on line 141
The topic has been locked.
- jacob
- Offline
- Senior Member
Less
More
- Posts: 75
- Thank you received: 22
7 years 2 weeks ago #149632
by jacob
Replied by jacob on topic API where to start?
Maybe allow_url_fopen is turned off?
Check your php.ini
Check your php.ini
The following user(s) said Thank You: jltrussart11
The topic has been locked.
- Ben_V
- Offline
- Platinum Member
Less
More
- Posts: 1223
- Thank you received: 351
7 years 2 weeks ago - 7 years 2 weeks ago #149633
by Ben_V
In this case you should access a valid webpage (status 200) with some text when connecting to:
www.vecteursleviers.com/conseil/index.php/admin/remotecontrol
It's not the case (redirect to home page) and you have to focus on this first before starting any other test.
IMHO there is something wrong in your server configuration... could be about "allow_url_fopen" or similar... I don't really know and hard to guess...Sorry !
Benoît
EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)
Replied by Ben_V on topic API where to start?
jltrussart11 wrote: ...and it's published on admin/remotecontrol.
In this case you should access a valid webpage (status 200) with some text when connecting to:
www.vecteursleviers.com/conseil/index.php/admin/remotecontrol
It's not the case (redirect to home page) and you have to focus on this first before starting any other test.
IMHO there is something wrong in your server configuration... could be about "allow_url_fopen" or similar... I don't really know and hard to guess...Sorry !
Benoît
EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)
Last edit: 7 years 2 weeks ago by Ben_V.
The following user(s) said Thank You: jltrussart11
The topic has been locked.
- jltrussart11
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 55
- Thank you received: 2
7 years 2 weeks ago #149635
by jltrussart11
Replied by jltrussart11 on topic API where to start?
Thanks a lot Jacob and Ben_V for your precious help!
Unfortunately, I added allow_url_fopen to my php.ini file and It does'nt do anything.
In the API setttings, it's been displayed that the API is publish at the URL : vecteursleviers.com/conseil/index.php?r=admin/remotecontrol
Should it be at www.vecteursleviers.com/conseil/index.php/admin/remotecontrol ?
I'm looking towards my server config!
Thanks again!
Unfortunately, I added allow_url_fopen to my php.ini file and It does'nt do anything.
In the API setttings, it's been displayed that the API is publish at the URL : vecteursleviers.com/conseil/index.php?r=admin/remotecontrol
Should it be at www.vecteursleviers.com/conseil/index.php/admin/remotecontrol ?
I'm looking towards my server config!
Thanks again!
The topic has been locked.
- jltrussart11
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 55
- Thank you received: 2
7 years 2 weeks ago #149637
by jltrussart11
Replied by jltrussart11 on topic API where to start?
Found the solution from this post:
www.limesurvey.org/forum/installation-a-...st-page-doesn-t-work
in config.php
I've changed
'urlManager' => array(
'urlFormat' => 'get',
to
'urlManager' => array(
'urlFormat' => 'path',
in config.php
I've changed
'urlManager' => array(
'urlFormat' => 'get',
to
'urlManager' => array(
'urlFormat' => 'path',
The following user(s) said Thank You: Ben_V
The topic has been locked.
- jacob
- Offline
- Senior Member
Less
More
- Posts: 75
- Thank you received: 22
7 years 2 weeks ago #149638
by jacob
Replied by jacob on topic API where to start?
And now RemoteControl works as expected?
The topic has been locked.
- Ben_V
- Offline
- Platinum Member
Less
More
- Posts: 1223
- Thank you received: 351
7 years 2 weeks ago #149640
by Ben_V
Benoît
EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)
Replied by Ben_V on topic API where to start?
Good to know... thanks for your feedback
Congrats!!!
Congrats!!!
Benoît
EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)
The following user(s) said Thank You: jltrussart11
The topic has been locked.
- jltrussart11
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 55
- Thank you received: 2
7 years 2 weeks ago #149642
by jltrussart11
Replied by jltrussart11 on topic API where to start?
Hi Jacob,
vecteursleviers.com/conseil/api-test.php ssems to works with Ben_V script.
vecteursleviers.com/conseil/index.php/admin/remotecontrol show the different routines.
Everything seems normal!
Thanks again for your precious help!
vecteursleviers.com/conseil/api-test.php ssems to works with Ben_V script.
vecteursleviers.com/conseil/index.php/admin/remotecontrol show the different routines.
Everything seems normal!
Thanks again for your precious help!
The following user(s) said Thank You: jacob
The topic has been locked.