Welcome to the LimeSurvey Community Forum

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

Copy_survey working properly in json/rpc?

More
7 years 8 months ago #162093 by jsibley
Hi,

I've been able to test a number of remotecontrol calls using Postman, but have been unsuccessful getting copy_survey to work. This is the json body I am testing:

{
"method": "copy_survey",
"id": " ",
"params": {
"sSessionKey" : {{SessionKey}},
"iSurveyID_org" : {{SurveyID}},
"sNewname" : "copy1"
}
}

Of course, I have set SessionKey and SurveyID. These parameters seem to fit the documentation, unless I have misread something. The result back is:

{"id":" ","result":null,"error":null}

Any thoughts on why this might not be working?

Thanks.
The topic has been locked.
More
7 years 6 months ago #164911 by jsibley
It has been 2 months, does "copy_survey" work for anyone using json?

Thanks.
The topic has been locked.
More
7 years 6 months ago #164923 by tpartner
I can't speak to Postman but the PHP example below works fine in version 3.4.3. This indicates the there is no bug in the API.

Code:
<?php
 
  require_once 'jsonRPCClient.php';
 
  define( 'LS_BASEURL', 'https://pathTo/limesurvey');  
  define( 'LS_USER', 'admin' );
  define( 'LS_PASSWORD', 'password' );
 
  $iSurveyID_org = 123456;
  $sNewname = 'Copy of survey 123456';
 
 
  if(ctype_alnum($iSurveyID_org) &amp;&amp; strlen($iSurveyID_org == 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
 
      // Copy survey
      $newSurvey = $myJSONRPCClient->copy_survey($sSessionKey, $iSurveyID_org, $sNewname);
 
      // Print results
      print_r($newSurvey);
    }
 
    // 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.
The following user(s) said Thank You: jsibley
The topic has been locked.
More
7 years 6 months ago #164927 by jsibley
Thank you, I think I am a step closer.

I hadn't noticed that the survey ID needs to be an integer, not a string. If I'm not mistaken, some of the other api calls accept the survey ID as an integer or a string (or, perhaps, this is a Postman issue).

In any case, I am now seeing this message:

{"id":" ","result":null,"error":null}

I'm not seeing a copy of the survey, but it seems like a step in the right direction.

Any thoughts about what might be going on. I assume that error being null is a good thing, but what might get in the way of actually making the copy?

Thank you.
The topic has been locked.
More
7 years 6 months ago - 7 years 6 months ago #164937 by tpartner
I'm not sure why you're getting that as a response.

As far as I know, the should be an array:

- status
- error (if status != OK)
- newsid (if status == OK)

So, this response for a successful copy:

Code:
Array ( [status] => OK [newsid] => 234567)

And, this response for an unsuccessful copy:

Code:
Array ( [status] => Copy failed [error] => Invalid survey ID )

Cheers,
Tony Partner

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

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 6 months ago #165010 by jsibley
Thank you so much, and my apologies. I took a look at my version of the code and realized that it is time for me to update! A lot seems to have changed in the api code since the version I have been using.

Thanks again.
The topic has been locked.
More
7 years 4 months ago #167098 by VinodhTechie
Same problem for Me too anyhelp would be appreciated struck on copy survey for last 2 days
The topic has been locked.
More
7 years 4 months ago #167147 by tpartner
How are we supposed to answer that without knowing your LimeSurvey version or what you have done.

Did you try the attached example script?

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 4 months ago - 7 years 4 months ago #167148 by vinodhtechiedev
Thanks for the reply,

currently used lime survey version 2.63.1 + +170305

We have the comfort update for 3.0.0-RC.3 (171113) version in our lime survey dashboard it will not taken yet.

Code:

function copySurvey() {

$.ajax({
async: true,
crossDomain: false,
url: "https://<survey domain name>/index.php/admin/remotecontrol",
type: "POST",
dataType: "json",
data: JSON.stringify({
method: 'copy_survey',
params: {'' + lssessionKey + '', 123434, 'copysurveydescription'},
id: 1
}),
cache: false,
headers: {
'content-type': 'application/json',
},
success: function(data) {
console.log(data);
},
error: function(data) {
console.log(JSON.stringify(data));
}
});
}

Please help in which version "copy_survey" will work

Thanks
Last edit: 7 years 4 months ago by vinodhtechiedev.
The topic has been locked.
More
7 years 4 months ago #167151 by tpartner
I am not familiar with AJAXing directly to remote control but it seems to me that "params" should be an array.

Did you try AJAXing to a PHP/jsonRPC script as my example?

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 4 months ago - 7 years 4 months ago #167182 by vinodhtechiedev
i have using it as array only [] It works fine already,


also, tested the same in trial account with 3.6 version it works perfect. it seems not problem with script it returns null value of result in version 2.6



Please let me know which version supports "Copy_survey"
Last edit: 7 years 4 months ago by vinodhtechiedev.
The topic has been locked.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose