I am having trouble using Invoke-RestMethod in PS and retrieving the results...
here is my code:
$request='https://sandbox.api.dell.com/support/assetinfo/v4/getassetwarranty/SERVICETAG?apikey=APIKEY'
Invoke-RestMethod $request |
Select $request.ServiceTag
The JSON returned by the DELL API call looks like this:
{
"AssetWarrantyResponse": [
{
"AssetHeaderData": {
"BUID": "202",
"ServiceTag": "XXXXXXX",
"ShipDate": "2017-12-04T18:00:00",
"CountryLookupCode": "UK",
"LocalChannel": "ENTP",
"CustomerNumber": "NNNNNN",
"ItemClassCode": "OB002",
"IsDuplicate": false,
"MachineDescription": "Latitude 7480",
"OrderNumber": "123456789",
"ParentServiceTag": null
},
"ProductHeaderData": {
"SystemDescription": "Latitude 7480",
"ProductId": "latitude-14-7480-laptop",
"ProductFamily": "Laptops",
"LOB": "Latitude",
"LOBFriendlyName": "Latitude"
},
"AssetEntitlementData": [
{
"StartDate": "2017-12-04T18:00:00",
"EndDate": "2020-12-05T17:59:59",
"ServiceLevelDescription": "Onsite Service After Remote Diagnosis (Consumer Customer)/ Next Business Day Onsite After Remote Diagnosis (Commercial Customer)",
"ServiceLevelCode": "ND",
"ServiceLevelGroup": 5,
"EntitlementType": "INITIAL",
"ServiceProvider": null,
"ItemNumber": "123-12345"
},
{
"StartDate": "2017-12-04T06:00:00",
"EndDate": "2025-12-05T05:59:59",
"ServiceLevelDescription": "Dell Digitial Delivery",
"ServiceLevelCode": "D",
"ServiceLevelGroup": 11,
"EntitlementType": "INITIAL",
"ServiceProvider": null,
"ItemNumber": "525-10302"
}
]
}
],
"InvalidFormatAssets": { "BadAssets": [ ] },
"InvalidBILAssets": { "BadAssets": [ ] },
"ExcessTags": { "BadAssets": [ ] },
"AdditionalInformation": null
}
I need to get several values from that JSON response, I tried using ConvertFrom-Json with |Select ServiceTag, SystemDescription, EndDate by following the advice in MS TechNet Scripting Guy: Playing with JSON and PowerShell
But couldn't get values for ServiceTag, SystemDescription, EndDate (they were blank) - eventually we need to run this in a script for nearly 1500 computers in blocks of 80 at a time and update a database
So where am I going wrong here?
I did try something like Invoke-RestMethod $request |
Select $request.AssetHeaderData.ServiceTag but had no luck
$o=(Get-Clipboard | ConvertFrom-Json) ; $o.AssetWarrantyResponse.AssetHeaderData.ServiceTagI get backXXXXXXX.Get-ClipboardcmdLet to work in PS?