API where to start?

More
1 year 5 months ago #149535 by jltrussart11
jltrussart11 created the topic: API where to start?
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?>

Please Log in or Create an account to join the conversation.

More
1 year 5 months ago #149547 by Ben_V
Ben_V replied the 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
<?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

Please Log in or Create an account to join the conversation.

More
1 year 5 months ago #149548 by jltrussart11
jltrussart11 replied the 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!

Please Log in or Create an account to join the conversation.

More
1 year 5 months ago #149552 by Ben_V
Ben_V replied the 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

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

Please Log in or Create an account to join the conversation.

More
1 year 5 months ago #149629 by jltrussart11
jltrussart11 replied the 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

Please Log in or Create an account to join the conversation.

More
1 year 5 months ago #149632 by jacob
jacob replied the topic: API where to start?
Maybe allow_url_fopen is turned off?
Check your php.ini
The following user(s) said Thank You: jltrussart11

Please Log in or Create an account to join the conversation.

More
1 year 5 months ago - 1 year 5 months ago #149633 by Ben_V
Ben_V replied the 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: 1 year 5 months ago by Ben_V.
The following user(s) said Thank You: jltrussart11

Please Log in or Create an account to join the conversation.

More
1 year 5 months ago #149635 by jltrussart11
jltrussart11 replied the 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!

Please Log in or Create an account to join the conversation.

More
1 year 5 months ago #149637 by jltrussart11
jltrussart11 replied the 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',
The following user(s) said Thank You: Ben_V

Please Log in or Create an account to join the conversation.

More
1 year 5 months ago #149638 by jacob
jacob replied the topic: API where to start?
And now RemoteControl works as expected?

Please Log in or Create an account to join the conversation.

More
1 year 5 months ago #149640 by Ben_V
Ben_V replied the topic: API where to start?
Good to know... thanks for your feedback

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

Please Log in or Create an account to join the conversation.

More
1 year 5 months ago #149642 by jltrussart11
jltrussart11 replied the 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!
The following user(s) said Thank You: jacob

Please Log in or Create an account to join the conversation.

More
3 months 2 weeks ago #167962 by ashna
ashna replied the topic: API where to start?
I Know this is old, but there may be someone who can help me. I Used the same code as the thread creater, however there is an error in the following line:

$myJSONRPCClient = new \org\jsonrpcphp\JsonRPCClient( LS_BASEURL.'/admin/remotecontrol');

,,jsonrpcphp" seems to be an undefined namespace. I´m not new to programming, but never used php. The jsonrpc-folder is in my limesurvey-root: localhost/umfragen_test/jsonrpcphp-master/...
I followed the tutorial. Is there something i´m missing?.

Please Log in or Create an account to join the conversation.

More
3 months 1 week ago #168224 by ashna
ashna replied the topic: API where to start?
Nevemind fixed it. The JsonRPCCLient.php was not in my Limesurveyroot.

Please Log in or Create an account to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!