You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

能否通过REST API在Azure Analysis Service创建对象并执行TMSL脚本?

Can You Create Azure Analysis Services Objects via REST API?

Absolutely—you can use the Azure Analysis Services (AAS) REST API to execute TMSL (Tabular Model Scripting Language) scripts for creating databases, tables, partitions, and other model objects. The confusion around only supporting refresh/sync operations is common, but the Execute endpoint is designed specifically for running TMSL commands like your createOrReplace example.

How to Execute Your TMSL Script via REST API

Here's a breakdown of the steps and request structure:

  1. Use the Execute API Endpoint
    The core endpoint for running TMSL commands is:

    POST https://<your-aas-server-name>.asazure.windows.net/v1/models/<model-name>/execute
    

    Replace <your-aas-server-name> with your AAS server's name, and <model-name> with the target model (omit /models/<model-name> if you're targeting the server level, like creating a new database).

  2. Mandatory Request Headers
    You'll need these headers to authenticate and format the request:

    • Authorization: Bearer token from Azure AD authentication (obtainable via Azure CLI, PowerShell, or an app registration).
    • Content-Type: application/json
  3. Request Body (Your TMSL Script)
    Wrap your TMSL command in a JSON object with a commands array. Here's how your script would be structured for the API:

    {
      "commands": [
        {
          "createOrReplace": {
            "object": {
              "database": "AdventureWorksTabular1200",
              "table": "FactSalesQuota",
              "partition": "FactSalesQuota - 2011"
            },
            "partition": {
              "name": "Sales Quota for 2011",
              "mode": "import",
              "dataView": "full",
              "source": {
                "query": [
                  "SELECT [dbo].[FactSalesQuota].* FROM [dbo].[FactSalesQuota]",
                  "JOIN DimDate as DD",
                  "on DD.DateKey = FactSalesQuota.DateKey",
                  "WHERE DD.CalendarYear='2011'"
                ],
                "dataSource": "SqlServer localhost AdventureworksDW2016"
              }
            }
          }
        }
      ]
    }
    

Key Notes & Troubleshooting

  • Permissions: Ensure your user or service principal has the appropriate AAS roles (e.g., Server Administrator, Database Administrator) to modify model objects—without these, the API will return a permission error.
  • Asynchronous Execution: Schema-modifying TMSL commands (like creating partitions) often run asynchronously. The API response will include an operationId; use the GetOperationStatus endpoint to verify completion:
    GET https://<your-aas-server-name>.asazure.windows.net/v1/operations/<operationId>
    
  • Script Validation: Double-check your TMSL syntax (e.g., correct data source name, valid SQL query) before executing—any errors will be detailed in the operation status response.
  • Server-Level Operations: If you're creating a new database (not just objects within an existing one), use the server-level Execute endpoint instead:
    POST https://<your-aas-server-name>.asazure.windows.net/v1/execute
    

Why You Might Have Thought Only Refresh/Sync Was Supported

Refresh and sync operations are more prominently documented, but the Execute endpoint is the flexible tool for all TMSL-based tasks, including schema modifications like creating tables and partitions.

内容的提问来源于stack exchange,提问作者Khorshed Alam

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.08 20:42:52