Welcome to the LimeSurvey Community Forum

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

Deactivate Survey with API

  • ccarmona
  • ccarmona's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
7 years 3 months ago - 7 years 3 months ago #144983 by ccarmona
Deactivate Survey with API was created by ccarmona
Hi people! If possible to deactivate a survey by API?

We have a activate_survey() function but not deactivate_survey(), only a delete_survey()........

Thanks!
Last edit: 7 years 3 months ago by ccarmona.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 3 months ago #144991 by tpartner
Replied by tpartner on topic Deactivate Survey with API

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
7 years 3 months ago #145068 by Deusdeorum
Replied by Deusdeorum on topic Deactivate Survey with API
You could extend the API. However, I always use expire survey instead, and that can be done with the API in set_survey_settings()
The topic has been locked.
More
6 years 1 month ago #163054 by bdrhoa
Replied by bdrhoa on topic Deactivate Survey with API
Could you please post an example of how to expire a survey?
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 1 month ago - 6 years 1 month ago #163078 by tpartner
Replied by tpartner on topic Deactivate Survey with API
Using JSON-RPC, I think something like this (untested):


Code:
<?php
 
  require_once 'jsonRPCClient.php';
 
  define( 'LS_BASEURL', 'http://pathTo/limeSurvey/');  
  define( 'LS_USER', 'username' );
  define( 'LS_PASSWORD', 'password' );
 
  $iSurveyID = 11111; 
 
  if(ctype_alnum($iSurveyID) &amp;&amp; (strlen($iSurveyID) == 5 || strlen($iSurveyID) == 6)) { // Valid SID format
 
    // Instantiate a new RPC client
    $myJSONRPCClient = new jsonRPCClient( LS_BASEURL.'/index.php/admin/remotecontrol' );
 
    // Get a session key
    $sSessionKey= $myJSONRPCClient->get_session_key( LS_USER, LS_PASSWORD );
 
    if(is_array($sSessionKey)) { // Invalid session
      echo $sSessionKey['status'];
    }
    else if($sSessionKey) { // Valid session      
 
      // Expire survey
      $aSurveyData = array('expires'=>'2018-01-27 00:00:00');
      $newSurveyProperties = $myJSONRPCClient->set_survey_properties($sSessionKey, $iSurveyID, $aSurveyData);
    }
 
    // Release the session key
    $myJSONRPCClient->release_session_key( $sSessionKey );
  }
  else { // Invalid SID format
    die( 'Invalid format!' );
  }
 
?>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 6 years 1 month ago by tpartner.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose