Embed Token - Generate Token

为多个报表、数据集和目标工作区生成嵌入令牌。

  • 报表和数据集不必相关。
  • 可以在嵌入过程中将报表绑定到数据集。
  • 只能在 targetWorkspaces 参数指定的工作区中创建报表。

重要

此 API 调用仅适用于客户 方案的 嵌入。 若要了解有关使用此 API 的详细信息,请参阅生成嵌入令牌 时的注意事项。

权限

所需范围

除非要求不适用,否则以下所有内容均不适用:

  • Content.Create,如果在 GenerateTokenRequestV2中指定了目标工作区,则需要创建 。
  • 如果 GenerateTokenRequestV2中指定了报表,则需要 Report.ReadWrite.All 或 Report.Read.All。
  • Report.ReadWrite.All,如果 GenerateTokenRequestV2中至少为一个报表指定了 allowEdit 标志,则需要使用 Report.ReadWrite.All。
  • Dataset.ReadWrite.All 或 Dataset.Read.All

局限性

  • 只能在 targetWorkspaces 参数指定的工作区中创建报表。
  • 所有报表和数据集都必须驻留在 V2 工作区中。
  • 所有目标工作区都必须 V2 工作区。
  • 最多 50 个报表。
  • 最多 50 个数据集。
  • 最多 50 个目标工作区。
  • 对于 Azure Analysis Services 或 Analysis Services 本地实时连接报告,在重新绑定 后,生成具有行级安全性的嵌入令牌(RLS)可能无法工作几分钟。

POST https://api.powerbi.com/v1.0/myorg/GenerateToken

请求正文

名称 类型 说明
datasets

GenerateTokenRequestV2Dataset[]

数据集列表

datasourceIdentities

DatasourceIdentity[]

连接到启用了单 Sign-On(SSO)的数据源时要使用的标识列表。

identities

EffectiveIdentity[]

用于行级别安全规则的标识列表

lifetimeInMinutes

integer

令牌的最大生存期(以分钟为单位),从生成令牌的时间开始。 可用于缩短令牌的过期时间,但不能将其延长。 该值必须是正整数。 零(0)等效于 null,并将设置默认过期时间。

reports

GenerateTokenRequestV2Report[]

报表列表

targetWorkspaces

GenerateTokenRequestV2TargetWorkspace[]

嵌入令牌允许保存到的工作区列表

响应

名称 类型 说明
200 OK

EmbedToken

还行

示例

Example of generating an embed token for a dataset and two reports example. Only one of the reports can be edited.
Example of generating an embed token for a paginated report which has a Power BI dataset as a datasource. The ID of the dataset must be specified in the request. The report and dataset can each have its own identity
Example of generating an embed token for a paginated report with a data source identity
Example of generating an embed token for a paginated report with multiple data source identities and a single identity blob
Example of generating an embed token for a paginated report with multiple data source identities and multiple identity blobs
Example of generating an embed token for a Power BI report with a dataset which is connected with DirectQuery to another Power BI dataset. All related dataset IDs must be specified in the request with 'xmlaPermissions' set to 'ReadOnly'. IdentityBlobs for all SSO-enabled data sources must be provided in the 'datasourceIdentities' array
Example of generating an embed token for a Power BI report with a paginated visual. The paginated report ID ('...4850') of the paginated visual must be included in the 'reports' section of the request.
Example of generating an embed token for two datasets with RLS identities and a single report with read-only permissions. The embed token lets you view the report, which is dynamically bound to two different datasets.
Example of generating an embed token that expires no later than ten minutes from the API call

Example of generating an embed token for a dataset and two reports example. Only one of the reports can be edited.

示例请求

POST https://api.powerbi.com/v1.0/myorg/GenerateToken
{
  "datasets": [
    {
      "id": "cfafbeb1-8037-4d0c-896e-a46fb27ff229"
    }
  ],
  "reports": [
    {
      "allowEdit": true,
      "id": "b2e49b01-2356-4456-bfb9-3f4c2bc4ddbd"
    },
    {
      "id": "759908bb-ead8-4a43-9645-7ffbf921c68d"
    }
  ]
}

示例响应

{
  "token": "H4sI....AAA=",
  "tokenId": "49ae3742-54c0-4c29-af52-619ff93b5c80",
  "expiration": "2018-07-29T17:58:19Z"
}

Example of generating an embed token for a paginated report which has a Power BI dataset as a datasource. The ID of the dataset must be specified in the request. The report and dataset can each have its own identity

示例请求

