我正在尝试在流程中使用图形 API 调用,该调用将在创建新用户时分配许可证。我正在尝试构建许可证分配,但收到错误
"error": { "code": "Request_BadRequest", "message": "Specified HTTP method is not allowed for the request target.",
我不确定什么是不正确的。我正在使用的应用程序对目录和用户都有 ReadWrite.All 权限。这是完整的 JSON 输出和输入。
有什么想法吗?
输入:
{
"uri": "https://graph.microsoft.com/v1.0/users/67a9cbf3-d55b-47b3-b0d2-be1ba01f683d/assignedLicenses",
"method": "POST",
"authentication": {
"authority": "https://login.microsoftonline.com",
"tenant": "Tenant ID",
"audience": "https://graph.microsoft.com",
"clientId": "Secret ID",
"secret": "*sanitized*",
"type": "ActiveDirectoryOAuth"
},
"body": {
"addLicenses": [
{
"disabledPlans": [],
"skuId": "f30db892-07e9-47e9-837c-80727f46fd3d"
},
{
"disabledPlans": [],
"skuId": ""
}
],
"removeLicenses": []
}
}
输出:
{
"statusCode": 405,
"headers": {
"Cache-Control": "no-cache",
"Transfer-Encoding": "chunked",
"Vary": "Accept-Encoding",
"Strict-Transport-Security": "max-age=31536000",
"request-id": "fe8722cd-c0ab-462b-aa01-4271924efb28",
"client-request-id": "fe8722cd-c0ab-462b-aa01-4271924efb28",
"x-ms-ags-diagnostic": "{\"ServerInfo\":{\"DataCenter\":\"West US\",\"Slice\":\"E\",\"Ring\":\"4\",\"ScaleUnit\":\"001\",\"RoleInstance\":\"BY1PEPF00003AA0\"}}",
"x-ms-resource-unit": "1",
"Date": "Thu, 09 May 2024 20:25:32 GMT",
"Content-Type": "application/json",
"Content-Length": "267"
},
"body": {
"error": {
"code": "Request_BadRequest",
"message": "Specified HTTP method is not allowed for the request target.",
"innerError": {
"date": "2024-05-09T20:25:33",
"request-id": "fe8722cd-c0ab-462b-aa01-4271924efb28",
"client-request-id": "fe8722cd-c0ab-462b-aa01-4271924efb28"
}
}
}
}
我希望将许可证分配给用户,但我收到 Request_BadRequest 错误
您调用了错误的端点
"uri": "https://graph.microsoft.com/v1.0/users/{user_id}/assignedLicenses",
正确的是
https://graph.microsoft.com/v1.0/users/{user_id}/assignLicense
"uri": "https://graph.microsoft.com/v1.0/users/{user_id}/assignLicense",
https://learn.microsoft.com/graph/api/user-assignlicense?view=graph-rest-1.0&tabs=http