Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

API doesn't work

  • yuto0419
  • yuto0419's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
1 year 3 months ago - 1 year 3 months ago #244441 by yuto0419
API doesn't work was created by yuto0419
Please help us help you and fill where relevant:
Your LimeSurvey version: version 5.6.9+230306
Own server or LimeSurvey hosting: Azure
Survey theme/template:
==================
I get an error [Unable to connect to test.com/index.php?r=admin/remotecontrol ] with get_session_key.

↓↓↓Below is the actual PHP source code.
<?php
try {
    require_once 'application/libraries/jsonRPCClient.php';
    // instanciate a new client
    $myJSONRPCClient = new JsonRPCClient(' test.com/index.php?r=admin/remotecontrol ');
    $sessionKey = $myJSONRPCClient->get_session_key('admin', 'password');
   
    // the survey to process
    $survey_id = 837454;
    // receive all ids and info of groups belonging to a given survey
    $groups = $myJSONRPCClient->list_groups( $sessionKey, $survey_id );
    print_r($groups);
   
    // release the session key
    $myJSONRPCClient->release_session_key( $sessionKey );
   
} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage();
}
?>
↑↑↑
The URL, ID, and password are not real for security reasons.

If there are any bugs or problems, please let me know.
Last edit: 1 year 3 months ago by yuto0419.

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 3 months ago #244464 by tpartner
Replied by tpartner on topic API doesn't work
Did you enable it in Global settings --> Interfaces?

Did you copy the access URL given there?

- manual.limesurvey.org/Global_settings#Interfaces

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

  • yuto0419
  • yuto0419's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
1 year 3 months ago #244483 by yuto0419
Replied by yuto0419 on topic API doesn't work

Did you enable it in Global settings --> Interfaces?

Did you copy the access URL given there?

- manual.limesurvey.org/Global_settings#Interfaces
RPC interface enabled:JSON-RPC
Publish API on /admin/remotecontrol:On
As a result of copying the URL with the above settings, an error has occurred.

Please Log in to join the conversation.

  • yuto0419
  • yuto0419's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
1 year 3 months ago #244535 by yuto0419
Replied by yuto0419 on topic API doesn't work
RPC interface enabled:JSON-RPC
Publish API on /admin/remotecontrol:On

<?php
include_once 'vendor/autoload.php';
// instanciate a new client
$myJSONRPCClient = new \org\jsonrpcphp\JsonRPCClient(' test.com/r5/index.php?r=admin/remotecontrol ');
print_r($sessionKey);
try {
    $sessionKey = $myJSONRPCClient->get_session_key('admin', 'password');
} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage();
}

↑↑↑When I run this process, [Incorrect response id: (request id: 1)] occurs.
print_r($sessionKey); results in [NULL].

I'm struggling because I can't find the same case on the forum.
What I noticed is that the pash is [index.php?r=admin/remotecontrol'], but everyone is [index.php/admin/remotecontrol'].
 

I would like your cooperation.
 

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 3 months ago #244538 by Joffm
Replied by Joffm on topic API doesn't work
Hi,
I do not see any issue with this:
Code:
<?php
require_once 'jsonrpcphp/JsonRPCClient.php';
 
define( 'LS_BASEURL', 'https://www.myserver.de/survey');  // adjust this one to your actual LimeSurvey URL
define( 'LS_USER', 'myUser' );
define( 'LS_PASSWORD', 'myPassword' );
 
// the survey to process
$survey_id=123456;
 
// instantiate a new client
$myJSONRPCClient = new \org\jsonrpcphp\JsonRPCClient( LS_BASEURL.'/index.php/admin/remotecontrol' );
 
// receive session key
$sessionKey= $myJSONRPCClient->get_session_key( LS_USER, LS_PASSWORD );
 
if(is_array($sessionKey))
{
    header("Content-type: application/json");
    echo json_encode($sessionKey);
    die();
}
 
$groups = $myJSONRPCClient->list_groups( $sessionKey, $survey_id );
 
    if(is_array($groups)) {
      // Oops, print any errors
      print_r($groups);
    }
    else {
      // Decode the retuned base-64 string and convert to an array
      $decodedString = base64_decode($groups);
      $aResponses = json_decode($decodedString, True);
      echo "<pre>";
        print_r($aResponses);
      echo "</pre>";
    }
 
// release the session key
$myJSONRPCClient->release_session_key( $sessionKey );
 
?>

 

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

  • yuto0419
  • yuto0419's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
1 year 3 months ago - 1 year 3 months ago #244605 by yuto0419
Replied by yuto0419 on topic API doesn't work

Hi,
I do not see any issue with this:
Code:
<?php
require_once 'jsonrpcphp/JsonRPCClient.php';
 
define( 'LS_BASEURL', 'https://www.myserver.de/survey');  // adjust this one to your actual LimeSurvey URL
define( 'LS_USER', 'myUser' );
define( 'LS_PASSWORD', 'myPassword' );
 
// the survey to process
$survey_id=123456;
 
// instantiate a new client
$myJSONRPCClient = new \org\jsonrpcphp\JsonRPCClient( LS_BASEURL.'/index.php/admin/remotecontrol' );
 
// receive session key
$sessionKey= $myJSONRPCClient->get_session_key( LS_USER, LS_PASSWORD );
 
if(is_array($sessionKey))
{
    header("Content-type: application/json");
    echo json_encode($sessionKey);
    die();
}
 
$groups = $myJSONRPCClient->list_groups( $sessionKey, $survey_id );
 
    if(is_array($groups)) {
      // Oops, print any errors
      print_r($groups);
    }
    else {
      // Decode the retuned base-64 string and convert to an array
      $decodedString = base64_decode($groups);
      $aResponses = json_decode($decodedString, True);
      echo "<pre>";
        print_r($aResponses);
      echo "</pre>";
    }
 
// release the session key
$myJSONRPCClient->release_session_key( $sessionKey );
 
?>


 

Joffm
I have a couple of questions.

① Where do you put JsonRPCClient.php?
  When I downloaded LimeSurvey, there is a file in [...\application\libraries\jsonRPCClient.php], but [require_once 'jsonrpcphp/JsonRPCClient.php';] does 'require' it?
  Or is it a fresh download with composer and placed in a different directory?

② I get the error [Unable to connect to {URL}] [Incorrect response id: (request id: 1)].
  I would like some advice on how to identify the cause...
Last edit: 1 year 3 months ago by yuto0419.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 3 months ago #244607 by Joffm
Replied by Joffm on topic API doesn't work
Hi,
I downloaded it from here (I do not use composer)
[url] github.com/weberhofer/jsonrpcphp [/url]
and as you see I put it into the subdirectory "jsonrpcphp" of my small and simple application.

If you compare this "original" Weberhofer file and the one included in LimeSurvey you see the only difference seems to be the definition of the namespace.
namespace org\jsonrpcphp;

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: yuto0419

Please Log in to join the conversation.

  • yuto0419
  • yuto0419's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
1 year 3 months ago #244721 by yuto0419
Replied by yuto0419 on topic API doesn't work
It wasn't an LS issue, it was [Azure AD] authentication getting in the way.
It doesn't seem to work, so I decided to look for another way...
Thank you very much for your help!

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose