"Power Platform" atsargų API

Atsargų API leidžia vykdyti struktūrizuotas užklausas "Azure Resource Graph" naudojant POST užklausą su užklausos specifikacija užklausos tekste. API išverčia jūsų užklausos specifikaciją į Kusto užklausų kalbą (KQL) vykdyti prieš Azure Resource Graph. Išteklių atsargų API yra "Power Platform" API informacinės dokumentacijos dalis. Išsamų išteklių tipų ir užklausų laukų sąrašą rasite "Power Platform" atsargų schemos nuorodoje.

API galinis punktas


POST {PowerPlatformAPI url}/resourcequery/resources/query?api-version=2024-10-01

Užklausos tekstas

Užklausos tekste turi būti tokios struktūros užklausos specifikacija:

Užklausos užklausos struktūra

{
  "TableName": "string",
  "Clauses": [
    {
      "$type": "clause_type",
      // clause-specific properties
    }
  ],
  "Options": {
    "Top": 100,
    "Skip": 0,
    "SkipToken": "string"
  }
}

Ypatybės

Ypatybė Tipas Būtina Aprašą
TableName eilutė Taip Užklausos paskirties lentelės / išteklių tipas (pvz., "PowerPlatformResources")
Clauses masyvas Taip Užklausos sąlygų masyvas, apibrėžiantis operacijas, kurias reikia atlikti
Options daiktas Ne "Azure Resource Graph" užklausos parinktys, skirtos puslapių sudarymui ir rezultatų valdymui

Užklausos parinktys

Objektas Options palaiko Azure Resource Graph užklausos parametrus, skirtus puslapių sudarymui ir rezultatų valdymui. Norėdami sužinoti daugiau, žiūrėkite ResourceQueryRequestOptions dokumentaciją .

Palaikomos užklausos sąlygos

API palaiko šiame skyriuje paryškintus sąlygų tipus per polimorfinį JSON serializavimą. Kiekvienas sakinio tipas atitinka KQL operatorius, kaip nurodyta KQL nuorodoje:

Kur sąlyga

Filtruoja duomenis pagal lauko sąlygas. Verčiama į KQL where operatorių.

{
  "$type": "where",
  "FieldName": "string",
  "Operator": "string",
  "Values": ["string1", "string2"]
}

Palaikomi operatoriai: API palaiko visus standartinius KQL palyginimo ir eilučių operatorius. Išsamų galimų operatorių sąrašą rasite KQL eilučių operatorių ir skaitmeninių operatorių dokumentacijoje.

Pavyzdys:

{
  "$type": "where",
  "FieldName": "type",
  "Operator": "in~",
  "Values": ["'microsoft.powerapps/canvasapps'", "'microsoft.copilotstudio/agents'"]
}

Verčiama į KQL:| where type in~ ('microsoft.powerapps/canvasapps', 'microsoft.copilotstudio/agents')

Projekto sąlyga

Iš rezultatų pasirenka konkrečius laukus. Verčiama į KQL project operatorių.

{
  "$type": "project",
  "FieldList": ["field1", "field2", "field3"]
}

Pavyzdys:

{
  "$type": "project",
  "FieldList": [
    "name", 
    "properties.displayName", 
    "environmentId = tostring(properties.environmentId)",
    "createdDate = properties.createdAt"
  ]
}

Verčiama į KQL:| project name, properties.displayName, environmentId = tostring(properties.environmentId), createdDate = properties.createdAt

Paimkite sąlygą

Riboja grąžinamų rezultatų skaičių. Verčiama į KQL take operatorių.

{
  "$type": "take",
  "TakeCount": 50
}

Verčiama į KQL:| take 50

Tvarka pagal sąlygą

Rūšiuoja rezultatus pagal nurodytus laukus. Verčiama į KQL sort operatorių.


{
  "$type": "orderby",
  "FieldNamesAscDesc": {
    "field1": "asc",
    "field2": "desc"
  }
}

Pavyzdys:

{
  "$type": "orderby",
  "FieldNamesAscDesc": {
    "tostring(properties.createdAt)": "desc",
    "properties.displayName": "asc"
  }
}

Verčiama į KQL:| sort by tostring(properties.createdAt) desc, properties.displayName asc

Atskira sąlyga

Pateikia unikalias nurodytų laukų reikšmes. Verčiama į KQL distinct operatorių.


{
  "$type": "distinct",
  "FieldList": ["field1", "field2"]
}

Verčiama į KQL:| distinct field1, field2

Skaičiavimo sąlyga

Pateikia atitinkančių įrašų skaičių. Verčiama į KQL count operatorių.

{
  "$type": "count"
}

Verčiama į KQL:| count

Apibendrinimo sąlyga

