1

Set up API basic auth with token request

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 "======================================"

 

 

 

0 comments

Please sign in to leave a comment.