POST https://api.powerbi.com/v1.0/myorg/GenerateToken
{
  "datasets": [
    {
      "id": "cfafbeb1-8037-4d0c-896e-a46fb27ff229",
      "xmlaPermissions": "ReadOnly"
    }
  ],
  "reports": [
    {
      "id": "b2e49b01-2356-4456-bfb9-3f4c2bc4ddbd"
    }
  ],
  "identities": [
    {
      "username": "john@contoso.com",
      "roles": [
        "sales"
      ],
      "datasets": [
        "cfafbeb1-8037-4d0c-896e-a46fb27ff229"
      ]
    },
    {
      "username": "john@contoso.com",
      "reports": [
        "b2e49b01-2356-4456-bfb9-3f4c2bc4ddbd"
      ]
    }
  ]
}

示例响应

{
  "token": "H4sI....AAA=",
  "tokenId": "49ae3742-54c0-4c29-af52-619ff93b5c80",
  "expiration": "2028-07-29T17:58:19Z"
}

Example of generating an embed token for a paginated report with a data source identity

示例请求

POST https://api.powerbi.com/v1.0/myorg/GenerateToken
{
  "reports": [
    {
      "id": "b2e49b01-2356-4456-bfb9-3f4c2bc4ddbd"
    }
  ],
  "datasourceIdentities": [
    {
      "datasources": [
        {
          "datasourceType": "Sql",
          "connectionDetails": {
            "server": "New-Sql-Server",
            "database": "New-Sql-Database"
          }
        }
      ],
      "identityBlob": "eyJ0eX....AAA="
    }
  ]
}

示例响应

{
  "token": "H4sI....AAA=",
  "tokenId": "49ae3742-54c0-4c29-af52-619ff93b5c80",
  "expiration": "2028-07-29T17:58:19Z"
}

Example of generating an embed token for a paginated report with multiple data source identities and a single identity blob

示例请求

POST https://api.powerbi.com/v1.0/myorg/GenerateToken
{
  "reports": [
    {
      "id": "b2e49b01-2356-4456-bfb9-3f4c2bc4ddbd"
    }
  ],
  "datasourceIdentities": [
    {
      "datasources": [
        {
          "datasourceType": "Sql",
          "connectionDetails": {
            "server": "New-Sql-Server",
            "database": "New-Sql-Database"
          }
        },
        {
          "datasourceType": "MySql",
          "connectionDetails": {
            "server": "New-MySql-Server",
            "database": "New-MySql-Database"
          }
        }
      ],
      "identityBlob": "eyJ0eX....AAA="
    }
  ]
}

示例响应

{
  "token": "H4sI....AAA=",
  "tokenId": "49ae3742-54c0-4c29-af52-619ff93b5c80",
  "expiration": "2028-07-29T17:58:19Z"
}

Example of generating an embed token for a paginated report with multiple data source identities and multiple identity blobs

示例请求

POST https://api.powerbi.com/v1.0/myorg/GenerateToken
{
  "reports": [
    {
      "id": "b2e49b01-2356-4456-bfb9-3f4c2bc4ddbd"
    }
  ],
  "datasourceIdentities": [
    {
      "datasources": [
        {
          "datasourceType": "Sql",
          "connectionDetails": {
            "server": "New-Sql-Server",
            "database": "New-Sql-Database"
          }
        }
      ],
      "identityBlob": "eyJ0eX....AAA="
    },
    {
      "datasources": [
        {
          "datasourceType": "MySql",
          "connectionDetails": {
            "server": "New-MySql-Server",
            "database": "New-MySql-Database"
          }
        }
      ],
      "identityBlob": "eyJ0dW....AAA="
    }
  ]
}

示例响应

{
  "token": "H4sI....AAA=",
  "tokenId": "49ae3742-54c0-4c29-af52-619ff93b5c80",
  "expiration": "2028-07-29T17:58:19Z"
}

示例请求

POST https://api.powerbi.com/v1.0/myorg/GenerateToken
{
  "datasets": [
    {
      "id": "b2e49b01-2356-4456-bfb9-3f4c2bc4ddbd",
      "xmlaPermissions": "ReadOnly"
    },
    {
      "id": "cfafbeb1-8037-4d0c-896e-a46fb27ff229",
      "xmlaPermissions": "ReadOnly"
    }
  ],
  "reports": [
    {
      "id": "f904e89a-7ebe-4aa0-8647-e409063b4850"
    }
  ],
  "datasourceIdentities": [
    {
      "datasources": [
        {
          "datasourceType": "Sql",
          "connectionDetails": {
            "server": "Best-Sql-Server",
            "database": "Database3"
          }
        }
      ],
      "identityBlob": "eyJ0eX....AAA="
    }
  ]
}

示例响应

{
  "token": "H4sI....AAA=",
  "tokenId": "ab4d49ae-c054-4c29-af52-93b5c80619ff",
  "expiration": "2022-06-10T12:41:11Z"
}

