wisem2540 Posted December 30, 2019 Share Posted December 30, 2019 Hey all, I have been fussing around with Rest API from Airwatch MDM trying to retrieve some information about my devices (corp environment). I gave up doing it natively in autoit for now and decided on running Curl.exe from a windows command prompt, Here is an example of that command curl "!!!URL!!/api/mam/apps/purchased/search?applicationname=Angry%20Birds%20Go!&locationgroupid=1098" \ -H "Accept: application/json" \ -H "Authorization: Basic !!APIKey!!!=" \ -H "aw-tenant-code: !!!!!" Here is an example of those outputs. I have looked at the JSON and XML UDFs but I don't really understand how they function. Any help on this would be helpful Json {"Application":[{"ApplicationName":"Angry Birds Go!","ApplicationSize":"436.56 MB","ApplicationUrl":"https://itunes.apple.com/us/app/angry-birds-go!/id642821482?mt=8&uo=4","Assignments":[{"Status":"Active","SmartGroupId":4193,"LocationGroupId":"0","Users":0,"Allocated":1,"Redeemed":0,"AssignmentRuleType":"License"}],"BundleId":"com.rovio.angrybirdsgo","IsReimbursable":false,"LargeIconUri":"","MediumIconUri":"","SmallIconUri":"","LocationGroupId":1098,"Platform":2,"ManagedDistribution":{"Purchased":1,"Burned":0,"OnHold":0,"Available":1,"AppLicenseEligibility":"Device"},"Deployment":{"AssignmentType":"OnDemand","RemoveOnUnenroll":true,"PreventApplicationBackup":true,"UseVPN":false},"AppType":"Purchased","AssignmentStatus":"Assigned","IsAutoUpdateEnabled":false,"Id":{"Value":140}}],"Page":0,"PageSize":500,"Total":1} XML <?xml version="1.0" encoding="utf-8"?><PurchasedApplicationSearchResult xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.air-watch.com/servicemodel/resources"><Page>0</Page><PageSize>500</PageSize><Total>1</Total><Application><PurchasedApplicationEntity><Id xmlns="">140</Id><ApplicationName>Angry Birds Go!</ApplicationName><ApplicationSize>436.56 MB</ApplicationSize><ApplicationUrl>https://itunes.apple.com/us/app/angry-birds-go!/id642821482?mt=8&uo=4</ApplicationUrl><Assignments><Assignment><Status>Active</Status><SmartGroupId>4193</SmartGroupId><LocationGroupId>0</LocationGroupId><Users>0</Users><Allocated>1</Allocated><Redeemed>0</Redeemed><AssignmentRuleType>License</AssignmentRuleType></Assignment></Assignments><BundleId>com.rovio.angrybirdsgo</BundleId><IsReimbursable>false</IsReimbursable><LargeIconUri /><MediumIconUri /><SmallIconUri /><LocationGroupId>1098</LocationGroupId><Platform>2</Platform><ManagedDistribution><Purchased>1</Purchased><Burned>0</Burned><OnHold>0</OnHold><Available>1</Available><AppLicenseEligibility>Device</AppLicenseEligibility></ManagedDistribution><Deployment><AssignmentType>OnDemand</AssignmentType><RemoveOnUnenroll>true</RemoveOnUnenroll><PreventApplicationBackup>true</PreventApplicationBackup><UseVPN>false</UseVPN><VPNProfileId xsi:nil="true" /></Deployment><AppType>Purchased</AppType><AssignmentStatus>Assigned</AssignmentStatus><IsAutoUpdateEnabled>false</IsAutoUpdateEnabled></PurchasedApplicationEntity></Application></PurchasedApplicationSearchResult> Link to comment Share on other sites More sharing options...
TheXman Posted December 30, 2019 Share Posted December 30, 2019 (edited) 1 hour ago, wisem2540 said: I gave up doing it natively in autoit for now and decided on running Curl.exe from a windows command prompt 1 hour ago, wisem2540 said: I have looked at the JSON and XML UDFs but I don't really understand how they function. Any help on this would be helpful I doubt that your request for assistance could have been much more vague. What is it that you want help with? Do you want help retrieving the JSON using AutoIt natively instead of using a CURL command? Do you want help parsing the data that you are already retrieving using the CURL command? If it is help parsing the JSON data, what values from the result are you wanting to parse? Or is it that you need help understanding how to use the json or xml UDFs? The more specific your request is, the more likely you will be to get someone interested enough to help you. Just throwing some vague request out there, without specifying any details on what you need help with, will most likely just get ignored -- which is probably what I should have done. What have you tried in your efforts to accomplish your goal. What exactly are you having a problem understanding? Do you prefer parsing XML or JSON? Edited December 30, 2019 by TheXman FrancescoDiMuro 1 CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
wisem2540 Posted December 31, 2019 Author Share Posted December 31, 2019 17 hours ago, TheXman said: I doubt that your request for assistance could have been much more vague. What is it that you want help with? Do you want help retrieving the JSON using AutoIt natively instead of using a CURL command? Do you want help parsing the data that you are already retrieving using the CURL command? If it is help parsing the JSON data, what values from the result are you wanting to parse? Or is it that you need help understanding how to use the json or xml UDFs? The more specific your request is, the more likely you will be to get someone interested enough to help you. Just throwing some vague request out there, without specifying any details on what you need help with, will most likely just get ignored -- which is probably what I should have done. What have you tried in your efforts to accomplish your goal. What exactly are you having a problem understanding? Do you prefer parsing XML or JSON? All I really need are they Properties and values into a 2D Array. Link to comment Share on other sites More sharing options...
Danp2 Posted December 31, 2019 Share Posted December 31, 2019 @wisem2540 Here's a quick and dirty example with your JSON string -- #include <JSON.au3> $sJson = '{"Application":[{"ApplicationName":"Angry Birds Go!","ApplicationSize":"436.56 MB","ApplicationUrl":"https://itunes.apple.com/us/app/angry-birds-go!/id642821482?mt=8&uo=4","Assignments":[{"Status":"Active","SmartGroupId":4193,"LocationGroupId":"0","Users":0,"Allocated":1,"Redeemed":0,"AssignmentRuleType":"License"}],"BundleId":"com.rovio.angrybirdsgo","IsReimbursable":false,"LargeIconUri":"","MediumIconUri":"","SmallIconUri":"","LocationGroupId":1098,"Platform":2,"ManagedDistribution":{"Purchased":1,"Burned":0,"OnHold":0,"Available":1,"AppLicenseEligibility":"Device"},"Deployment":{"AssignmentType":"OnDemand","RemoveOnUnenroll":true,"PreventApplicationBackup":true,"UseVPN":false},"AppType":"Purchased","AssignmentStatus":"Assigned","IsAutoUpdateEnabled":false,"Id":{"Value":140}}],"Page":0,"PageSize":500,"Total":1}' Json_Dump($sJson) $oJson = Json_Decode($sJson) ConsoleWrite(Json_Get($oJson,".Application[0].ApplicationName") & @CRLF) $oApp=Json_Get($oJson,".Application[0]") Json_Dump(Json_Encode($oApp)) I don't know of a way to dump it directly to an array, but you can certainly code it yourself. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Nine Posted December 31, 2019 Share Posted December 31, 2019 For the fun of it : #include <Array.au3> Opt ("MustDeclareVars", 1) Local $sJson = '{"Application":[{"ApplicationName":"Angry Birds Go!","ApplicationSize":"436.56 MB","ApplicationUrl":"https://itunes.apple.com/us/app/angry-birds-go!/id642821482?mt=8&uo=4","Assignments":[{"Status":"Active","SmartGroupId":4193,"LocationGroupId":"0","Users":0,"Allocated":1,"Redeemed":0,"AssignmentRuleType":"License"}],"BundleId":"com.rovio.angrybirdsgo","IsReimbursable":false,"LargeIconUri":"","MediumIconUri":"","SmallIconUri":"","LocationGroupId":1098,"Platform":2,"ManagedDistribution":{"Purchased":1,"Burned":0,"OnHold":0,"Available":1,"AppLicenseEligibility":"Device"},"Deployment":{"AssignmentType":"OnDemand","RemoveOnUnenroll":true,"PreventApplicationBackup":true,"UseVPN":false},"AppType":"Purchased","AssignmentStatus":"Assigned","IsAutoUpdateEnabled":false,"Id":{"Value":140}}],"Page":0,"PageSize":500,"Total":1}' ClipPut ($sJson) $sJson = StringRegExpReplace ($sJson, '(https?)(:)\/\/', "$1;\/\/") Local $aArray = StringSplit ($sJson, ":,{", $STR_CHRSPLIT) ;_ArrayDisplay ($aArray) Local $aFinal[Round($aArray[0]/2)][2], $iStart = 0, $iFinal = 0 Local $sP1, $sP2 While True $iStart += 2 If $iStart > $aArray[0] Then ExitLoop $sP1 = $aArray[$iStart] $sP2 = StringRegExpReplace ($aArray[$iStart+1],"}*]*$","") If $sP2 = "" or $sP2 = "[" Then ContinueLoop $aFinal[$iFinal][0] = $sP1 $aFinal[$iFinal][1] = $sP2 $iFinal += 1 WEnd redim $aFinal[$iFinal][2] _ArrayDisplay ($aFinal) argumentum 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now