How to - getJSON post request , query with key

Hi,
I want to post this as Https request:

POST https://firestore.googleapis.com/v1beta1/projects/.../documents:runQuery?key={MY_API_KEY}
{ "structuredQuery": {  "select": {   "fields": [   ]  },  "from": [   {    "collectionId": "Instances"   }  ],  "where": {   "fieldFilter": {    "field": {     "fieldPath": "Occupied"    },    "op": "EQUAL",    "value": {     "stringValue": ""    }   }  },  "limit": 1 }}

I GET IN API EXPLORER A SUCCESS:

200 OK
  • Show headers -
{ "0": {  "document": {   "name": "projects/.../databases/(default)/documents/Instances/00cn9FErQYxGujvLjXy5",   "createTime": "2019-01-20T21:33:43.894843Z",   "updateTime": "2019-01-20T23:43:15.550880Z"  },  "readTime": "2019-01-23T00:17:22.240725Z" }}

But when posting using wix- getJson in backend:

getJSON(“https://firestore.googleapis.com/v1beta1/projects/.../databases/(default)/documents:runQuery?appid={MY_KEY}”,{ method: ‘post’ , headers: { ‘Content-Type’: ‘application/json’ }, body: {“structuredQuery”: {“select”: {“fields”: },“from”: [{“collectionId”: “Instances”}],“where”: {“fieldFilter”: {“field”: {“fieldPath”: “Occupied”},“op”: “EQUAL”,“value”: {“stringValue”: “”}}},“limit”: 1}}})

I don’t get anything. It looks like nothing happens. I don’t get any response event or there are late exception responses I can’t connect to that.

I could not find no good answers in your API documentation that show how to do it right.

Thanks beforehand
Shlomi

Hi Shlomi,
Instead of using getJSON, you should use the fetch API. Click here for further information about it.

Best,
Tal.

Thanks you Tal very much for you response.
Sure I have tried fetch and got the same results (since it very easy to just switch between them). The api you sent does not contain in its scope enough information. But I search the net and find some examples and I have some questions:

  • Is there a specific format I have to follow when adding a key parameter since I found ‘appid’ is required instead of ‘key’ in your DOCs to indicate the API key in the params
  • Should I JASON.stringify the ‘body’ of the message sent?
  • What should be the headers?
    I really need to figure it out since the Alternative in getting deep into Stripe… ):open_mouth:

Shlomi

Hi,
Thanks again, I just noticed that fetch API uses node fetch. I will check it.