- Posts: 3
- Thank you received: 1
Ask the community, share ideas, and connect with other LimeSurvey users!
let sessionKey = ""; const paramsGetSessionKey = { method: "get_session_key", params: ["myUsername", "myPassword", "Authdb"], id: 1, }; const optionsGetSessionKey = { method: "POST", mode: "cors", body: JSON.stringify(paramsGetSessionKey), headers: { "Content-Type": "application/json", "Access-Control-Allow-Origin": "*", }, }; fetch( "https://mydomain.com/index.php/admin/remotecontrol", optionsGetSessionKey ) .then((response) => response.json()) .then((response) => { console.log(response); sessionKey = response.result; });
{ id: 1, result: 'asdf123456789', error: null }
const paramsExportResponses = { method: "export_responses", params: { sessionkey: sessionKey, surveyid: 12345, documenttype: "csv", }, jsonrpc: "2.0", id: 1, }; const optionsExportResponses = { method: "POST", mode: "cors", body: JSON.stringify(paramsExportResponses), contentType: "application/json", dataType: "json", }; fetch( "https://mitwirk-o-mat.de/formular/index.php/admin/remotecontrol", optionsExportResponses ) .then((response) => response.json()) .then((response) => { console.log(response); });
SyntaxError: Unexpected end of JSON input at JSON.parse (<anonymous>;)
Please Log in to join the conversation.
.then((response) => response.json())
Response { [Symbol(realm)]: null, [Symbol(state)]: { aborted: false, rangeRequested: false, timingAllowPassed: true, requestIncludesCredentials: true, type: 'default', status: 200, timingInfo: { startTime: 55.555555555, // changed by me redirectStartTime: 0, redirectEndTime: 0, postRedirectStartTime: 55.5555555, // changed by me finalServiceWorkerStartTime: 0, finalNetworkResponseStartTime: 0, finalNetworkRequestStartTime: 0, endTime: 0, encodedBodySize: 20, decodedBodySize: 0, finalConnectionTimingInfo: null }, cacheState: '', statusText: 'OK', headersList: HeadersList { [Symbol(headers map)]: [Map], [Symbol(headers map sorted)]: null }, urlList: [ [URL] ], body: { stream: undefined } }, [Symbol(headers)]: HeadersList { [Symbol(headers map)]: Map(15) { 'server' => 'nginx', 'date' => 'Sat, 21 Jan 2023 09:13:00 GMT', 'content-type' => 'text/html; charset=UTF-8', 'transfer-encoding' => 'chunked', 'connection' => 'keep-alive', 'vary' => 'Accept-Encoding', 'set-cookie' => 'XX-XXXXXXXXXXXXXXX=478rhfeuk898484uoedj8334; path=/; secure; HttpOnly', // changed by me 'expires' => 'Thu, 19 Nov 1981 08:52:00 GMT', 'cache-control' => 'no-store, no-cache, must-revalidate', 'pragma' => 'no-cache', 'access-control-allow-origin' => '*', 'x-xss-protection' => '1; mode=block', 'referrer-policy' => 'strict-origin-when-cross-origin', 'strict-transport-security' => 'max-age=63072000; includeSubDomains; preload', 'content-encoding' => 'gzip' }, [Symbol(headers map sorted)]: null } }
Please Log in to join the conversation.
const paramsGetSessionKey = { method: "get_session_key", params: ["MyUserName", "MyPassword", "Authdb"], id: 1, }; const optionsGetSessionKey = { method: "POST", mode: "same-origin", // Change if you make a cross-domain API call body: JSON.stringify(paramsGetSessionKey), headers: { "Content-Type": "application/json", } }; fetch("https://mydomain.com/index.php/admin/remotecontrol", optionsGetSessionKey).then((response) => response.json()).then((response) => { let sessionKey = response.result; console.log(sessionKey); const paramsExportResponses = { method: "export_responses", params: { sSessionKey: sessionKey, iSurveyID: 1234556, sDocumentType: "csv", sResponseType: "long", }, jsonrpc: "2.0", id: 1, }; const optionsExportResponses = { method: "POST", body: JSON.stringify(paramsExportResponses), dataType: "text", // Change to JSON if you want JSON instead of CSV contentType: "application/json", mode: "same-origin", // See above headers: { "Content-Type": "application/json", } }; fetch("https://mydomain.com/formular/index.php/admin/remotecontrol", optionsExportResponses).then((response) => response.json()).then((response) => { const csvContent = atob(response.result); console.log(csvContent); const output = document.createElement("p"); output.textContent = csvContent; document.body.appendChild(output); }); });
Please Log in to join the conversation.