Example of generating an embed token for a Power BI report with a paginated visual. The paginated report ID ('...4850') of the paginated visual must be included in the 'reports' section of the request.

示例请求

POST https://api.powerbi.com/v1.0/myorg/GenerateToken
{
  "datasets": [
    {
      "id": "cfafbeb1-8037-4d0c-896e-a46fb27ff229"
    }
  ],
  "reports": [
    {
      "id": "b2e49b01-2356-4456-bfb9-3f4c2bc4ddbd"
    },
    {
      "id": "f904e89a-7ebe-4aa0-8647-e409063b4850"
    }
  ]
}

示例响应

{
  "token": "H4sI....AAA=",
  "tokenId": "49ae3742-54c0-4c29-af52-619ff93b5c80",
  "expiration": "2018-07-29T17:58:19Z"
}

Example of generating an embed token for two datasets with RLS identities and a single report with read-only permissions. The embed token lets you view the report, which is dynamically bound to two different datasets.

示例请求

POST https://api.powerbi.com/v1.0/myorg/GenerateToken
{
  "datasets": [
    {
      "id": "cfafbeb1-8037-4d0c-896e-a46fb27ff229"
    },
    {
      "id": "e75afc47-1150-45e0-aba7-4eb04e4876e5"
    }
  ],
  "reports": [
    {
      "id": "b2e49b01-2356-4456-bfb9-3f4c2bc4ddbd"
    }
  ],
  "identities": [
    {
      "username": "john@contoso.com",
      "roles": [
        "sales"
      ],
      "datasets": [
        "cfafbeb1-8037-4d0c-896e-a46fb27ff229"
      ]
    },
    {
      "username": "iris@contoso.com",
      "roles": [
        "executive"
      ],
      "datasets": [
        "e75afc47-1150-45e0-aba7-4eb04e4876e5"
      ]
    }
  ]
}

示例响应

{
  "token": "H4sI....AAA=",
  "tokenId": "4b76f5ed-5a06-4150-8d1b-60f8e4c186f4",
  "expiration": "2028-07-29T17:58:19Z"
}

Example of generating an embed token that expires no later than ten minutes from the API call

示例请求

POST https://api.powerbi.com/v1.0/myorg/GenerateToken
{
  "datasets": [
    {
      "id": "cfafbeb1-8037-4d0c-896e-a46fb27ff229"
    }
  ],
  "reports": [
    {
      "id": "b2e49b01-2356-4456-bfb9-3f4c2bc4ddbd"
    }
  ],
  "identities": [
    {
      "username": "john@contoso.com",
      "roles": [
        "sales"
      ],
      "datasets": [
        "cfafbeb1-8037-4d0c-896e-a46fb27ff229"
      ]
    }
  ],
  "lifetimeInMinutes": 10
}

示例响应

{
  "token": "H4sI....AAA=",
  "tokenId": "4b76f5ed-5a06-4150-8d1b-60f8e4c186f4",
  "expiration": "2028-07-29T17:58:19Z"
}

定义

名称 说明
DatasourceConnectionDetails

Power BI 数据源连接详细信息。 请参阅 获取数据源获取数据源的示例。

DatasourceIdentity

用于连接已启用单一登录 (SSO) 的 DirectQuery 数据源的有效标识。

DatasourceSelector

一个对象,该对象通过其连接详细信息唯一标识单个数据源。

EffectiveIdentity

定义用户标识和角色。 有关详细信息,请参阅使用 Power BI Embedded 行级别安全性。

EmbedToken

Power BI 嵌入令牌

GenerateTokenRequestV2

Power BI 生成令牌请求 V2

GenerateTokenRequestV2Dataset

GenerateTokenRequestV2 中的数据集对象

GenerateTokenRequestV2Report

GenerateTokenRequestV2 中的报表对象

GenerateTokenRequestV2TargetWorkspace

GenerateTokenRequestV2 中的工作区对象

IdentityBlob

用于指定标识的 Blob。 仅支持使用 DirectQuery 连接到 Azure SQL 的数据集

XmlaPermissions

XMLA 权限

DatasourceConnectionDetails

Power BI 数据源连接详细信息。 请参阅 获取数据源获取数据源的示例。

名称 类型 说明
account

string

连接帐户

classInfo

string

连接类信息

database

string

连接数据库

___domain

string

连接域

emailAddress

string

连接电子邮件地址

kind

string

连接类型

loginServer

string

连接登录服务器

path

string

连接路径

server

string

连接服务器

url

string

连接 URL

DatasourceIdentity

用于连接已启用单一登录 (SSO) 的 DirectQuery 数据源的有效标识。

名称 类型 说明
datasources

DatasourceSelector[]

