Welcome to the LimeSurvey Community Forum

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

Obtain Token from LimeSurvey Using VBA

  • websolprov
  • websolprov's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
5 years 1 month ago #181907 by websolprov
Obtain Token from LimeSurvey Using VBA was created by websolprov
Dear Friends,

I have a macro system in Excel that does other update tasks for internal records, and I want to (at the end of the process) send out a LimeSurvey to the recipient of the update. I want to use VBA to obtain a token from Lime and then use this to generate an email from within VBA containing the unique link.

I cant get the API to return the session_key despite trying everything I cant get anything to return. This is the current version of code I am using. I dont get any errors, receive the status code = 200 but the response is empty:

Sub GetData()
Dim objHTTP As Object
Dim arrJSON As Variant, strJSON As String
Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")
Url = "http://[website URL obscured]/survey/index.php/admin/remotecontrol"
objHTTP.Open "POST", Url, False
objHTTP.SetRequestHeader "Content-Type", "application/json"
strJSON = "{""method"":""get_session_key"",""username"":""*obscured username*"",""password"":""*obscured password*""}"

objHTTP.send (strJSON)

Debug.Print objHTTP.Status
If objHTTP.Status = "200" Then
MsgBox (objHTTP.responseText)
End If

End Sub
The topic has been locked.
More
4 years 6 months ago #189094 by davidphi
Replied by davidphi on topic Obtain Token from LimeSurvey Using VBA
Hi,

I've just come across your post as I was trying to do the same. The format for the JSON needs to be:

"{""method"":""get_session_key"",""params"":[""username"",""password""],""id"":""1"",""jsonrpc"":""2.0""}"

Then you should get a response

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

Hope this helps!

Cheers,
David
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose