Fiware-Orion 3.7.0自动生成实体ID失败问题求助
Fiware-Orion 3.7.0自动生成实体ID报错解决
问题描述
在Fiware-Orion中提交多部智能手机的匿名报告时,希望系统自动生成实体ID,提交包含autoAssignId:true的POST请求后,返回错误:
{"error": "BadRequest", "description": "entity id length: 0, min length supported: 1"}
环境详情:
Uptime: 2 days, 7 hours, 13 minutes, 24 seconds Git Hash: 8b19705a8ec645ba1452cb97847a5615f0b2d3ca Compile Time: Thu May 26 11:45:49 UTC 2022 Compiled By: root Compiled In: 025d96e1419a Release Date: Thu May 26 11:45:49 UTC 2022 Machine: x86_64 Documentation: Fiware-Orion Documentation Library Versions: boost: 1_74 libcurl: libcurl/7.74.0 OpenSSL/1.1.1n zlib/1.2.11 brotli/1.0.9 libidn2/2.3.0 libpsl/0.21.0 (+libidn2/2.3.0) libssh2/1.9.0 nghttp2/1.43.0 librtmp/2.3 libmosquitto: 2.0.12 libmicrohttpd: 0.9.70 openssl: 1.1 rapidjson: 1.1.0 mongoc: 1.17.4 bson: 1.17.4
原请求示例:
POST /v2/entities HTTP/1.1 Content-Type: application/json { "type": "Complaint", "description": "Short description of the complaint", "creationDate": { "type": "DateTime", "value": "2023-07-26T12:34:56.789Z" }, "location": { "type": "geo:json", "value": { "type": "Point", "coordinates": [-46.73004, -23.55469] } }, "image": "SGVsbG8gV29ybGQh", "deviceId": "012edf4", "autoAssignId": true }
解决方案
Fiware-Orion 3.x版本中,autoAssignId的使用规则和旧版本不同,需修正两个核心问题:
- 参数位置错误:
autoAssignId不是实体属性,而是请求的URL查询参数,不能放在请求体的实体数据中。正确的请求URL应为:POST /v2/entities?autoAssignId=true - 请求体调整:请求体中不能保留错误的
autoAssignId字段,且无需手动填写id字段(系统会自动生成)。调整后的请求体如下:
{ "type": "Complaint", "description": "Short description of the complaint", "creationDate": { "type": "DateTime", "value": "2023-07-26T12:34:56.789Z" }, "location": { "type": "geo:json", "value": { "type": "Point", "coordinates": [-46.73004, -23.55469] } }, "image": "SGVsbG8gV29ybGQh", "deviceId": "012edf4" }
验证要点
发送请求时需确保:
- 请求方法为POST,路径为
/v2/entities - URL携带查询参数
autoAssignId=true - 请求体中无
id和autoAssignId字段 - 请求头
Content-Type设置为application/json
调整后,Orion会自动生成UUID格式的实体ID,并在响应的Location头中返回该ID的访问路径。
内容的提问来源于stack exchange,提问作者Vicente Orru
相关产品推荐
相关产品推荐

