Solved

Set up API basic auth with token request

  • 18 November 2020
  • 1 reply
  • 25 views

I have below the API request for Power Shell. Now I want to set it up in TX. 


How to set up (Basic) Authentication for a request with a token retrieve? 


 


# Force the use of SSL


[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12


#######################


# SETTINGS                                                                       #


#######################


# REST API SETTINGS #


$API_key = "HIDDEN"


$API_username = "HIDDEN"


$API_password = "HIDDEN"


$API_company = "HIDDEN"


$API_URL_Login = "https://secure.xxxxxxxxxxxxx.eu/ta/rest/v1/login"


#######################


# LOGIN AND RETRIEVE TOKEN FOR UKG Ready                                         #


#######################


         Write-Host "### Retrieving token"


           $headers_login = @{   'Content-Type' = 'application/json';         'Accept' = 'application/json';         'API-Key' = $API_key;      }


    Write-Host "- Headers prepared"


        $request_login = '{"credentials": {"username": "'+$API_username+'", "password": "'+$API_password+'", "company": "'+$API_company+'"  }


        }'


    Write-Host "- JSON request prepared"


    Write-Host "- Invoking webrequest"


        $response = Invoke-RestMethod -Uri $API_URL_Login -ContentType 'application/json;charset=utf-8' -Method POST -Headers $headers_login


-Body $request_login


        $WFRtoken = $response.token


    Write-Host "- Webrequest finished"


    write-host "- Token received:" $WFRtoken


    Write-Host "-----"


    Write-Host " "


#########################


# DATA EXPORT INTERFACE                                                          #


#########################


Write-Host "### Data export interface"


$uri = "https://secure.xxxxxxxxxxxxxxx.eu/ta/rest/v1/report/saved/xxxxxxxxxxx"


$headers_request = @{


   'Accept' = '*/xml';


   'Authentication' = 'Bearer '+$WFRtoken;


   'Cache-Control' = 'no-cache' }


$result = Invoke-RestMethod -Uri $uri -Headers $headers_request


 


 


Write-Host "======================================"


Write-Host "                                                                       "


Write-Host "                  INTERFACE DONE                                       "


Write-Host "                                                                       "


Write-Host "======================================"


 


 


 

icon

Best answer by Thomas Lind 23 January 2023, 14:52

View original

1 reply

Userlevel 2
Badge +5

Hi

You can use OAuth Authentication with grant type set to PASSWORD. Then you need to fill out a OAuth Access Token URL and add an user in the User field and a password in the Password field.

Then you click on Authorize OAuth. If successful that is it.

https://legacysupport.timextender.com/hc/en-us/articles/360034695651-Connect-to-a-REST-API#oauth-authentication

Do you know if you need more options to authenticate?

I think I saw that you apply a company. If so you can probably add this part in the OAuth Params field. Like Company=<companyname>

Try it out.

Reply