Welcome to the LimeSurvey Community Forum

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

How Can I Auto-Populate Known Fields from RPC API

  • nichogenius
  • nichogenius's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 years 4 months ago - 2 years 4 months ago #232844 by nichogenius
Your LimeSurvey version: .5.4.5
Own server or LimeSurvey hosting: Own server (Community)
Survey theme/template: NA
==================

I am writing an integration script that creates survey participants and sends invites whenever a support ticket is closed.
I have access to all of the ticket information fields available to me in a PHP script and I can successfully add participants and send invitations from the script.
The last piece is I want to submit some information from the ticket into question fields in the response by using the participant token.

Example: I have a hidden question called "Ticket ID".  I intend to auto-populate this question with the ticket number from my ticket system completely transparently to the end user.
I have figured out how to pass question answers by adding a GET request parameter, but this exposes that information to the end user (this is acceptable, but not ideal)

I think I need to use the 

Code:
// Get the API Client Handle
$myJSONRPCClient = new \org\jsonrpcphp\JsonRPCClient( LS_RPCURL );
 
// Authenticate and receive a session key
$sessionKey= $myJSONRPCClient->get_session_key( LS_USER, LS_PASSWORD );
 
// Build the participant from ticket data
$participant = array("email"=>$email,"lastname"=>$last,"firstname"=>$first,"language"=>$language,"emailstatus"=>$emailStatus); ​​​​​
 
// Add single participant to an array of length 1
$participantList = array($participant);
 
// Add the participant to the survey and save the JSON response to get the tokens out of
$tokens = $myJSONRPCClient->add_participants( $sessionKey, $surveyId, $participantList, $createToken );
 
// Save some ticket information using the token
// TODO - How do I do this?
// Save $ticketNumber to "Ticket ID" question.  I have a already created a URL parameter called 'ticketid' which works.  If I can use this parameter directly from the API, that would be awesome.
 
// Create an array of length 1 using the single returned token.
$tokenIds = array($tokens[0]['tid']);
 
// Send invites
$tokens = $myJSONRPCClient->add_participants( $sessionKey, $surveyId, $participantList, $createToken );


 
Last edit: 2 years 4 months ago by nichogenius.

Please Log in to join the conversation.

  • nichogenius
  • nichogenius's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 years 4 months ago - 2 years 4 months ago #232845 by nichogenius
Replied by nichogenius on topic How Can I Auto-Populate Known Fields from RPC API
I just found a solution, though it wasn't quite what I was expecting.

The trick is to use a participant attribute instead of auto-populating a question.

I created a couple of new attributes through the web UI admin, then I was able to do the following:

Code:
$participant = array( "email"=>$email,"lastname"=>$last,"firstname"=>$first,"language"=>$language,"emailstatus"=>$emailStatus, "attribute_1"=>$ticketId, "attribute_2"=>$groupName );


A couple of remaining gripes:
  1. How to choose my own attribute name? I suspect the auto-generated attribute names are for the sake of avoiding database collisions and to simplify the schema updates.
  2. If I wanted to use a survey question instead of an attribute, could I?  In my case, attributes are more appropriate, but I may find a case where I want to submit a question response in the future.
Last edit: 2 years 4 months ago by nichogenius. Reason: spelling correction.

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose