# TechDirect OAUTH 2

**URL:** <https://forums.powershell.org/t/techdirect-oauth-2/13596>\
**Category:** PowerShell Help\
**Created:** [December 30, 2019, 2:11pm UTC](https://forums.powershell.org/t/techdirect-oauth-2/13596 "2019-12-30T14:11:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![brian-clanton](https://avatars.discourse-cdn.com/v4/letter/b/ebca7d/32.png) [@brian-clanton](https://forums.powershell.org/u/brian-clanton)\
**Post date:** [December 30, 2019, 2:11pm UTC](https://forums.powershell.org/t/techdirect-oauth-2/13596/1 "2019-12-30T14:11:12Z")

</div>

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 = "https://apigtwb2c.us.dell.com/auth/oauth/v2/token"
$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 = "https://apigtwb2c.us.dell.com/PROD/sbil/eapi/v5/asset-entitlements"
$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
```

&nbsp;

This is to show that I do have a valid token

&nbsp;

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

---

<div class="post-metadata">

**Author:** ![rob-simmers](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/rob-simmers/32/1010_2.png) [@rob-simmers](https://forums.powershell.org/u/rob-simmers)\
**Post date:** [December 30, 2019, 3:37pm UTC](https://forums.powershell.org/t/techdirect-oauth-2/13596/2 "2019-12-30T15:37:26Z")

</div>

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
```

---

<div class="post-metadata">

**Author:** ![brian-clanton](https://avatars.discourse-cdn.com/v4/letter/b/ebca7d/32.png) [@brian-clanton](https://forums.powershell.org/u/brian-clanton)\
**Post date:** [December 31, 2019, 9:57am UTC](https://forums.powershell.org/t/techdirect-oauth-2/13596/3 "2019-12-31T09:57:15Z")

</div>

Yes, that was it.

Thank you.

---

<div class="post-metadata">

**Author:** ![stephane13](https://avatars.discourse-cdn.com/v4/letter/s/ed655f/32.png) [@stephane13](https://forums.powershell.org/u/stephane13)\
**Post date:** [March 12, 2020, 7:54am UTC](https://forums.powershell.org/t/techdirect-oauth-2/13596/4 "2020-03-12T07:54:19Z")

</div>

Hello,

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.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:30pm UTC](https://forums.powershell.org/t/techdirect-oauth-2/13596/5 "2024-05-16T20:30:17Z")

</div>


