Microsoft Fabric 数据管道公共 REST API(预览版)

重要

用于数据工厂的 Microsoft Fabric API 目前为公共预览版。 此信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 Microsoft 不对此处提供的信息作任何明示或默示的担保。

在 Microsoft Fabric 中,数据工厂 API 仅包含管道和数据流的 CRUD 操作。 当前,仅支持数据管道。 之后将会发布数据流 API。 数据集成项目其他常见领域均有独立的 API:日程安排、监视、连接,在 Fabric 中都有自己的 API。 可在 Microsoft Fabric REST API 参考中找到 Microsoft Fabric REST API 的主要联机参考文档。 另请参阅核心项 API 以及作业日程安排

装载公共 API

装载公共 API 现已提供。 通过这些 API,可在数据管道内无缝集成和访问各种公共数据源。

获取授权令牌

选项 1:使用 MSAL.Net

Fabric API 快速入门 - Microsoft Fabric REST API

使用 MSAL.Net 获取具有以下作用域的 Fabric 服务的 Microsoft Entra ID 令牌:Workspace.ReadWrite.All、Item.ReadWrite.All。 有关使用 MSAL.Net 获取令牌的详细信息,请参阅令牌获取 - 适用于 .NET 的 Microsoft 身份验证库

粘贴之前复制的应用程序(客户端)ID,并将其粘贴到 ClientId 变量。

选项 2:使用 Fabric 门户

登录到要测试的租户的 Fabric 门户,然后按 F12 进入浏览器的开发人员模式。 在控制台中运行以下内容:

powerBIAccessToken

复制令牌并将其粘贴到 ClientId 变量中。

有效负载 base64 编码的项定义

  • 使用 Base64 编码和解码对 JSON 进行编码。
  • 确保未选中“执行 URL 安全编码”复选框。
  • 可以通过 Fabric 用户界面中的“视图” - >查看 JSON 代码选项卡获取管道定义。
{ 
    "name": "Pipeline_1_updated", 
    "objectId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", 
    "properties": { 
        "description": "this is the description", 
        "activities": [ 
            { 
                "name": "Wait1", 
                "type": "Wait", 
                "dependsOn": [], 
                "typeProperties": { 
                    "waitTimeInSeconds": 240 
                } 
            } 
        ], 
        "annotations": [], 
        "lastModifiedByObjectId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", 
        "lastPublishTime": "2024-02-01T17:28:02Z" 
    } 
}

获取属性对象并将其括在大括号 - { } 中,因此 REST 项定义有效负载为:

{
    "properties": { 
        "description": "this is the description", 
        "activities": [ 
            { 
                "name": "Wait1", 
                "type": "Wait", 
                "dependsOn": [], 
                "typeProperties": { 
                    "waitTimeInSeconds": 240 
                } 
            } 
        ], 
        "annotations": [], 
        "lastModifiedByObjectId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", 
        "lastPublishTime": "2024-02-01T17:28:02Z" 
    } 
} 

创建项目

REST API - 项 - 创建项

示例 1 - CreateDataPipeline:

POST https://api.fabric.microsoft.com/v1/workspaces/<your WS Id>/items

正文:

{ 
  "displayName": "pipeline_1", 
  "type": "DataPipeline" 
} 

注意

按照文档的说法,只有 2 个必需的属性 - displayNametype。 目前,Workload-DI 不支持在没有定义的情况下创建。 目前正在部署此错误要求的修复。 你可以发送 Fabric 用户界面使用的相同默认定义:‘{"properties":{"activities":[]}}’

修改后的 JSON 包含定义:

{ 
  "displayName": "pipeline_1", 
  "type": "DataPipeline", 
  "definition": { 
    "parts": [ 
      { 
        "path": "pipeline-content.json", 
        "payload": "eyJwcm9wZXJ0aWVzIjp7ImFjdGl2aXRpZXMiOltdfX0=", 
        "payloadType": "InlineBase64" 
      } 
    ] 
  } 
} 

响应 201:

{ 
    "id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", 
    "type": "DataPipeline", 
    "displayName": "Pipeline_1", 
    "description": "", 
    "workspaceId": "<Your WS Id>" 
} 

