> For the complete documentation index, see [llms.txt](https://uidata.gitbook.io/datacentral-knowledge-center/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://uidata.gitbook.io/datacentral-knowledge-center/product-guides/isv-for-report-embedding.md).

# ISV for Report Embedding

## Content

[Step 1: Setting up the API request](#step-1-setting-up-the-api-request)

[Step 2: Constructing the POST payload](#step-2-constructing-the-post-payload)

[Step 3: Sending the Request](#step-3-sending-the-request)

[Step 4: Embedding the Power BI Report](#step-4-embedding-the-power-bi-report)

[Security and Best Practices](#security-and-best-practices)

[Additional Notes](#additional-notes)

[Examples](#examples)

* [Example in Python](#example-in-python)
* [Example in Powershell](#example-in-powershell)
* [Example in Postman / Insomnia](#example-in-postman-insomnia)

## Overview

What steps are needed to embed a report from a DataCentral tenant into a 3rd party application or website using the REST API endpoint provided by the DataCentral SaaS solution. This will involve sending a POST request to the API to receive an encrypted key, which will then be used to embed the report.

## Step 1: Setting up the API request

* **Endpoint:** <https://apim.datacentral.ai/dcai/encrypter>
* **Method:** POST
* **Required Querystring Parameter:** key=fd049aba32334c95a761abfd8b65723d

## Step 2: Constructing the POST payload

Prepare a JSON payload with the following structure:

```json
{ 
    "value": { 
        "userId": "<USER_ID>", 
        "reportId": "<REPORT_ID>", 
        "roleNames": ["Role1",”Role2”], 
        "expiration": "<OPTIONAL_EXPIRATION_DATETIME>" 
    }, 
    "passPhrase": "TenantSecrePhrase", 
    "tenancyName": "YourTenantName" 
} 
```

* Replace *\<USER\_ID>* with the customer's unique user ID (Kennitala) that will be the value of the DAX UserName() function.
* Set *\<REPORT\_ID>* should uniquely identify a report on website.
* Set *\<OPTIONAL\_EXPIRATION\_DATETIME>* with the desired expiration time for the session, example date-time format: "2025-12-18T20:22".&#x20;
* The *roleNames* is a comma separated list of role names to be applied to the model.&#x20;

The *passPhrase* can be found on your tenant under Settings-Security, see screenshot below:

<div align="left"><figure><img src="/files/j33D0x9DmQLPQaviNVCA" alt=""><figcaption></figcaption></figure></div>

## Step 3: Sending the request

* Use a server-side method to send the POST request to ensure security.
* The request should return a JSON object. If successful, you will receive a response in the following format:

```json
{ 
    "result": { 
        "key": "<ENCRYPTED_KEY>" 
    }, 
    "success": true, 
    "error": null 
} 
```

* Extract *\<ENCRYPTED\_KEY>* from the response for embedding the report.

## Step 4: Embedding the Power BI Report

* Replace *\<ENCRYPTED\_KEY>* with the key received from the API response.&#x20;
* Embed this URL in an iframe on the desired page of our website.&#x20;

Note in this example the value 1 is the report ID being displayed.&#x20;

See following picture.

<div align="left"><figure><img src="/files/P8DFcAr3TLiTDJyF3yKf" alt=""><figcaption></figcaption></figure></div>

## Security and best practices

* Ensure all API calls are made securely from the server-side to protect the API key and other sensitive data.&#x20;
* Validate and sanitize all inputs to prevent security vulnerabilities.&#x20;
* Test the implementation thoroughly to ensure the embedded report functions correctly and adheres to the specified role and expiration constraints.&#x20;

## Additional notes

* The *\<USER\_ID>* should uniquely identify a customer on website.&#x20;
* The *\<REPORT\_ID>* should uniquely identify a report on website.&#x20;
* The *roleNames* array can contain multiple roles if necessary. In this setup, it contains a single role: KennitalaRLS.&#x20;
* The *\<OPTIONAL\_EXPIRATION\_DATETIME>* parameter is optional but recommended to align with the duration of a login session for security reasons.&#x20;

## Examples

### Example in Python

```python
import requests 

from flask import Flask, render_template_string 

app = Flask(__name__) 

@app.route('/') 

def embed_power_bi_report(): 

    # API endpoint and payload 
    url = 'https://apim.datacentral.ai/dcai/encrypter?key=fd049aba32334c95a761abfd8b65723d' 

    payload = { 
        "value": { 
            "userId": "1809742969",  # Replace with dynamic user ID as needed 
         "reportId": "7",  # Replace with report ID  
            "roleNames": ["KennitalaRLS"], 
            "expiration": "2024-12-18T20:22"  # Adjust expiration as needed 
        }, 
        "passPhrase": "rhxsukgbw", 
        "tenancyName": "kort" 
    } 

    # Send POST request 

    response = requests.post(url, json=payload) 
    response_data = response.json() 

    # Extract encrypted key 
    encrypted_key = response_data['result']['key'] 

    # Construct iframe source URL 
    iframe_src = f"https://kort.demo.datacentral.ai/report/7?ev={encrypted_key}" 

   # HTML template with iframe 
    html_template = f""" 
    <html> 
    <head> 
        <title>Power BI Report</title> 
    </head> 
    <body> 
        <iframe src="{iframe_src}" width="800" height="600"></iframe> 
    </body> 
    </html> 
    """ 
    return render_template_string(html_template)  

if __name__ == '__main__': 
    app.run(debug=True) 
```

### Example in Powershell

```powershell
# Define the API endpoint and the payload 

$ApiEndpoint = "https://apim.datacentral.ai/dcai/encrypter?key=fd049aba32334c95a761abfd8b65723d" 

$Payload = @{ 
    value = @{ 
        userId = "1809742969"  # Replace with the actual user ID 
  	  reportId = "7"  # Replace with the actual user ID 
        roleNames = @("KennitalaRLS") 
        expiration = "2025-12-18T20:22"  # Adjust the expiration date as needed 
    } 
    passPhrase = "rhxsukgbw" 
    tenancyName = "kort" 
} 

# Convert the payload to JSON 
$JsonPayload = $Payload | ConvertTo-Json 
 
# Make the POST request 
$Response = Invoke-RestMethod -Uri $ApiEndpoint -Method Post -Body $JsonPayload -ContentType "application/json" 

# Extract the encrypted key from the response 
$EncryptedKey = $Response.result.key 

# Print the report URL with the encrypted key 
Write-Host "https://kort.demo.datacentral.ai/report/7?ev=$EncryptedKey" 
```

### Example in Postman / Insomnia

<figure><img src="/files/qrc1fyzd7NiVzapahu3D" alt=""><figcaption></figcaption></figure>
