Firestore REST API use with appGyver Composer Pro - rest

I´m trying the new appGyver Composer Pro with Google Firebase (without success). AppGyver uses REST API to get data on the database, but I can´t get it to work.
The database is very simple and has only two documents, so I´m using SoapUI and Postman to try differen uri´s to identify how to set Composer Pro:
So, using GET https://firestore.googleapis.com/v1/projects/{project}/databases/(default)/documents/{collection}/
This is the result of the request:
{"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"
}
]}
But if I use
https://firestore.googleapis.com/v1/projects/{project}/databases/(default)/documents/{collection}/?Nombre=Cerros
I get
{"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."}]
}]
}}
I get almost the same message (only the name of the field changes) using any of the following instead of ?Nombre=Cerros:
?"Nombre"="Cerros"
?"documents.Nombre"="Cerros"
?"documents.fields.Nombre"="Cerros"
Or using before ? any of the following:
:runQuery
search
What am I doing wrong?
I would really appreciate any help
Eduardo
P.D.
I tried on the 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
And got
{
"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."
}
]
}
]
}
}

The endpoint you're using is meant for listing the documents of a collection, not for retrieving it's contents.
When you call https://firestore.googleapis.com/v1/projects/{project}/databases/(default)/documents/{collection}/ you're calling the method projects.databases.documents.list which as you saw returns a list of the documents belonging to that collection.
Afterwards you're trying to retrieve the document matching the restriction "Nombre=Cierros" using query parameters while pointing to the list endpoint, which is not a valid request.
If you actually want to retrieve the documents you would need to use one of the following:
To request for a single document you need to use the method projects.databases.documents.get with a get request to the endpoint https://firestore.googleapis.com/v1/projects/{project_id}/databases/{database_id}/documents/{document_path}. Where document path would be of the form {collection}/{documentId}.
To query documents based on a filter you need to use the method projects.databases.documents.runQuery supplying a request body in the format described in the documentation.

Thanks Happy-Monad. I followed your lead and got it to work:
There needs to be an Index by {collection} {query field}, created in addition to the default ones.
Never got it to work with the API EXPLORER, because it needs the collection id on the parent path, but :runQuery does not work if its in there.
:runQuery is requested with a POST call (not GET): https://firebase.google.com/docs/firestore/reference/rest#rest-resource:-v1.projects.databases.documents
The curl call that worked is as follows:
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
It 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

Related

How can I use Google Apps Script in Unity? [duplicate]

This question is about receiving POST request from somewhere. I'm looking for a google sheet script function that can take and handle data from the POST request in JSON format. Could you suggest any example?
The POST request is here:
https://script.google.com/macros/s/BOdirjv45Dn6FHrx_4GUguuS6NJxnSEeviMHm3HerJl4UsDBnDgfFPO/
{
"p1": "writeTitle",
"p2": [[URL]],
"p3": [[PIC_A]],
"p4": [[PIC_B]],
"p5": [[TITLE]]
}
application/json
doPost() doesn't work:
doPost(e) {
var json = JSON.parse(e.postData.contents);
Logger.log(json);
}
You want to retrieve the value from the request body as an object.
You have already deployed Web Apps.
If my understanding of your situation is correct, how about this modification?
Post and retrieved object:
As a sample, I used the following curl command to POST to Web Apps.
curl -L \
-H 'Content-Type:application/json' \
-d '{"p1": "writeTitle","p2": "[[URL]]","p3": "[[PIC_A]]","p4": "[[PIC_B]]","p5": "[[TITLE]]"}' \
"https://script.google.com/macros/s/#####/exec"
When above command is run, e of doPost(e) is as follows.
{
"parameter": {},
"contextPath": "",
"contentLength": 90,
"queryString": "",
"parameters": {},
"postData": {
"type": "application/json",
"length": 90,
"contents": "{\"p1\": \"writeTitle\",\"p2\": \"[[URL]]\",\"p3\": \"[[PIC_A]]\",\"p4\": \"[[PIC_B]]\",\"p5\": \"[[TITLE]]\"}",
"name": "postData"
}
}
The posted payload can be retrieved by e.postData. From above response, it is found that the value you want can be retrieved by e.postData.contents. By the way, when the query parameter and the payload are given like as follows,
curl -L \
-H 'Content-Type:application/json' \
-d '{"p1": "writeTitle","p2": "[[URL]]","p3": "[[PIC_A]]","p4": "[[PIC_B]]","p5": "[[TITLE]]"}' \
"https://script.google.com/macros/s/#####/exec?key=value"
value can be retrieved by e.parameter or e.parameters. And the payload can be retrieved by e.postData.contents.
Modified script:
In this modified script, the result can be seen at the Stackdriver, and also the result is returned.
function doPost(e) {
var json = JSON.parse(e.postData.contents);
console.log(json);
return ContentService.createTextOutput(JSON.stringify(json));
}
Note:
When you modified your script of Web Apps, please redeploy it as new version. By this, the latest script is reflected to Web Apps. This is an important point.
Reference:
Web Apps
Stackdriver Logging
If this was not what you want, I'm sorry.

How can I create a pull request with github api?

The API is : /repos/{owner}/{repo}/pulls.
I used the correct token, and the request body is :
data = {
"base": "master",
"head": "owner:master",
"title": "title",
}
The head is like this:
{'Accept': 'application/vnd.github.v3+json', "Authorization": "token {}".format(git_token)}
Then I call the pull API. Returned 200.
<Response [200]>
Why? Maybe the request body wrong?
The Pull Request API specified the answer:
Status: 201 Created
Try and anddapt their example to your repository, to see if it does work:
curl \
-X POST \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world/pulls \
-d '{"head":"head","base":"base"}'

