调用Android Management API设备操作接口时遇操作ID格式错误
Android Management API 400错误:操作ID格式无效问题解决
错误详情
{ "error": { "code": 400, "message": "Invalid operation id format. Choose a valid operation id.", "status": "INVALID_ARGUMENT" } }
你的请求命令
curl 'https://androidmanagement.googleapis.com/v1/enterprises/LC021x5h57/devices/36a36c5bdf986911/operations?key=[YOUR_API_KEY]' --header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' --header 'Accept: application/json' --compressed
问题原因
这个错误说明你的请求不符合API端点规则:
- 当前使用的
/enterprises/{enterpriseId}/devices/{deviceId}/operations是设备操作列表查询端点,GET请求时不需要指定操作ID,它会返回该设备下所有操作记录。 - 如果你的目标是查询单个操作的状态,应该使用操作资源的专属端点
/enterprises/{enterpriseId}/operations/{operationId},这个端点才需要传入合法的操作ID。
解决方案
分两种情况处理:
查询设备所有操作记录:
直接使用你当前的curl命令即可,确认API密钥和Bearer令牌有效,路径无拼写错误。查询单个操作状态:
修改请求路径为操作资源端点,替换[VALID_OPERATION_ID]为实际操作ID(操作ID是执行设备命令后API返回的name字段值,比如enterprises/LC021x5h57/operations/op_abc123,也可仅使用op_abc123部分):curl 'https://androidmanagement.googleapis.com/v1/enterprises/LC021x5h57/operations/[VALID_OPERATION_ID]?key=[YOUR_API_KEY]' --header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' --header 'Accept: application/json' --compressed
另外,检查是否误传了操作ID相关的查询参数,或路径中存在多余字符,这些也可能触发格式错误提示。
内容的提问来源于stack exchange,提问作者nileshkardate
相关产品推荐
相关产品推荐

