Welcome to the LimeSurvey Community Forum

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

Can you export a question to a .csv file?

  • LimeAprentice
  • LimeAprentice's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
8 years 2 weeks ago #133765 by LimeAprentice
Can you export a question to a .csv file? was created by LimeAprentice
I wanted to export a question into a .csv file is this possible?
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 2 weeks ago #133800 by tpartner
Replied by tpartner on topic Can you export a question to a .csv file?
Why?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • LimeAprentice
  • LimeAprentice's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
8 years 2 weeks ago #133820 by LimeAprentice
Replied by LimeAprentice on topic Can you export a question to a .csv file?
Because I want to import a question using the RPC2 API and one the parameters is a string with the structure of a .csv file, so I wanted to know how's the structure of a .csv file of a Limesurvey question.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 2 weeks ago #133821 by tpartner
Replied by tpartner on topic Can you export a question to a .csv file?
I think that's a typo in the manual. I think it should say "String containing the BASE 64 encoded data of a lsq,csv" which means you can use .lsq (a normal question export) or .csv (I'm not sure how you would get that).


Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • LimeAprentice
  • LimeAprentice's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
8 years 2 weeks ago #133822 by LimeAprentice
Replied by LimeAprentice on topic Can you export a question to a .csv file?
yes that's what I mean a String containing the BASE 64 encoded data of csv file, so it's not possible to export a .csv file from LimeSurvey to find how's the structure of a .csv file?? I know that you need to pass a String but I don't now how it's the structure of the .csv file
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 2 weeks ago #133823 by tpartner
Replied by tpartner on topic Can you export a question to a .csv file?
No, my point is that you don't need a csv. You can use a normal lsq file instead. The lsq export files are actually XML.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • LimeAprentice
  • LimeAprentice's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
8 years 2 weeks ago #133826 by LimeAprentice
Replied by LimeAprentice on topic Can you export a question to a .csv file?
well I don't have any other choice than to try with that xml file, but in the api method it requires the groupID, but I don't know where can I find that groupID is there a function that returns this groupID. I tried with get_group_properties() but this function also requires a gropuID
The topic has been locked.
More
8 years 2 weeks ago #133828 by jelo
I am not into the API but when you create groups you know the ID. If there are no groups, you cannot have an ID.
Is the API not offering a method to create groups?

The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
The topic has been locked.
  • LimeAprentice
  • LimeAprentice's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
8 years 2 weeks ago - 8 years 2 weeks ago #133836 by LimeAprentice
Replied by LimeAprentice on topic Can you export a question to a .csv file?
I created the group using the graphic user interface in localhost/admin but I don't know I tried looking into the details of the group but it only shows the name,

But I really need to know how to get the group id from the api since I'm integrating limesurvey with a web application in java and I need that id to call other api functions so I need to get it using the api
Last edit: 8 years 2 weeks ago by LimeAprentice.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 2 weeks ago #133837 by tpartner
Replied by tpartner on topic Can you export a question to a .csv file?

...but I don't know I tried looking into the details of the group but it only shows the name

You can see the group ID in the "List groups" screen or in the "Group summary" screen.




Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • LimeAprentice
  • LimeAprentice's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
8 years 2 weeks ago - 8 years 2 weeks ago #133838 by LimeAprentice
Replied by LimeAprentice on topic Can you export a question to a .csv file?
Thanks tpartner but I found how to get the group id using the api , you can get it by using list_groups

but know I don't know what this param means

string $sNewqQuestion An optional new question

can I put there a question like this: "what do you think of the weather"

here is my call

"{\"method\": \"import_question\", \"params\": {\"sSessionKey \": "
+ respuesta
+ ", \"iSurveyID\": \"100000\""
+ ", \"iGroupID \": \"2\""
+ ", \"sImportData \": " + "\""+ stringWithTheEntireXML+ "\""
+ ", \"sImportDataType \": \"lsq\""
+ ", \"sMandatory \": \"no\""
+ ", \"sNewQuestionTitle \": \"questionNewTitle\""
+ ", \"sNewqQuestion \": \"what do you think of the weather\""
+ ", \"sNewQuestionHelp \": \"a question help\"},"
+ "\"id\": 1}"));

but the respond is this {"id":null,"result":null,"error":"unable to decode malformed json"}

here is the string I copy and paste the content of the xml file when I exported a question using the graphic user interface

