- Posts: 2
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
LimeSurvey add_participants via Talend and Java
- RobVor
- Topic Author
- Offline
- New Member
Less
More
6 years 2 months ago #163184
by RobVor
LimeSurvey add_participants via Talend and Java was created by RobVor
Hi All,
New here and learning about LSRC2 and its pitfalls.
I have been given a few projects to automate a lot of our surveys and retrieval of response etc.
Recently, I have been asked to load participants and send invitations for a new project that we are starting. The reason it needs to be automated is that the client will be dumping the data twice daily and although they gave us times, we know well enough that this isn't how things always work.
Now, I have everything from the monitoring of the specific FTP site to the prepping and cleaning of the data all in order, but cannot get the 'post' to work at all.
I am using Talend Studio to manage this, not that I think it makes that much of a difference. I am able to get the session key, list survey questions etc. So I know it works.
The setup is as follows:
- A tRest component is loaded and set to:
"content-type" : "application/json"
"connection" : "Keep-Alive"
"content-length" : "67"
"user-agent" : "Apache-HttpClient/4.2.2 (java 1.5)"
The body then contains one line:
((String)globalMap.get("Participants"))
This calls the Java variable used to store the whole construct.
The the java component that builds the construct is:
String AddParticipants = "{\"method\""add_participants\",\"params\":[\""+(String)globalMap.get("SessionKey")+"\",\"398747\",\"["+((String)globalMap.get("output"))+"]\"],\"id\""1\"}";
globalMap.put("Participants", AddParticipants)
When I run the job I get:
{"method":"add_participants","params":["va2ij8euv3kc5ju5hh82vfuurfgap5uv","398747","[{"firstname":"Bob","lastname":"Hope","email":"bob@gmail.com","emailstatus":"OK","attribute_2":"8000009876","attribute_3":"Bob Hope","attribute_4":"Yasmien","attribute_6":"28 January 2018","attribute_9":"Refreshments","attribute_11":"AGG","attribute_12":"NMT 12345678","attribute_13":"NMT456987","attribute_14":"XYZ4569879","attribute_15":"ABC1325648"}]"],"id":"1"}
Which appears fine. (At least over the past day I have been breaking my brain a bit hahaha)
But the response is:
{"id":null,"result":null,"error":"unable to decode malformed json"}
Any help or pointers please?
BTW, I added the \"["+((String) and ))+"]\"]
^--- Bracket ^--- Bracket
Because I initially though that LSRC needed this to understand the array passed.
New here and learning about LSRC2 and its pitfalls.
I have been given a few projects to automate a lot of our surveys and retrieval of response etc.
Recently, I have been asked to load participants and send invitations for a new project that we are starting. The reason it needs to be automated is that the client will be dumping the data twice daily and although they gave us times, we know well enough that this isn't how things always work.
Now, I have everything from the monitoring of the specific FTP site to the prepping and cleaning of the data all in order, but cannot get the 'post' to work at all.
I am using Talend Studio to manage this, not that I think it makes that much of a difference. I am able to get the session key, list survey questions etc. So I know it works.
The setup is as follows:
- A tRest component is loaded and set to:
"content-type" : "application/json"
"connection" : "Keep-Alive"
"content-length" : "67"
"user-agent" : "Apache-HttpClient/4.2.2 (java 1.5)"
The body then contains one line:
((String)globalMap.get("Participants"))
This calls the Java variable used to store the whole construct.
The the java component that builds the construct is:
String AddParticipants = "{\"method\""add_participants\",\"params\":[\""+(String)globalMap.get("SessionKey")+"\",\"398747\",\"["+((String)globalMap.get("output"))+"]\"],\"id\""1\"}";
globalMap.put("Participants", AddParticipants)
When I run the job I get:
{"method":"add_participants","params":["va2ij8euv3kc5ju5hh82vfuurfgap5uv","398747","[{"firstname":"Bob","lastname":"Hope","email":"bob@gmail.com","emailstatus":"OK","attribute_2":"8000009876","attribute_3":"Bob Hope","attribute_4":"Yasmien","attribute_6":"28 January 2018","attribute_9":"Refreshments","attribute_11":"AGG","attribute_12":"NMT 12345678","attribute_13":"NMT456987","attribute_14":"XYZ4569879","attribute_15":"ABC1325648"}]"],"id":"1"}
Which appears fine. (At least over the past day I have been breaking my brain a bit hahaha)
But the response is:
{"id":null,"result":null,"error":"unable to decode malformed json"}
Any help or pointers please?
BTW, I added the \"["+((String) and ))+"]\"]
^--- Bracket ^--- Bracket
Because I initially though that LSRC needed this to understand the array passed.
The topic has been locked.
- RobVor
- Topic Author
- Offline
- New Member
Less
More
- Posts: 2
- Thank you received: 0
6 years 2 months ago #163192
by RobVor
Replied by RobVor on topic LimeSurvey add_participants via Talend and Java
Never mind.
Character escaping and proper placing of the constructs works.
The fix is:
String AddParticipants = "{\"method\""add_participants\",\"params\":[\""+(String)globalMap.get("SessionKey")+"\",\"398747\",["+((String)globalMap.get("output"))+"]],\"id\""1\"}";
Character escaping and proper placing of the constructs works.
The fix is:
String AddParticipants = "{\"method\""add_participants\",\"params\":[\""+(String)globalMap.get("SessionKey")+"\",\"398747\",["+((String)globalMap.get("output"))+"]],\"id\""1\"}";
The topic has been locked.