Agreguoja duomenis naudojant skaičiavimo arba argmax operacijas. Verčiama į KQL summarize operatorių.

{
  "$type": "summarize",
  "SummarizeClauseExpression": {
    "OperatorName": "count|argmax",
    "OperatorFieldName": "string",
    "FieldList": ["field1", "field2"]
  }
}

Palaikomi operatoriai:

  • countcount() – skaičiuoti įrašus, sugrupuotus pagal nurodytus laukus.
  • argmaxarg_max() – gaukite įrašus su didžiausia reikšme nurodytame lauke.

Skaičiavimo pavyzdys:

{
  "$type": "summarize",
  "SummarizeClauseExpression": {
    "OperatorName": "count",
    "OperatorFieldName": "resourceCount",
    "FieldList": ["resourceGroup", "type"]
  }
}

Verčiama į KQL:| summarize resourceCount = count() by resourceGroup, type

ArgMax pavyzdys:

{
  "$type": "summarize",
  "SummarizeClauseExpression": {
    "OperatorName": "argmax",
    "OperatorFieldName": "createdTime",
    "FieldList": ["resourceGroup"]
  }
}

Verčiama į KQL:| summarize arg_max(createdTime, *) by resourceGroup

Išplėsti sąlygą

Į rezultatus įtraukia apskaičiuotus stulpelius. Verčiama į KQL extend operatorių.

{
  "$type": "extend",
  "FieldName": "newFieldName",
  "Expression": "KQL_EXPRESSION"
}

Pavyzdys:

{
  "$type": "extend",
  "FieldName": "environmentId",
  "Expression": "tostring(properties.environmentId)"
}

Verčiama į KQL:| extend environmentId = tostring(properties.environmentId)https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/scalarfunctions) turimoms funkcijoms.

Prisijungimo sąlyga

Jungiasi su kita lentele / antrine užklausa. Verčiama į KQL join operatorių.


{
  "$type": "join",
  "RightTable": {
    "TableName": "string",
    "Clauses": []
  },
  "JoinKind": "string",
    "LeftColumnName": "string",
  "RightColumnName": "string"
}

Palaikomos sujungimo rūšys: API palaiko visus KQL prisijungimo tipus. Išsamų galimų sujungimo tipų sąrašą ir jų elgseną rasite KQL prisijungimo operatoriaus dokumentacijoje.

Pavyzdys ("Power Platform" išteklių sujungimas su aplinkos informacija):

{
  "$type": "join",
  "JoinKind": "leftouter",
  "RightTable": {
    "TableName": "PowerPlatformResources",
    "Clauses": [
      {
        "$type": "where",
        "FieldName": "type",
        "Operator": "==",
        "Values": ["'microsoft.powerplatform/environments'"]
      },
      {
        "$type": "project",
        "FieldList": [
          "environmentId = name",
          "environmentName = properties.displayName",
          "environmentRegion = location",
          "environmentType = properties.environmentType",
          "isManagedEnvironment = properties.isManaged"
        ]
      }
    ]
  },
  "LeftColumnName": "environmentId",
  "RightColumnName": "environmentId"
}

Verčiama į KQL:| join kind=leftouter (PowerPlatformResources | where type == 'microsoft.powerplatform/environments' | project environmentId = name, environmentName = properties.displayName, environmentRegion = location, environmentType = properties.environmentType, isManagedEnvironment = properties.isManaged) on $left.environmentId == $right.environmentId

Išsamūs užklausų pavyzdžiai

Pavyzdys: pagrindinė "Power Platform" išteklių užklausa ("Power Platform" administravimo centro numatytasis šablonas)

Gaukite visus "Power Platform" išteklius su aplinkos informacija – tai numatytoji užklausa, kurią naudoja "Power Platform" administravimo centras.

{
  "Options": {
    "Top": 1000,
    "Skip": 0,
    "SkipToken": ""
  },
  "TableName": "PowerPlatformResources",
  "Clauses": [
    {
      "$type": "extend",
      "FieldName": "joinKey",
      "Expression": "tolower(tostring(properties.environmentId))"
    },
    {
      "$type": "join",
      "JoinKind": "leftouter",
      "RightTable": {
        "TableName": "PowerPlatformResources",
        "Clauses": [
          {
            "$type": "where",
            "FieldName": "type",
            "Operator": "==",
            "Values": ["'microsoft.powerplatform/environments'"]
          },
            {
            "$type": "project",
            "FieldList": [
              "joinKey = tolower(name)",
              "environmentName = properties.displayName",
              "environmentRegion = location",
              "environmentType = properties.environmentType",
              "isManagedEnvironment = properties.isManaged"
            ]
          }
        ]
      },
      "LeftColumnName": "joinKey",
      "RightColumnName": "joinKey"
    },
    {
      "$type": "where",
      "FieldName": "type",
      "Operator": "in~",
      "Values": [
        "'microsoft.powerapps/canvasapps'",
        "'microsoft.powerapps/modeldrivenapps'",
        "'microsoft.powerautomate/cloudflows'",
        "'microsoft.copilotstudio/agents'",
        "'microsoft.powerautomate/agentflows'",
        "'microsoft.powerapps/codeapps'"
      ]
    },
    {
      "$type": "orderby",
      "FieldNamesAscDesc": {
        "tostring(properties.createdAt)": "desc"
      }
    }
  ]
}