Facebook Messenger API Messenge Attachments example does not work

I have a problem with reproducing the second example https://developers.facebook.com/docs/messenger-platform/reference/attachment-upload-api#example_request
It is:
curl \
-F 'message={"attachment":{"type":"image", "payload":{"is_reusable":true}}}' \
-F 'filedata=#/tmp/shirt.png;type=image/png' \
"https://graph.facebook.com/v6.0/me/message_attachments?access_token=<PAGE_ACCESS_TOKEN>"
When I check the request with httpbin, I get:
{
"args": {},
"data": "",
"files": {
"filedata": ""
},
"form": {
"message": "{\"attachment\":{\"type\":\"image\", \"payload\":{\"is_reusable\"=true}}}",
"recipient": "{\"id\":\"2673203139464950\"}"
},
"headers": {
"Accept": "*/*",
"Content-Length": "474",
"Content-Type": "multipart/form-data; boundary=------------------------855a2be7cb07aa99",
"Host": "httpbin.org",
"User-Agent": "curl/7.58.0",
"X-Amzn-Trace-Id": "Root=1-5e71f6ce-edeb373f3e446e443e23f2e3"
},
"json": null,
"origin": "my.ip.ad.dr",
"url": "https://httpbin.org/post"
}
When I run it locally, I get
{
"error":{
"message":"(#100) Field message must be a valid json object with string keys",
"type":"OAuthException",
"code":100,
"fbtrace_id":"ABYTTCTcFg7DoXr8i8ySdJB"
}
}
My attempts to solve it by myself are unsuccessful, despite several days of effort.
I guess, the problem is really simple, but I need help.
By the way, in general I need python-requests way of uploading files to Facebook, thus, if I had one, I would not need curl solution.
Any help will be appreciated.
I was told to replace the equals sign with a colon and add backslashes, however, it does not seem to work:
$ curl \
> -F 'message:{\"attachment\":{\"type\":\"image\", \"payload\":{\"is_reusable\": true}}}' \
> -F 'filedata=#/tmp/shirt.png;type=image/png' \
> "https://graph.facebook.com/v6.0/me/message_attachments?access_token=<MY-TOKEN>"
Warning: Illegally formatted input field!
curl: option -F: is badly used here
You only want to replace the second equal sign with a colon, the one after is_reusable, otherwise the JSON you provide is not valid. The equal sign after message should stay, because it is required by curl. Check out the documentation for more details.
In your case you want to use the following:
-F 'message={"attachment":{"type":"image","payload":{"is_reusable":true}}}'

How to send a form with just 1 TextBox and 1 Button via Postman

I tried creating a request via postman with below Request Body with 1 input text,
{
"subject" : "Fill Up the Form",
"content" : "Form Data",
"formMetaData" : {
"id": "myform1234",
"controls": [{
"type": "Circuit.Enums.FormControlType.INPUT",
"name": "Your Name"
}]
}
}
But I am only getting the Content and Subject part in Circuit Sandbox. Form part is missing
Using the Rest API and not the SDK you should replace the ENUMS with strings for the control types.
I have a working code sample in Postman for this
curl -X POST \
https://beta.circuit.com/rest/v2/conversations/6aecff9e-1aa0-46f3-8e24-8519e2956291/messages \
-H 'Authorization: Bearer 11111omitted' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-F 'content=Please fill in the form below' \
-F 'subject=Test form' \
-F 'formMetaData={"id":"myformonbeta","title":"Test Form","controls":[{"type":"INPUT","name":"name","text":"What is your namne ?","rows":1},{"type":"BUTTON","text":"Send"}]}'
Hope this helps

RT request tracker Can't able to get the tickets for query in Rest 2.0

I tried to follow the RT REST Guide but i can't able to search tickets with query . Every time it is getting empty items . But i have tickets with all query and it is a valid token . All other api is working with this token
I used the command
curl -si http://rt-test.backbonesecure.com/rt/REST/2.0/tickets?token=1-115-31ee899218dfb70735c500cd0a878857 -XPOST --data-binary '[{"field":"Status","value":"open"}]'
curl -H "Content-Type: application/json" -d "#abc.txt" -X POST http://rt-test.backbonesecure.com/rt/REST/2.0/tickets?token=1-115-31ee899218dfb70735c500cd0a878857
abc.txt contains the json query
{
"Queue": "General",
"Status": "new"
"Priority":"0"
"Owner":"Nobody"
}
Does anyone have any advice?
I am having luck using a query string. I haven't tried with a JSON search.
Firstly, I am quite sure that you are misusing the authentication token. It should be put into the header like this. I would recommend you get a simple request working, like the queues/all example.
Here is the request that I send:
POST http://localhost/rt/REST/2.0/tickets
Authorization: token <REDACTED>
User-Agent: libwww-perl/6.15
Content-Type: application/x-www-form-urlencoded
query=subject = 'Test Subject';page=1
And the reponse back:
{
"total" : 1,
"count" : 1,
"page" : 1,
"items" : [
{
"type" : "ticket",
"id" : "1415",
"_url" : "http://localhost/rt/REST/2.0/ticket/1415"
}
],
"per_page" : 20
}