示例 2 - 创建 MountedDataFactory

POST https://api.fabric.microsoft.com/v1/workspaces/<your WS Id>/items

正文:

有效负载:

{"DataFactoryResourceId":"/subscriptions/<ADF subscription Id>/resourceGroups/<ADF resource group name>/providers/Microsoft.DataFactory/factories/<ADF datafactory name>"} 

编码的 JSON:

{ 
  "displayName": "pipeline_mdf", 
  "type": " MountedDataFactory ", 
  "definition": { 
    "parts": [ 
      { 
        "path": "mountedDataFactory-content.json", 
        "payload": <base64 encoded value>, 
        "payloadType": "InlineBase64" 
      } 
    ] 
  } 
}  

响应 201:

{ 
    "id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", 
    "type": "MountedDataFactory", 
    "displayName": "Pipeline_mdf", 
    "description": "", 
    "workspaceId": "<Your WS Id>"
} 

删除物品

REST API - 项 - 删除项

示例:

DELETE https://api.fabric.microsoft.com/v1/workspaces/<your WS Id>/items/<pipeline id>

响应 200:(无正文)

获取项目

REST API - 项 - 获取项

示例:

GET https://api.fabric.microsoft.com/v1/workspaces/<your WS Id>/items/<pipeline id>

响应 200:

{ 
    "id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", 
    "type": "DataPipeline", 
    "displayName": "Pipeline_1", 
    "workspaceId": "<your WS Id>" 
} 

获取项定义

REST API - 项 - 获取项定义

示例:

POST https://api.fabric.microsoft.com/v1/workspaces/<your WS Id>/items/<pipeline id>/getDefinition

响应 200:

{ 
    "definition": { 
        "parts":[ 
            { 
                "path": "pipeline-content.json", 
                "payload": "ewogICJwcm9wZXJ0aWVzIjogewogICAgImFjdGl2aXRpZXMiOiBbXQogIH0KfQ==", 
                "payloadType": "InlineBase64" 
            } 
        ] 
    } 
} 

列出 项

REST API - 项 - 列表项

示例:

GET https://api.fabric.microsoft.com/v1/workspaces/<your WS Id>/items

响应 200:

{ 
    "value": [ 
        { 
            "id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", 
            "type": "SemanticModel", 
            "displayName": "deata_lh", 
            "description": "", 
            "workspaceId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" 
        }, 
        { 
            "id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", 
            "type": "SQLEndpoint", 
            "displayName": "deata_lh", 
            "description": "", 
            "workspaceId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" 
        }, 
        { 
            "id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", 
            "type": "Lakehouse", 
            "displayName": "deata_lh", 
            "description": "", 
            "workspaceId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" 
        }, 
        { 
            "id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", 
            "type": "DataPipeline", 
            "displayName": "Pipeline_1", 
            "description": "", 
            "workspaceId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" 
        } 
    ] 
} 

更新项目

REST API - 项 - 更新项

示例:

PATCH https://api.fabric.microsoft.com/v1/workspaces/<your WS Id>/items/<pipeline id>

正文:

{ 
  "displayName": "Pipeline_1_updated", 
  "description": "This is the description." 
}

响应 200:

{ 
    "id": "<pipeline id>", 
    "type": "DataPipeline", 
    "displayName": "Pipeline_1_updated", 
    "description": "This is the description.", 
    "workspaceId": "<Your WS id>" 
}

更新项定义

REST API - 项 - 更新项定义

示例:

POST https://api.fabric.microsoft.com/v1/workspaces/<your WS Id>/items/<pipeline id>/updateDefinition

正文:

{ 
  "definition": { 
    "parts": [ 
      { 
        "path": "pipeline-content.json", 
        "payload": "eyJwcm9wZXJ0aWVzIjp7ImFjdGl2aXRpZXMiOltdfX0=", 
        "payloadType": "InlineBase64" 
      } 
    ] 
  } 
}

响应 200:(无正文)

按需运行项作业

REST API - 项目 - 运行按需项作业

