TechDirect OAUTH 2

Welcome Forums General PowerShell Q&A TechDirect OAUTH 2

Viewing 3 reply threads
  • Author
    • #195731
      Topics: 66
      Replies: 71
      Points: 510
      Rank: Major Contributor

      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
    • #195743
      Topics: 12
      Replies: 1615
      Points: 2,530
      Helping Hand
      Rank: Community Hero

      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
    • #195812
      Topics: 66
      Replies: 71
      Points: 510
      Rank: Major Contributor

      Yes, that was it.

      Thank you.

    • #209880
      Topics: 0
      Replies: 1
      Points: 6
      Rank: Member


      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.

Viewing 3 reply threads
  • You must be logged in to reply to this topic.