此标识应用于的数据源数组。

identityBlob

string

用于指定标识的 Blob。

DatasourceSelector

一个对象,该对象通过其连接详细信息唯一标识单个数据源。

名称 类型 说明
connectionDetails

DatasourceConnectionDetails

数据源连接详细信息。 可以使用 获取分页报表的数据源获取连接详细信息获取 powerbi 报表 API 的数据源。

datasourceType

string

数据源 的类型。

数据源的 API 名称
ActiveDirectory AdobeAnalytics AdoDotNet
AnalysisServices AzureBlobs AzureDataLakeStorage
AzureMarketplace AzureTables BizTalk
CDPA CustomConnector CustomHttpApi
DB2 Essbase EventHub
Excel 交流 扩展
Facebook 文件 文件夹
GoogleAnalytics Hdfs HDInsight
Informix MQ MySql
OData ODBC OleDb
Oracle PostgreSql PowerQueryMashup
PubNub Salesforce SAPBW
SAPBWMessageServer SapErp SAPHana
SharePoint SharePointDocLib SharePointList
SQL Sybase Teradata
UIFlow 网络

EffectiveIdentity

定义用户标识和角色。 有关详细信息,请参阅使用 Power BI Embedded 行级别安全性。

名称 类型 说明
auditableContext

string

EffectiveIdentity 可审核上下文。 如果提供此参数且不为空,它将启用 EffectiveIdentity 的审核,其值将设置为审核记录中的用户名。 否则,将从 GenerateToken 审核记录中省略 EffectiveIdentity 上下文。

customData

string

用于应用行级别安全规则的自定义数据。 仅支持实时连接到 Azure Analysis Services 模型和云模型。

datasets

string[]

此标识适用的数据集数组

identityBlob

IdentityBlob

一个 blob,指定 标识。 仅支持使用 DirectQuery 连接到 Azure SQL 的数据集。

reports

string[]

此标识适用的报表数组。 仅支持分页报表。

roles

string[]

应用 RLS 规则的令牌中的行级安全性 (RLS) 角色数组。 标识最多可以包含 50 个角色。 角色可以包含除 ,以外的任何字符,其长度不得超过 50 个字符。

username

string

应用行级安全规则的令牌中的有效用户名。 对于本地模型,用户名可以包含字母数字或任何以下字符 .-_!#^~\\@。 对于云模型,用户名可以包含任何 ASCII 字符。 对于任一模型,用户名长度不得超过 256 个字符,用户名不应包含空格。

EmbedToken

Power BI 嵌入令牌

名称 类型 说明
expiration

string (date-time)

令牌过期的日期和时间(UTC)

token

string

嵌入令牌

tokenId

string (uuid)

唯一令牌 ID。 通过审核日志,令牌 ID 可用于将使用该令牌的作与生成作相关联。

GenerateTokenRequestV2

Power BI 生成令牌请求 V2

名称 类型 说明
datasets

GenerateTokenRequestV2Dataset[]

数据集列表

datasourceIdentities

DatasourceIdentity[]

连接到启用了单 Sign-On(SSO)的数据源时要使用的标识列表。

identities

EffectiveIdentity[]

用于行级别安全规则的标识列表

lifetimeInMinutes

integer

令牌的最大生存期(以分钟为单位),从生成令牌的时间开始。 可用于缩短令牌的过期时间,但不能将其延长。 该值必须是正整数。 零(0)等效于 null,并将设置默认过期时间。

reports

GenerateTokenRequestV2Report[]

报表列表

targetWorkspaces

GenerateTokenRequestV2TargetWorkspace[]

嵌入令牌允许保存到的工作区列表

GenerateTokenRequestV2Dataset

GenerateTokenRequestV2 中的数据集对象

名称 类型 说明
id

string

数据集 ID

xmlaPermissions

XmlaPermissions

XMLA 权限

GenerateTokenRequestV2Report

GenerateTokenRequestV2 中的报表对象

名称 类型 说明
allowEdit

boolean

生成的嵌入令牌是否支持报表编辑

id

string (uuid)

报表 ID

GenerateTokenRequestV2TargetWorkspace

GenerateTokenRequestV2 中的工作区对象

名称 类型 说明
id

string (uuid)

工作区 ID

IdentityBlob

用于指定标识的 Blob。 仅支持使用 DirectQuery 连接到 Azure SQL 的数据集

名称 类型 说明
value

string

Azure SQL 的 OAuth 2.0 访问令牌

XmlaPermissions

XMLA 权限

说明
Off

指示生成的嵌入令牌不会向数据集的 XMLA 终结点授予访问权限。

ReadOnly

指示生成的嵌入令牌授予对数据集的 XMLA 终结点的读取访问权限。