archivo = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+ "<document>"
+ "<LimeSurveyDocType>Question</LimeSurveyDocType>"
+ "<DBVersion>257</DBVersion>"
+ "<languages>"
+ "<language>en</language>"
+ "</languages>"
+ "<questions>"
+ "<fields>"
+ "<fieldname>qid</fieldname>"
+ "<fieldname>parent_qid</fieldname>"
+ "<fieldname>sid</fieldname>"
+ "<fieldname>gid</fieldname>"
+ "<fieldname>type</fieldname>"
+ "<fieldname>title</fieldname>"
+ "<fieldname>question</fieldname>"
+ "<fieldname>preg</fieldname>"
+ "<fieldname>help</fieldname>"
+ "<fieldname>other</fieldname>"
+ "<fieldname>mandatory</fieldname>"
+ "<fieldname>question_order</fieldname>"
+ "<fieldname>language</fieldname>"
+ "<fieldname>scale_id</fieldname>"
+ "<fieldname>same_default</fieldname>"
+ "<fieldname>relevance</fieldname>"
+ "<fieldname>modulename</fieldname>"
+ "</fields>"
+ "<rows>"
+ "<row>"
+ "<qid><![CDATA[1]]></qid>"
+ "<parent_qid><![CDATA[0]]></parent_qid>"
+ "<sid><![CDATA[192622]]></sid>"
+ "<gid><![CDATA[1]]></gid>"
+ "<type><![CDATA[T]]></type>"
+ "<title><![CDATA[codigopre]]></title>"
+ "<question><![CDATA[how is the weatehr]]></question>"
+ "<preg/>"
+ "<help><![CDATA[this is a help text]]></help>"
+ "<other><![CDATA[N]]></other>"
+ "<mandatory><![CDATA[N]]></mandatory>"
+ "<question_order><![CDATA[1]]></question_order>"
+ "<language><![CDATA[en]]></language>"
+ "<scale_id><![CDATA[0]]></scale_id>"
+ "<same_default><![CDATA[0]]></same_default>"
+ "<relevance><![CDATA[1]]></relevance>"
+ "</row>"
+ "</rows>"
+ "</questions>"
+ "</document>";

in that exported xml it has and question id should I delete that part of the xml since I'm creating a question I beleive that the id should be blank in that part of the xml or should I put a random id??
Last edit: 8 years 2 weeks ago by LimeAprentice.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 2 weeks ago #133890 by tpartner
Replied by tpartner on topic Can you export a question to a .csv file?
The contents of the LSQ file need to be Base 64 Encoded.
- en.wikipedia.org/wiki/Base64
- www.freeformatter.com/base64-encoder.html

Additionally, before you do that you should make sure that the question code in the LSQ file does not match any existing codes or the API will return an error. (look for the <title> tag in the LSQ file and modify the CDATA value)

Following the PHP example in the manual , this successfully adds new short-text questions. Of course you will need to modify the variables for your set up and requirements. These variables could also be passed in via GET or POST.

Code:
<?php
 
  require_once 'jsonRPCClient.php';
 
  define( 'LS_BASEURL', 'http://path/to/limeSurvey/');  
  define( 'LS_USER', 'adminUsername' );
  define( 'LS_PASSWORD', 'adminPassword' );
 
  $iSurveyID = 358123; // The survey ID
  $iGroupID = 44; // The group ID
  $sLanguage = 'en'; // The language  
  $sImportData = 'PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4NCjxkb2N1bWVudD4NCiA8TGltZVN1cnZleURvY1R5cGU+UXVlc3Rpb248L0xpbWVTdXJ2ZXlEb2NUeXBlPg0KIDxEQlZlcnNpb24+MjU3PC9EQlZlcnNpb24+DQogPGxhbmd1YWdlcz4NCiAgPGxhbmd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lPg0KICAgIDx2YWx1ZT48IVtDREFUQVtQcmVmaXggdGV4dF1dPjwvdmFsdWU+DQogICAgPGxhbmd1YWdlPjwhW0NEQVRBW2VuXV0+PC9sYW5ndWFnZT4NCiAgIDwvcm93Pg0KICAgPHJvdz4NCiAgICA8cWlkPjwhW0NEQVRBWzUyMV1dPjwvcWlkPg0KICAgIDxhdHRyaWJ1dGU+PCFbQ0RBVEFbc3RhdGlzdGljc19ncmFwaHR5cGVdXT48L2F0dHJpYnV0ZT4NCiAgICA8dmFsdWU+PCFbQ0RBVEFbNV1dPjwvdmFsdWU+DQogICA8L3Jvdz4NCiAgIDxyb3c+DQogICAgPHFpZD48IVtDREFUQVs1MjFdXT48L3FpZD4NCiAgICA8YXR0cmlidXRlPjwhW0NEQVRBW3N1ZmZpeF1dPjwvYXR0cmlidXRlPg0KICAgIDx2YWx1ZT48IVtDREFUQVtTdWZmaXggdGV4dF1dPjwvdmFsdWU+DQogICAgPGxhbmd1YWdlPjwhW0NEQVRBW2VuXV0+PC9sYW5ndWFnZT4NCiAgIDwvcm93Pg0KICA8L3Jvd3M+DQogPC9xdWVzdGlvbl9hdHRyaWJ1dGVzPg0KPC9kb2N1bWVudD4NCg==';   // The Base64 Encoded lsq file
  $sImportDataType = 'lsq'; // Data type  
  $sMandatory = 'N'; // Question mandatory? (optional)
  $sNewQuestionTitle = 'Q66'; // New question code (optional)
  $sNewqQuestion = 'This is new question text...'; // New text (optional)
  $sNewQuestionHelp = 'Some new question help...'; // New help text (optional)
 
  if(ctype_alnum($iSurveyID) &amp;&amp; strlen($iSurveyID) == 6) { // Valid iSurveyID 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 );
 
    // Add new question
    $newQuestion = $myJSONRPCClient->import_question($sSessionKey, $iSurveyID, $iGroupID, $sImportData, $sImportDataType, $sMandatory, $sNewQuestionTitle, $sNewqQuestion, $sNewQuestionHelp);
 
    // Release the session key
    $myJSONRPCClient->release_session_key( $sSessionKey );
  }
  else { // Invalid iSurveyID format
    die( 'Invalid format!' );
  }
 
?>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose