且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用REST API获取Azure API管理SKU

更新时间:2022-05-01 00:09:55

您在标头令牌中丢失了Bearer.

You lose Bearer in your header token.

-H "Authorization: Bearer $SAS"

此外,您使用的api是 Azure Rest API .令牌不是您由APIM Publisher门户生成的.您需要创建一个服务主体,然后使用它来获取令牌.例如:

Also, the api you used is a Azure Rest API. The token is not your generate by APIM Publisher portal. You need create a service principal, then use it to get token. For example:

TENANTID=""
APPID=""
PASSWORD=""
curl -X "POST" "https://login.microsoftonline.com/$TENANTID/oauth2/token" \
-H "Cookie: flight-uxoptin=true; stsservicecookie=ests; x-ms-gateway-slice=productionb; stsservicecookie=ests" \
-H "Content-Type: application/x-www-form-urlencoded" \
--data-urlencode "client_id=$APPID" \
--data-urlencode "grant_type=client_credentials" \
--data-urlencode "client_secret=$PASSWORD" \
--data-urlencode "resource=https://management.azure.com/"

获得令牌后,您可以使用API​​来获取sku.

After you get token, you could use API to get the sku.

curl -X "GET" "https://management.azure.com/subscriptions/*********/resourceGroups/shuiapi/providers/Microsoft.ApiManagement/service/shuiapi?api-version=2017-03-01" \
    -H "Authorization: Bearer $token" \
    -H "Content-Type: application/json"