Lygiavertis KQL:

PowerPlatformResources
| extend joinKey = tolower(tostring(properties.environmentId))
| join kind=leftouter (
    PowerPlatformResources
    | where type == 'microsoft.powerplatform/environments'
    | project joinKey = tolower(name), environmentName = properties.displayName, environmentRegion = location, environmentType = properties.environmentType, isManagedEnvironment = properties.isManaged
  ) on $left.joinKey == $right.joinKey
| where type in~ ('microsoft.powerapps/canvasapps', 'microsoft.powerapps/modeldrivenapps', 'microsoft.powerautomate/cloudflows', 'microsoft.copilotstudio/agents', 'microsoft.powerautomate/agentflows', 'microsoft.powerapps/codeapps')
| order by tostring(properties.createdAt) desc

Pavyzdys: "Power Platform" išteklių skaičiavimas pagal tipą ir vietą

{
  "TableName": "PowerPlatformResources",
  "Clauses": [
    {
      "$type": "summarize",
      "SummarizeClauseExpression": {
        "OperatorName": "count",
        "OperatorFieldName": "resourceCount",
        "FieldList": ["type", "location"]
      }
    },
    {
      "$type": "orderby",
      "FieldNamesAscDesc": {
        "resourceCount": "desc"
      }
    }
  ]
}

Lygiavertis KQL:

PowerPlatformResources
| summarize resourceCount = count() by type, location
| sort by resourceCount desc

Pavyzdys: paprasta drobės programų užklausa

Gaukite drobės programas su pagrindiniu filtravimu ir projekcija:

{
  "TableName": "PowerPlatformResources",
  "Clauses": [
    {
      "$type": "where",
      "FieldName": "type",
      "Operator": "==",
      "Values": ["'microsoft.powerapps/canvasapps'"]
    },
    {
      "$type": "project",
      "FieldList": [
        "name",
        "location",
        "properties.displayName",
        "properties.createdAt",
        "properties.environmentId"
      ]
    },
    {
      "$type": "take",
      "TakeCount": 100
    }
  ]
}

Lygiavertis KQL:

PowerPlatformResources
| where type == 'microsoft.powerapps/canvasapps'
| project name, location, properties.displayName, properties.createdAt, properties.environmentId
| take 100

Pavyzdys: išteklių filtravimas pagal aplinką ir dienų seką

{
  "TableName": "PowerPlatformResources",
  "Clauses": [
    {
      "$type": "where",
      "FieldName": "type",
      "Operator": "==",
      "Values": ["'microsoft.powerapps/canvasapps'"]
    },
    {
      "$type": "where",
      "FieldName": "properties.environmentId",
      "Operator": "==",
      "Values": ["your-environment-id"]
    },
    {
      "$type": "extend",
      "FieldName": "createdDate",
      "Expression": "todatetime(properties.createdAt)"
    },
    {
      "$type": "where",
      "FieldName": "createdDate",
      "Operator": ">=",
      "Values": ["datetime(2024-01-01)"]
    },
    {
      "$type": "project",
      "FieldList": [
        "name",
        "properties.displayName",
        "properties.createdAt",
        "properties.createdBy",
        "properties.ownerId"
      ]
    },
    {
      "$type": "orderby",
      "FieldNamesAscDesc": {
        "createdDate": "desc"
      }
    }
  ]
}

Verčiama į KQL:

PowerPlatformResources
| where type == 'microsoft.powerapps/canvasapps'
| where properties.environmentId == "your-environment-id"
| extend createdDate = todatetime(properties.createdAt)
| where createdDate >= datetime(2024-01-01)
| project name, properties.displayName, properties.createdAt, properties.createdBy, properties.ownerId
| sort by createdDate desc

Atsakymo formatas

API pateikia objektą ResourceQueryResult iš Azure Resource Graph SDK. Šiame objekte yra užklausos rezultatai ir metaduomenys apie užklausos vykdymą.

Atsakymo struktūra:

{
  "totalRecords": 1250,
  "count": 50,
  "resultTruncated": 1,
  "skipToken": "string_for_next_page",
  "data": [
    // Array of result objects based on your query
  ]
}