Embed Token - Generate Token
为多个报表、数据集和目标工作区生成嵌入令牌。
- 报表和数据集不必相关。
- 可以在嵌入过程中将报表绑定到数据集。
- 只能在
targetWorkspaces
参数指定的工作区中创建报表。
权限
- 使用服务主体进行身份验证时,请参阅 将 Power BI 内容嵌入服务主体,注意事项和限制。
- 对于具有分页视觉对象的 Power BI 报表,请在 API 调用中包含分页报表 ID。 有关详细信息,请参阅 示例。
- 此 API 调用可由服务主体配置文件调用。 有关详细信息,请参阅:Power BI Embedded中的服务主体配置文件。
所需范围
除非要求不适用,否则以下所有内容均不适用:
- 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 |
数据集列表 |
|
datasourceIdentities |
连接到启用了单 Sign-On(SSO)的数据源时要使用的标识列表。 |
|
identities |
用于行级别安全规则的标识列表 |
|
lifetimeInMinutes |
integer |
令牌的最大生存期(以分钟为单位),从生成令牌的时间开始。 可用于缩短令牌的过期时间,但不能将其延长。 该值必须是正整数。 零( |
reports |
报表列表 |
|
targetWorkspaces |
嵌入令牌允许保存到的工作区列表 |
响应
名称 | 类型 | 说明 |
---|---|---|
200 OK |
还行 |
示例
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"
}
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
示例请求
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"
}
定义
名称 | 说明 |
---|---|
Datasource |
|
Datasource |
用于连接已启用单一登录 (SSO) 的 DirectQuery 数据源的有效标识。 |
Datasource |
一个对象,该对象通过其连接详细信息唯一标识单个数据源。 |
Effective |
|
Embed |
Power BI 嵌入令牌 |
Generate |
Power BI 生成令牌请求 V2 |
Generate |
GenerateTokenRequestV2 中的数据集对象 |
Generate |
GenerateTokenRequestV2 中的报表对象 |
Generate |
GenerateTokenRequestV2 中的工作区对象 |
Identity |
用于指定标识的 Blob。 仅支持使用 DirectQuery 连接到 Azure SQL 的数据集 |
Xmla |
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 |
此标识应用于的数据源数组。 |
|
identityBlob |
string |
用于指定标识的 Blob。 |
DatasourceSelector
一个对象,该对象通过其连接详细信息唯一标识单个数据源。
名称 | 类型 | 说明 | |||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
connectionDetails |
数据源连接详细信息。 可以使用 获取分页报表的数据源获取连接详细信息,获取 powerbi 报表 API 的数据源。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||
datasourceType |
string |
|
EffectiveIdentity
定义用户标识和角色。 有关详细信息,请参阅使用 Power BI Embedded 行级别安全性。
名称 | 类型 | 说明 |
---|---|---|
auditableContext |
string |
EffectiveIdentity 可审核上下文。 如果提供此参数且不为空,它将启用 EffectiveIdentity 的审核,其值将设置为审核记录中的用户名。 否则,将从 GenerateToken 审核记录中省略 EffectiveIdentity 上下文。 |
customData |
string |
用于应用行级别安全规则的自定义数据。 仅支持实时连接到 Azure Analysis Services 模型和云模型。 |
datasets |
string[] |
此标识适用的数据集数组 |
identityBlob |
一个 blob,指定 标识。 仅支持使用 DirectQuery 连接到 Azure SQL 的数据集。 |
|
reports |
string[] |
此标识适用的报表数组。 仅支持分页报表。 |
roles |
string[] |
应用 RLS 规则的令牌中的行级安全性 (RLS) 角色数组。 标识最多可以包含 50 个角色。 角色可以包含除 |
username |
string |
应用行级安全规则的令牌中的有效用户名。 对于本地模型,用户名可以包含字母数字或任何以下字符 |
EmbedToken
Power BI 嵌入令牌
名称 | 类型 | 说明 |
---|---|---|
expiration |
string (date-time) |
令牌过期的日期和时间(UTC) |
token |
string |
嵌入令牌 |
tokenId |
string (uuid) |
唯一令牌 ID。 通过审核日志,令牌 ID 可用于将使用该令牌的作与生成作相关联。 |
GenerateTokenRequestV2
Power BI 生成令牌请求 V2
名称 | 类型 | 说明 |
---|---|---|
datasets |
数据集列表 |
|
datasourceIdentities |
连接到启用了单 Sign-On(SSO)的数据源时要使用的标识列表。 |
|
identities |
用于行级别安全规则的标识列表 |
|
lifetimeInMinutes |
integer |
令牌的最大生存期(以分钟为单位),从生成令牌的时间开始。 可用于缩短令牌的过期时间,但不能将其延长。 该值必须是正整数。 零( |
reports |
报表列表 |
|
targetWorkspaces |
嵌入令牌允许保存到的工作区列表 |
GenerateTokenRequestV2Dataset
GenerateTokenRequestV2 中的数据集对象
名称 | 类型 | 说明 |
---|---|---|
id |
string |
数据集 ID |
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 终结点的读取访问权限。 |