Firestore REST API 与 appGyver Composer Pro 一起使用
Firestore REST API use with appGyver Composer Pro
我正在尝试使用 Google Firebase 的新 appGyver Composer Pro(没有成功)。 AppGyver 使用 REST API 获取数据库中的数据,但我无法让它工作。
数据库非常简单,只有两个文档,所以我使用 SoapUI 和 Postman 尝试不同的 uri 来确定如何设置 Composer Pro:
因此,使用 GET https://firestore.googleapis.com/v1/projects/{project}/databases/(default)/documents/{collection}/
这是请求的结果:
{"documents": [
{
"name": "projects/{project}/databases/(default)/documents/{collection}/{id}",
"fields": {
"Nombre": {"stringValue": "Cerros"},
"Resolucion": {"mapValue": {"fields": {
"Numero": {"stringValue": "22"},
"Entidad": {"stringValue": "Curaduria"},
"FechaResolucion": {"timestampValue": "2020-04-09T05:00:00Z"}
}}}
},
"createTime": "2020-04-10T13:11:35.364097Z",
"updateTime": "2020-04-10T13:11:35.364097Z"
},
{
"name": "projects/{project}/databases/(default)/documents/{collection}/{id}",
"fields": {
"Nombre": {"stringValue": "Urbanizacion Guayacanes"},
"Resolucion": {"mapValue": {"fields": {
"Numero": {"stringValue": "14"},
"Entidad": {"stringValue": "Municipio de Chinchina"},
"FechaResolucion": {"timestampValue": "2013-11-13T05:00:00Z"}
}}}
},
"createTime": "2020-04-09T14:29:09.633853Z",
"updateTime": "2020-04-09T14:29:09.633853Z"
}
]}
我明白了
{"error": {
"code": 400,
"message": "Invalid JSON payload received. Unknown name \"Nombre\": Cannot bind query parameter. Field 'Nombre' could not be found in request message.",
"status": "INVALID_ARGUMENT",
"details": [ {
"@type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [{"description": "Invalid JSON payload received. Unknown name \"Nombre\": Cannot bind query parameter. Field 'Nombre' could not be found in request message."}]
}]
}}
我使用以下任何一个而不是 ?Nombre=Cerros:
得到几乎相同的消息(只有字段名称发生变化)
- ?"Nombre"="Cerros"
- ?"documents.Nombre"="Cerros"
- ?"documents.fields.Nombre"="Cerros"
或者以前用过?以下任何一项:
- :runQuery
- 搜索
我做错了什么?
我真的很感激任何帮助
爱德华多
P.D。
我试过 REST API Explorer:
curl --request POST \
'https://firestore.googleapis.com/v1/projects/permisos-23395/databases/(default)/documents/Inmueble/:runQuery' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{"structuredQuery":{"select":{"fields":[{"fieldPath":"Nombre"},{"fieldPath":"matInm"}]},"from":[{"collectionId":"Inmueble","allDescendants":false}],"where":{"fieldFilter":{"field":{"fieldPath":"Nombre"},"op":"EQUAL","value":{"stringValue":"Cerros"}}}}}' \
--compressed
得到了
{
"error": {
"code": 400,
"message": "Invalid JSON payload received. Unknown name \"structuredQuery\" at 'document': Cannot find field.",
"status": "INVALID_ARGUMENT",
"details": [
{
"@type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"field": "document",
"description": "Invalid JSON payload received. Unknown name \"structuredQuery\" at 'document': Cannot find field."
}
]
}
]
}
}
您使用的端点用于列出集合的文档,而不是用于检索其内容。
当您调用 https://firestore.googleapis.com/v1/projects/{project}/databases/(default)/documents/{collection}/
时,您正在调用方法 projects.databases.documents.list,如您所见,returns 属于该集合的文档列表。
之后,您在指向列表端点时尝试使用查询参数检索与限制 "Nombre=Cierros" 匹配的文档,这不是有效请求。
如果您确实想要检索文档,则需要使用以下方法之一:
- 要请求单个文档,您需要使用方法 projects.databases.documents.get 和对端点
https://firestore.googleapis.com/v1/projects/{project_id}/databases/{database_id}/documents/{document_path}
的获取请求。其中文档路径的格式为 {collection}/{documentId}
.
- 要根据过滤器查询文档,您需要使用 projects.databases.documents.runQuery 方法以文档中描述的格式提供请求正文。
谢谢 Happy-Monad。我听从了您的指导并开始工作:
除默认索引外,还需要按{collection} {query field} 创建索引。
从来没有让它与 API EXPLORER 一起工作,因为它需要父路径上的集合 id,但是 :runQuery 如果它在那里就不起作用。
:使用 POST 调用(不是 GET)请求运行查询:https://firebase.google.com/docs/firestore/reference/rest#rest-resource:-v1.projects.databases.documents
有效的 curl 调用如下:
curl --request POST \
'https://firestore.googleapis.com/v1/projects/{database}/databases/(default)/documents:runQuery' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{"structuredQuery":{"select":{"fields":[{"fieldPath":"Nombre"},{"fieldPath":"nicInm"}]},"from":[{"collectionId":"{collection}","allDescendants":true}],"where":{"fieldFilter":{"field":{"fieldPath":"Nombre"},"op":"EQUAL","value":{"stringValue":"Cerros"}}}}}' \
--compressed
它returns (JSON):
array [1]
0 {2}
document {4}
name : projects/{database}/databases/(default)/documents/{collection}/{document id}
fields {2}
nicInm {1}
stringValue : 17-00-01-0001
nameInm {1}
stringValue : Cerros
createTime : 2020-04-14T15:22:53.782673Z
updateTime : 2020-04-14T15:22:53.782673Z
readTime : 2020-04-14T16:04:55.392601Z
我正在尝试使用 Google Firebase 的新 appGyver Composer Pro(没有成功)。 AppGyver 使用 REST API 获取数据库中的数据,但我无法让它工作。 数据库非常简单,只有两个文档,所以我使用 SoapUI 和 Postman 尝试不同的 uri 来确定如何设置 Composer Pro:
因此,使用 GET https://firestore.googleapis.com/v1/projects/{project}/databases/(default)/documents/{collection}/
这是请求的结果:
{"documents": [
{
"name": "projects/{project}/databases/(default)/documents/{collection}/{id}",
"fields": {
"Nombre": {"stringValue": "Cerros"},
"Resolucion": {"mapValue": {"fields": {
"Numero": {"stringValue": "22"},
"Entidad": {"stringValue": "Curaduria"},
"FechaResolucion": {"timestampValue": "2020-04-09T05:00:00Z"}
}}}
},
"createTime": "2020-04-10T13:11:35.364097Z",
"updateTime": "2020-04-10T13:11:35.364097Z"
},
{
"name": "projects/{project}/databases/(default)/documents/{collection}/{id}",
"fields": {
"Nombre": {"stringValue": "Urbanizacion Guayacanes"},
"Resolucion": {"mapValue": {"fields": {
"Numero": {"stringValue": "14"},
"Entidad": {"stringValue": "Municipio de Chinchina"},
"FechaResolucion": {"timestampValue": "2013-11-13T05:00:00Z"}
}}}
},
"createTime": "2020-04-09T14:29:09.633853Z",
"updateTime": "2020-04-09T14:29:09.633853Z"
}
]}
我明白了
{"error": {
"code": 400,
"message": "Invalid JSON payload received. Unknown name \"Nombre\": Cannot bind query parameter. Field 'Nombre' could not be found in request message.",
"status": "INVALID_ARGUMENT",
"details": [ {
"@type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [{"description": "Invalid JSON payload received. Unknown name \"Nombre\": Cannot bind query parameter. Field 'Nombre' could not be found in request message."}]
}]
}}
我使用以下任何一个而不是 ?Nombre=Cerros:
得到几乎相同的消息(只有字段名称发生变化)- ?"Nombre"="Cerros"
- ?"documents.Nombre"="Cerros"
- ?"documents.fields.Nombre"="Cerros"
或者以前用过?以下任何一项:
- :runQuery
- 搜索
我做错了什么? 我真的很感激任何帮助
爱德华多
P.D。 我试过 REST API Explorer:
curl --request POST \
'https://firestore.googleapis.com/v1/projects/permisos-23395/databases/(default)/documents/Inmueble/:runQuery' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{"structuredQuery":{"select":{"fields":[{"fieldPath":"Nombre"},{"fieldPath":"matInm"}]},"from":[{"collectionId":"Inmueble","allDescendants":false}],"where":{"fieldFilter":{"field":{"fieldPath":"Nombre"},"op":"EQUAL","value":{"stringValue":"Cerros"}}}}}' \
--compressed
得到了
{
"error": {
"code": 400,
"message": "Invalid JSON payload received. Unknown name \"structuredQuery\" at 'document': Cannot find field.",
"status": "INVALID_ARGUMENT",
"details": [
{
"@type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"field": "document",
"description": "Invalid JSON payload received. Unknown name \"structuredQuery\" at 'document': Cannot find field."
}
]
}
]
}
}
您使用的端点用于列出集合的文档,而不是用于检索其内容。
当您调用 https://firestore.googleapis.com/v1/projects/{project}/databases/(default)/documents/{collection}/
时,您正在调用方法 projects.databases.documents.list,如您所见,returns 属于该集合的文档列表。
之后,您在指向列表端点时尝试使用查询参数检索与限制 "Nombre=Cierros" 匹配的文档,这不是有效请求。
如果您确实想要检索文档,则需要使用以下方法之一:
- 要请求单个文档,您需要使用方法 projects.databases.documents.get 和对端点
https://firestore.googleapis.com/v1/projects/{project_id}/databases/{database_id}/documents/{document_path}
的获取请求。其中文档路径的格式为{collection}/{documentId}
. - 要根据过滤器查询文档,您需要使用 projects.databases.documents.runQuery 方法以文档中描述的格式提供请求正文。
谢谢 Happy-Monad。我听从了您的指导并开始工作:
除默认索引外,还需要按{collection} {query field} 创建索引。
从来没有让它与 API EXPLORER 一起工作,因为它需要父路径上的集合 id,但是 :runQuery 如果它在那里就不起作用。
:使用 POST 调用(不是 GET)请求运行查询:https://firebase.google.com/docs/firestore/reference/rest#rest-resource:-v1.projects.databases.documents
有效的 curl 调用如下:
curl --request POST \
'https://firestore.googleapis.com/v1/projects/{database}/databases/(default)/documents:runQuery' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{"structuredQuery":{"select":{"fields":[{"fieldPath":"Nombre"},{"fieldPath":"nicInm"}]},"from":[{"collectionId":"{collection}","allDescendants":true}],"where":{"fieldFilter":{"field":{"fieldPath":"Nombre"},"op":"EQUAL","value":{"stringValue":"Cerros"}}}}}' \
--compressed
它returns (JSON):
array [1]
0 {2}
document {4}
name : projects/{database}/databases/(default)/documents/{collection}/{document id}
fields {2}
nicInm {1}
stringValue : 17-00-01-0001
nameInm {1}
stringValue : Cerros
createTime : 2020-04-14T15:22:53.782673Z
updateTime : 2020-04-14T15:22:53.782673Z
readTime : 2020-04-14T16:04:55.392601Z