Skip to main content

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



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


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


 


 


 

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.


Hi @Thomas Lind 

I have a similar REST API request, written in JavaScript.

First a POST call is made, with username and password in the body, to an authentication url.

A token is returned which is then passed on as a header to a GET call, like this.

headers: {
'Authorization': 'Bearer ' + authorizationString,
'Content-Type': 'application/json',
'Accept': 'application/json'
}

Using the CData Rest connector in TX is somewhat succesful. We have done as you suggested:

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.

This authenticates successfully and I have verified that the correct token is returned in the verbosity 5 log file.

Our problem is when we test the connection. Then we get the following error message:

“Exception has been thrown by the target of an invocation.
HTTP protocol error. 401 Missing Jwt Token Header.”

Should we try using JWT OAuth? If so do you have any advice on doing that? We are unable to even authenticate when we try ourselves. It seems to us that the token is not correctly passed in the header of the GET call.


Hi Pontus,

To resolve the "Exception has been thrown by the target of an invocation. HTTP protocol error. 401 Missing Jwt Token Header" error when testing the connection, check to see whether you have provided the necessary authentication token in the headers.

Here are some steps from the XPilot that may resolve the issue:

1. Check the authentication requirements of the REST API you are trying to connect to. It may require a JWT (JSON Web Token) in the header for authentication.

2. Obtain the JWT token from the API provider. This token is usually generated after successful authentication with the API.

3. In TimeXtender, go to the data source configuration for the REST API.

4. Look for the "Headers" section in the configuration. This is where you can specify the necessary headers for authentication.

5. Add a new header with the key "Authorization" and the value "Bearer JWT token]". Replace JWT token] with the actual token you obtained in step 2.

6. Save the configuration and test the connection again.

If you still encounter the same error after following these steps, it is possible that there is an issue with the authentication process or the token itself. In such cases, it is recommended to reach out to the API provider for further assistance.

You can read more about this here: https://support.timextender.com/data-sources-112/connect-to-a-rest-api-824

 


Hi @Greg Lennox 

To resolve the "Exception has been thrown by the target of an invocation. HTTP protocol error. 401 Missing Jwt Token Header" error when testing the connection, check to see whether you have provided the necessary authentication token in the headers.

How do I do this in the REST connector?

1. Check the authentication requirements of the REST API you are trying to connect to. It may require a JWT (JSON Web Token) in the header for authentication.

2. Obtain the JWT token from the API provider. This token is usually generated after successful authentication with the API.

As I wrote in my first comment, we are authenticating successfully and by enabling logging, I can verify that a valid token is returned.

5. Add a new header with the key "Authorization" and the value "Bearer JWT token]". Replace JWT token] with the actual token you obtained in step 2.

This is what I do in my Node JS script. As far as I can tell, it is not clear if this is possible to do in the REST connector.

@Thomas Lind do you know any way (with or without having to use .rsd files) to pass the token in the header?


Reply