How to access Data Virtualization ODATA URL from Excel using Bearer token?

How to access Data Virtualization ODATA URL from Excel using Bearer token?

book

Article ID: KB0137748

calendar_today

Updated On:

Products Versions
TIBCO Data Virtualization All supported versions

Description

Pre-requisite: Ensure that an OAuth domain is already configured in the DV instance. For this example, we will use Azure as the Identity Provider.

Steps to follow -  

(1) Prepare the OData Service URL

For the DV-published OData URL that you wish to access:

* Ensure the 'Bearer' checkbox is selected.
* Copy the 'Service URL' (double-click on the URL to copy it).

Example Service URL: http://muepvdipd1439.corp.cloud.com:9900/odata/test/

image.png

Note: If you encounter an error such as *"Unsupported: No primary key defined. Please define a primary key to access this view via OData"*, verify that the underlying resource has a primary key defined. Follow the standard procedure in DV to define a primary key. if needed.

(2) Obtain an Access Token (External to DV)

You can retrieve an access token using tools like https://oauthdebugger.com. Enter the following details:

* Authorization URI: https://login.microsoft.com/<tenantId>/oauth2/v2.0/authorize

* Redirect URI:  https://oauthdebugger.com/debug
(Ensure this redirect URI is also added under the Azure App Registration: `Authentication > Web Redirect URIs)

* Client ID & Scope: As configured in the DV OAuth domain.

* Select the checkboxes:

Response Type: `token`
Response Mode: `form_post`

Click Send Request. Screenshot for reference. 

image.png

Once the access token is generated, click the copy icon next to it to copy the token.

image.png

(3) Use Access Token in Excel Power Query

* Open Excel.
* Navigate to: `Data` tab > `Get Data` > `Launch Power Query Editor`.
* Go to: `New Source` > `Other Sources` > `Blank Query`.
* Open 'Advanced Editor' and paste the following code (update the `url` and `token` values accordingly):

 let
    url = "http://muepvdipd1439.corp.cloud.com:9900/odata/test/employees",
    token = "eyJ0e..Nhb-8tk6gSTDSceJsN1zSL3FthIeG3ohdoEn8yjnr03cCaDCdAf0coicYN1NlzYDkTtQokFGZnnCWYG89jA_A", 
    headers = [
        Authorization = "Bearer " & token
    ],
    rawResponse = Web.Contents(url, [Headers = headers]),
    responseText = Text.FromBinary(rawResponse)
in
    responseText

Note -The token shown above is truncated. Real tokens are typically longer. Screenshot for reference - 

image.png

Click Done and the OData URL will execute using the Bearer token, returning the results : 

image.png

You can now continue working with and transforming the data using Power Query as needed.

Environment

All supported Operating Systems

Issue/Introduction

This articles provides details on how to access Data Virtualization ODATA URL from Excel using Bearer token?