Trying to submit using API, WinHttpRequest in Excel

  • Profile Image
    bjorn.kvinge298
    Asked on November 26, 2017 at 02:40 PM

    Hi,

    I am trying to make a script that can send a submission with using the API and WinHttpRequst in Excel vba.

    Can you please help me with the first question/answer field, how and where it should be in the code?

    TargetURL = "https://eu-api.jotform.com/form/73295515263358/submissions?apiKey=XXXXXXXXXXXXXXXXXXXXXXX"
    Set HTTPReq = CreateObject("WinHttp.WinHttpRequest.5.1")
    HTTPReq.Open "PUT", TargetURL, False
    HTTPReq.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
    HTTPReq.send
    MsgBox (HTTPReq.responseText)

    Regards

    McQuinge

  • Profile Image
    Mike
    Answered on November 26, 2017 at 05:03 PM

    I am not really familiar with vba, but the following example should work, just make sure to add your API key:

    https://pastebin.com/raw/YJ8DRS30

    Related API documentation:

    https://api.jotform.com/docs/#post-form-id-submissions

    In provided example, submission[1] represents the field with qid 1 and submission[2] the field with qid 2.

    Sub httpPost()
    Dim XMLHTTP
    Dim result As String
    Dim argumentString
    argumentString = "submission[1]=Siv&submission[2]=Per Nils"
    Set XMLHTTP = CreateObject("MSXML2.XMLHTTP.6.0")
    XMLHTTP.Open "POST", _
    "https://api.jotform.com/form/73295880106965/submissions?apiKey=XXXXXXXXXXXXXXXXXXXXX", False
    XMLHTTP.setRequestHeader "Content-type", "application/x-www-form-urlencoded"
    XMLHTTP.send argumentString
    result = XMLHTTP.responsetext
    Set XMLHTTP = Nothing
    End Sub

    Thank you.

  • Profile Image
    bjorn.kvinge298
    Answered on November 27, 2017 at 03:53 PM

    It worked perfect, thank you very much for your help!  :)