Jump to content

Recommended Posts

Posted

Hi Guys, 

Since I'm able to get a Dell equipment warranty status thanks to my API key, I'm using an UDF to extract data from an XML file and get the end date. > 

Thing is, when using InetGet, the original file is in JSON format and the UDF is not working anymore, even if I download the file with the xml extension. Therefore, and when I manually download the page with Chrome, I have a proper XML file where the UDF is working fine.

Here's my code:

  Reveal hidden contents

I even tried to convert the json to xml > https://www.autoitscript.com/forum/topic/185717-js-json-to-xml/

I took a look here https://www.autoitscript.com/forum/topic/104150-json-udf-library-fully-rfc4627-compliant/ but I don't understand anything :/

 

The XML read UDF is just perfect for my needs but I'm stuck here... 

Thanks for any help you can provide :)

-31290-

3MTXM12.json

3MTXM12.xml

~~~ Doom Shall Never Die, Only The Players ~~~

Posted (edited)

Hi @31290

here is two suggestions for you. Hope they are useful.

Let me know if you have any questions, i will do my best to answer :)

$oXML = ObjCreate("Microsoft.XMLDOM")
$oXML.Load("3MTXM12.xml"); or $oXML.LoadXML(FileRead("3MTXM12.xml"))
$oNodes = $oXML.SelectNodes("./AssetWarrantyDTO/AssetWarrantyResponse/AssetWarrantyResponse/AssetEntitlementData/AssetEntitlement/EndDate"); or $oNodes = $oXML.SelectNodes("//AssetEntitlement/EndDate")
For $oNode In $oNodes
    ConsoleWrite($oNode.text&@CRLF)
Next

ConsoleWrite("-----------------------------------------------"&@CRLF)

$oSC = ObjCreate("ScriptControl")
$oSC.language = "JScript"
$oSC.Eval("Array.prototype.Item = function(i){return this[i];};")
$oJSON = $oSC.Eval("("&FileRead("3MTXM12.json")&")")
For $i=0 To $oJSON.AssetWarrantyResponse.length-1
    For $j=0 To $oJSON.AssetWarrantyResponse.Item($i).AssetEntitlementData.length-1
        ConsoleWrite($oJSON.AssetWarrantyResponse.Item($i).AssetEntitlementData.Item($j).EndDate&@CRLF)
    Next
Next

 

Edited by genius257
Posted

Hi Genius257, 

Thanks a lot for your input. 

But in the meantime, I found this solution:

; Creating the object
$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
$oHTTP.Open("GET", "https://sandbox.apidp.dell.com/support/assetinfo/V4/getassetwarranty/ASSET?apikey=XXXX", False)
$oHTTP.SetRequestHeader("Accept", "application/xml")
$oHTTP.Send()

; Download the body response if any, and get the server status response code.
$oReceived = $oHTTP.ResponseText
$oStatusCode = $oHTTP.Status

If $oStatusCode <> 200 then
 MsgBox(4096, "Response code", $oStatusCode)
EndIf

; Saves the body response regardless of the Response code
 $file = FileOpen(@TempDir & "\update222.xml", 2) ; The value of 2 overwrites the file if it already exists
 FileWrite($file, $oReceived)
 FileClose($file)

Can be useful if someone ever need it :)

Bye

-31290-

~~~ Doom Shall Never Die, Only The Players ~~~

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...