示例:

POST https://api.fabric.microsoft.com/v1/workspaces/<your WS Id>/items/<pipeline id>/jobs/instances?jobType=Pipeline

响应 202:(无正文)

包含两个参数值的示例:

此处有一个等待活动,其中包含用于指定要等待的秒数的名为 param_waitsec 的参数。

POST https://api.fabric.microsoft.com/v1/workspaces/<your WS Id>/items/<pipeline id>/jobs/instances?jobType=Pipeline

正文:

{ 
  "executionData": { 
    "parameters": {
      "param_waitsec": "10" 
    } 
  } 
}

响应 202:(无正文)

注意

当前没有返回的正文,但应返回作业 ID。 在预览期间,可以在返回的标头中找到它,位于“Location”属性中。

获取项作业实例

REST API - 项 - 获取项作业实例

示例:

GET https://api.fabric.microsoft.com/v1/workspaces/<your WS Id>/items/<pipeline id>/jobs/instances/<job ID>

响应 200:

{ 
    "id": "4511ffcd-a9f6-4f75-91a9-9ceab08d7539", 
    "itemId": "2bb9fe4a-0a84-4725-a01f-7ac4e6850259", 
    "jobType": "Pipeline", 
    "invokeType": "Manual", 
    "status": "Completed", 
    "failureReason": null, 
    "rootActivityId": "f14bdd95-2cff-4451-b839-bea81509126d", 
    "startTimeUtc": "2024-02-01T03:03:19.8361605", 
    "endTimeUtc": "2024-02-01T03:05:00.3433333" 
} 

取消项作业实例

REST API - 项 - 取消项作业实例

示例:

POST https://api.fabric.microsoft.com/v1/workspaces/<your WS Id>/items/<pipeline id>/jobs/instances/<job ID>/cancel

响应 202:(无正文)

注意

取消作业后,可以通过调用 Get 项作业实例或查看 Fabric 用户界面中的视图运行历史记录来检查状态。

查询活动运行

示例:

POST https://api.fabric.microsoft.com/v1/workspaces/<your WS Id>/datapipelines/pipelineruns/<job id>/queryactivityruns

正文:

{
  "filters":[],
  "orderBy":[{"orderBy":"ActivityRunStart","order":"DESC"}],
  "lastUpdatedAfter":"2024-05-22T14:02:04.1423888Z",
  "lastUpdatedBefore":"2024-05-24T13:21:27.738Z"
}

注意

“作业 ID”是在 Job Scheduler 公共 API 中创建和使用的相同 ID

响应 200:

[
    {
        "pipelineName": "ca91f97e-5bdd-4fe1-b39a-1f134f26a701",
        "pipelineRunId": "bbbb1b1b-cc2c-dd3d-ee4e-ffffff5f5f5f",
        "activityName": "Wait1",
        "activityType": "Wait",
        "activityRunId": "cccc2c2c-dd3d-ee4e-ff5f-aaaaaa6a6a6a",
        "linkedServiceName": "",
        "status": "Succeeded",
        "activityRunStart": "2024-05-23T13:43:03.6397566Z",
        "activityRunEnd": "2024-05-23T13:43:31.3906179Z",
        "durationInMs": 27750,
        "input": {
            "waitTimeInSeconds": 27
        },
        "output": {},
        "error": {
            "errorCode": "",
            "message": "",
            "failureType": "",
            "target": "Wait1",
            "details": ""
        },
        "retryAttempt": null,
        "iterationHash": "",
        "userProperties": {},
        "recoveryStatus": "None",
        "integrationRuntimeNames": null,
        "executionDetails": null,
        "id": "/SUBSCRIPTIONS/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/RESOURCEGROUPS/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/PROVIDERS/MICROSOFT.TRIDENT/WORKSPACES/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/pipelineruns/bbbb1b1b-cc2c-dd3d-ee4e-ffffff5f5f5f/activityruns/cccc2c2c-dd3d-ee4e-ff5f-aaaaaa6a6a6a"
    }
]

已知限制

  • 目前不支持服务主体身份验证 (SPN)。