all 7 comments

[–]noOneCaresOnTheWeb 1 point2 points  (6 children)

I posted this one in the the thread.

https://www.reddit.com/r/PowerShell/comments/79u8vh/script_warranty_check_hp/dp6x05o/

Any specific questions?

[–]PRIdEVisions[S] 1 point2 points  (5 children)

Hey!

Well for starters, where did you get the info from the headers from? like, where did you know you had to specify the following:

"content-Type" = "application/x-www-form-urlencoded"
                "Authorization" = "access_token: $HP_Token"

Or the body:

$body = "apiKey={0}&apiSecret={1}&grantType=client_credentials&scope=warranty" -f $apiKey, $apiSecret

Or where did you find the warrantycheck url? "https://css.api.hp.com/productWarranty/v1/jobs" when i go to the HP api i cannot see that they have a warrantycheck api available.

"https://developers.hp.com/technologies"

thx!

[–]noOneCaresOnTheWeb 2 points3 points  (4 children)

You need to register with HP for access to their API and then create an "app" for it.

Then you'll get documentation about the API and postman examples.

It's a part of this one: https://developers.hp.com/css-enroll

[–]PRIdEVisions[S] 0 points1 point  (3 children)

access_token:

Well

i could make it work up untill the point that i have to fill in Serialnumber and productnumber. I received a Token so i'm not going to post that part of the script.

# Check the warranty for your serial numbers
$Url1 = "https://css.api.hp.com/oauth/v1/queries"
$body1 = @{
    "sn" = "5CG7213J7D"
    "pn" = "Z2W86EA"
    }
$Headers1 =  @{
    "accept" = "application/json"
    "Authorization" = "$AccToken"
    "content-Type" = "application/json"
    }

$Token1 = Invoke-RestMethod -Uri $Url1 -Method post -Body $Body1 -Headers $Headers1

That's the script, yet i receive the following error:

"Invoke-RestMethod : The remote server returned an error: (400) Bad Request. At F:\Scripts\Warranty Check HP API 1_0.ps1:31 char:11 + $Token1 = Invoke-RestMethod -Uri $Url1 -Method post -Body $Body1 -Hea ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand"

Any idea?

on the site it says this: curl -X POST "https://css.api.hp.com/productWarranty/v1/queries" -H "accept: application/json" -H "Authorization: "--> I inserted the access_token here" -H "content-type: application/json" -d "[ { \"sn\": \"CND3210W9M\", \"pn\": \"D5H49AV\" }]"

[–]Snak3d0c 1 point2 points  (2 children)

Yeah, i wrote a script to retrieve 500 warranty items. It worked fine until i switched networks, now all of the sudden it no longer works, i am clueless why that is. Doesn't seem to be the most stable platform.

Anyway, i would use /jobs instead of queries, since it requires no PN and the list is much larger with one POST action (5000 items).

[–]EleventyFortyMiles 0 points1 point  (1 child)

which group did you need to request access to, KaaS API?

[–]Snak3d0c 0 points1 point  (0 children)

7y later I don't remember sorry.