TechDirect OAUTH 2

Anyone have experience using PowerShell with Oauth2 authorization. I have a Dell TechDirect key API ID and API Secret. I can object the initial token without a problem but when I try to acquire the authorization, my script fails.

I’ve obfuscated the API ID and key, but I did a direct copy and paste from Dell’s website.

#My Dell Service Tag
$tag = "J088K72"

# Get Access Token - expires in 3600 seconds
$accessTokenEndpointUrl = ""
$requestBody = @{
grant_type = "client_credentials"
client_id = "XXXXXXXXXXX" # api id
client_secret = "XXXXXXXX" # api secret
$token = Invoke-RestMethod -Method Post -Uri $accessTokenEndpointUrl -Body $requestBody -ContentType "application/x-www-form-urlencoded"

# url for api warranty query - tag is comma separated list of service tags
$url = ""
$headers = @{"Authorization" = "Bearer $token" }
$body = @{
servicetags = $tag

Invoke-RestMethod -URI $url -Method GET -contenttype 'Application/xml' -Headers $headers -body $body

This is the output

Invoke-RestMethod : Invalid Authentication
At C:\Users\bclanton\Documents\REPOS\TP_PSCode\TechDirect\Get-DellAsset.ps1:21 char:2
+ Invoke-RestMethod -URI $url -Method GET -contenttype 'Application/xm ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand


This is to show that I do have a valid token


access_token token_type expires_in scope
------------        ----------      ----------     -----
d0fb4c9f-7732-4b76-b3e0-13fb0640b68d         Bearer 3600 oob

You are adding the full response rather than the access_token, something like this:

$authResponse = Invoke-RestMethod -Method Post -Uri $accessTokenEndpointUrl -Body $requestBody -ContentType "application/x-www-form-urlencoded"

$token = $authResponse.access_token

Yes, that was it.

Thank you.


YOUR scripts allow you to get a token that works perfectly. Can you help me by telling me how to get the return of DELL on a service number?
is it necessary to do get-dellwarranty ? Can you help me? Thank you.