Azure 監視器 Log Analytics API 錯誤

此節包含已知常見錯誤、其原因,以及可能解決方案的非詳盡清單。 其中還會包含成功的回應,這些回應通常表示要求問題 (例如缺少標頭) 或其他非預期的行為。

查詢語法錯誤

400 回應:

    {
        "error": {
            "message": "The request had some invalid properties",
            "code": "BadArgumentError",
            "innererror": {
                "code": "SyntaxError",
                "message": "Syntax Error"
            }
        }
    }

查詢字串的格式不正確。 檢查是否有額外的空格、標點符號或拼字錯誤。

未提供驗證

401 回應:

    {
        "error": {
            "code": "AuthenticationFailed",
            "message": "Authentication failed. The 'Authorization' header is missing."
        }
    }

在要求中包含驗證形式,例如標頭 "Authorization: Bearer \<token\>"

無效的驗證權杖

403 回應:

    {
        "error": {
            "code": "InvalidAuthenticationToken",
            "message": "The access token is invalid."
        }
    }

權杖的格式錯誤或無效。 如果您手動複製並貼上權杖,且將字元新增或剪下至承載,就可能會發生此錯誤。 請驗證權杖與從 Microsoft Entra ID 接收到的完全相同。

無效的權杖對象

403 回應:

    {
        "error": {
            "code": "InvalidAuthenticationTokenAudience",
            "message": "The access token has been obtained from wrong audience or resource 'https://api.loganalytics.io'. It should exactly match (including forward slash) with one of the allowed audiences 'https://management.core.windows.net/','https://management.azure.com/'."
        }
    }

如果您嘗試使用用戶端認證 OAuth2 流程來取得 API 的權杖,然後透過 Azure Resource Manager 端點使用該權杖,就會發生此錯誤。 如果您想要使用 Azure Resource Manager 端點,請使用其中一個指定的 URL 作為權杖要求中的資源。 或者,您可以使用直接 API 端點搭配不同的 OAuth2 流程進行授權。

直接 API 的用戶端認證

403 回應:

    {
        "error": {
            "message": "The provided credentials have insufficient access to perform the requested operation",
            "code": "InsufficientAccessError",
            "innererror": {
                "code": "UnauthorizedClient",
                "message": "The service principal does not have sufficient permissions to access this resource: 997631f8-3a55-4bb2-81b2-c0972b222260"
            }
        }
    }

如果您嘗試透過直接 API 端點使用用戶端認證,就可能會發生此錯誤。 如果您使用直接 API 端點,請使用不同的 OAuth2 流程進行授權。 如果您必須使用用戶端認證,請使用 Azure Resource Manager API 端點。

權限不足

403 回應:

    {
        "error": {
            "message": "The provided credentials have insufficient access to perform the requested operation",
            "code": "InsufficientAccessError"
        }
    }

您為授權出具的權杖,屬於對此權限沒有足夠存取權的使用者。 確認您的工作區 GUID 和權杖要求正確無誤。 如有必要,請將工作區中的 IAM 權限授與您建立為參與者的 Microsoft Entra 應用程式。

注意

使用 Microsoft Entra 驗證時,Application Insights REST API 辨識新的角色型存取控制權限最多可能需耗時 60 分鐘。 雖然權限正在傳播,但 REST API 呼叫可能會失敗,並顯示錯誤碼 403。

授權碼不正確

403 回應:

    {
        "error": "invalid_grant",
        "error_description": "AADSTS70002: Error validating credentials. AADSTS70008: The provided authorization code or refresh token is expired. Send a new interactive authorization request for this user and resource.",
        "error_codes": [
            70002,
            70008
        ]
    }

在權杖要求中提交的授權碼已過時或先前已用過。 透過 Microsoft Entra 授權端點重新授權以取得新代碼。

找不到路徑

404 回應:

    {
        "error": {
            "message": "The requested path does not exist",
            "code": "PathNotFoundError"
        }
    }

要求的查詢路徑不存在。 驗證您點閱的端點 URL 拼字正確,且您使用受支援的 HTTP 指令動詞。

缺少 JSON 或內容類型

200 回應:空白本文

如果您傳送的 POST 要求缺少 JSON 本文或 "Content-Type: application/json" 標頭,我們將傳回空的 200 回應。

工作區中沒有資料

204 回應:空白本文

如果工作區中沒有資料,我們會傳回「204 沒有內容」。