Search code examples
jsonparsingasp-classicconvertapi

Json not being parsed ConvertAPI


I'm using classic asp & JSON to convert html to pdf. I send the request using the following:

        ''Convert output to pdf
        varURL = "https://" & varServerLive & "/import/" & fileName

        postURL = "https://v2.convertapi.com/convert/htm/to/pdf?Secret=SECRET_KET&File=" & varURL & "&StoreFile=true"
        parmToSend = "{""Parameters"":[{""Name"":""File"",""FileValue"":{""url"": """ & varURL & """}}," & _
            "{""Name"":""WebHook"",""Value"":""" & varURL & """}" & _
            "]}"

        Set ServerXmlHttp = Server.CreateObject("MSXML2.XMLHTTP.6.0")
        ServerXmlHttp.open "POST", postURL
        ServerXmlHttp.setRequestHeader "Accept", "application/json"
        ServerXmlHttp.setRequestHeader "Content-Type", "application/json"
        ServerXmlHttp.send parmToSend

        ''Get response
        responseText = ServerXmlHttp.responseText
        response.write(responseText)

        set myJson = JSON.parse(responseText)
        varFileUrl = myJson.Files.Url
        response.write(varFileUrl)

I get the following response:

responseText:

{"ConversionCost":2,"Files":[{"FileName":"54-25062020177.pdf","FileExt":"pdf","FileSize":48596,"FileId":"542c6f079fe5722bdbac2f73f84652d3","Url":"https://v2.convertapi.com/d/542c6f079fe5722bdbac2f73f84652d3/54-25062020177.pdf"}]}

Which is all good, but when I try to return the fileURL I get an error:

Microsoft VBScript runtime error '800a01b6'

Object doesn't support this property or method: 'url'

/docs/members/cert.asp, line 122

Do you see any reason why the url is not being returned? Am I calling the url correctly (eg. myJson.Files.Url)?

Any help would be much appreciated.


Solution

  • Sorted. I needed to specify the position in the array, which is strange cause I never needed to do this in other functions.

    varFileUrl = myJson.Files.[0].Url