"Unexpected token } in JSON" (Firestore connecting through Zapier) - firebase

Attempting to hook up a trigger from Zapier when a Firestore document gets added, Zapier asks for an orderBy element. Documentation (https://zapier.com/help/firebase/#creating-a-firestore-structured-query-for-a-trigger) seems pretty straightforward, but I get an error that
ERROR: We had trouble finding a sample. The specified query does not contain valid JSON. Unexpected token } in JSON at position 123
I tried a couple of variations (see below for 2 examples), but I keep getting the same error each with a different position.
"orderBy": [{
"field": {
"fieldPath": "timestamp"
},
"direction": "DESCENDING"
}],
(Result: Position 123)
"orderBy": [{
"field": "timestamp,
"direction": "DESCENDING"
}],
(Result: Position 46)
I'm not even sure where Zapier is getting the JSON, so I can't look at the JSON to see if anything is funky.
Does anyone know how to fix, or at least how to view the full JSON file?

The issue is the trailing comma after the last ], which makes it invalid JSON.

Actually it's this one trailing comma, which renders the query invalid: ]},} - that should be ]}}.
The full JSON can usually be downloaded in the Firebase console; at least for Realtime Database.
And when it complains about JSON syntax, just use JSONLint; most IDE also highlight syntax errors.

According to Zapier documentation:
"orderBy": [{
"field": {
"fieldPath": "someKeyOfYourChoice"
},
"direction": "DESCENDING"
}]
This worked for me. There are more cases of troubleshooting, I highly suggest to check the site out if you still experiencing some issues:
https://zapier.com/help/doc/common-problems-firebase#creating-a-firestore-structured-query-for-a-trigger

Related

Firestore Pagination : how to set Cursor for startAt using Rest Api

I'm using firebase firestore using Rest API to get data limited by 5 documents only, ordered by a field called LikesCount.
When I want to fetch the next 5 documents I have to use startAt and pass the LikesCount value of the last document from the first 5 documents.
But in this way, it will fetch wrong data when there is another document with the same LikesCount value So I tried and searched a lot about how to pass the last Document id in addition to the LikesCount value But all of them did not work In addition, I tested the pagination using the Web SDK and it was working correctly because you can pass the document snapshot easily, but what does the document snapshot object include? So that we can understand the structure of the Cursor and apply it to the REST API.
I tried to use this method to pass the Document ID as referenceValue
{
"structuredQuery": {
"from": [{
"collectionId": "Users"
}],
"where": {
"compositeFilter": {
"op": "AND",
"filters": []
}
},
"orderBy": [{
"field": {
"fieldPath": "LikesCount"
},
"direction": "DESCENDING"
}],
"startAt":
{ "values": [
{
"integerValue": "6"
},
{
"referenceValue": "projects/myprojectid/databases/(default)/documents/Posts/xEvmJ1LLHwTKVREQfXtX"
}
],
"before": false
},
"limit":5
}
}
But an error will occur : Cursor has too many values.
also, I tried to pass only the referenceValue and it still did not return the correct 5 documents.
Thanks in advance :)
Your orderBy() has 1 field (LikesCount) but your startAt() has 2 fields. I suspect that is the reason for the error message?
Passing the integerValue won't work. If there are 13 results with the value 6, then each time you make the above call you'd get the same first 5 results.
When you say:
I tried only passing the referenceValue and still did not get the correct 5 documents
what documents are you getting? What documents were you expecting to get?

Fetch company posts from linkedin API

I am trying to fetch the posts of the company from the api, I have already applied to the marketing development platform and it was approved. I already got the token with the scope: r_organization_social and I'm calling the /shares api:
https://api.linkedin.com/v2/shares?q=owners&owners=urn:li:organization:{company_ID}&sharesPerOwner=100&count=25&sharesPerOwner=10
But I'm getting the following response:
{
"paging": {
"start": 0,
"count": 25,
"links": [
{
"type": "application/json",
"rel": "next",
"href": "/v2/shares?count=25&owners=urn%3Ali%3Aorganization%3A{company_ID}&q=owners&sharesPerOwner=10&sharesPerOwner=100&start=0"
}
],
"total": 242
},
"elements": []
}
I tried to change the query params and it's still the same
This end-point worked for me:
https://api.linkedin.com/v2/ugcPosts?q=authors&authors=List(urn%3Ali%3Aorganization%3A<ID_ORGANIZATION>)
See documentation: https://learn.microsoft.com/en-us/linkedin/marketing/integrations/community-management/shares/ugc-post-api?tabs=http#sample-request-6
Disclaimer: I've no access to the linkedin API and couldn't test. But these are some things I noticed:
Your url contains two times the paramater sharesPerOwner, try removing one.
In the docs it's recommended to set the sharesPerOwner to 1000 and the count to 50. I'd also include the start paramater, just to make sure:
Maybe try something like this:
GET https://api.linkedin.com/v2/shares?q=owners&owners=urn:li:organization:{id}&sharesPerOwner=1000&count=50&start=0
From the api-docs(https://learn.microsoft.com/en-us/linkedin/marketing/integrations/community-management/shares/share-api?tabs=http#find-shares-by-owner): "Note that the pagination excludes UGC and Direct Sponsored Content (DSC) posts". Make sure that the owner you are testing contains posts.
If this doesn't work. Could you provide some information on how you are sending the request? Have you tried accessing other parts of the api?

Field SCREEN_VIEW is not a valid dimension

I'm using firebase analytics with my android app.
I followed this article https://firebase.google.com/docs/analytics/screenviews?hl=en and now I'm tracking screens manually.
As you can see below it's working
Now I try to retrieve this data with the runReport-method https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1alpha/TopLevel/runReport as follows
{
"dimensions": [{
"name": "screen_view"
},
{
"name": "firebase_screen"
}
],
"metrics": [{
"name": "myMetric?"
}]
}
I get the return message
Field screen_view is not a valid dimension
I don't know what I'm doing wrong.
Here's your reference of all the dimensions and APIs you can use: https://developers.google.com/analytics/devguides/reporting/data/v1/api-schema
I think what you're having issues with is that the "screen_view" dimension doesn't exist. This is because if you go into your Firebase Console. "screen_view" is actually an EVENT.
So in your case, to solve, you would actually have to get the dimension "eventName" and FILTER for the "screen_view" name.

Google Cloud Datastore runQuery returning 412 "no matching index found"

** UPDATE **
Thanks to Alfred Fuller for pointing out that I need to create a manual index for this query.
Unfortunately, using the JSON API, from a .NET application, there does not appear to be an officially supported way of doing so. In fact, there does not officially appear to be a way to do this at all from an app outside of App Engine, which is strange since the Cloud Datastore API was designed to allow access to the Datastore outside of App Engine.
The closest hack I could find was to POST the index definition using RPC to http://appengine.google.com/api/datastore/index/add. Can someone give me the raw spec for how to do this exactly (i.e. URL parameters, what exactly should the body look like, etc), perhaps using Fiddler to inspect the call made by appcfg.cmd?
** ORIGINAL QUESTION **
According to the docs, "a query can combine equality (EQUAL) filters for different properties, along with one or more inequality filters on a single property".
However, this query fails:
{
"query": {
"kinds": [
{
"name": "CodeProse.Pogo.Tests.TestPerson"
}
],
"filter": {
"compositeFilter": {
"operator": "and",
"filters": [
{
"propertyFilter": {
"operator": "equal",
"property": {
"name": "DepartmentCode"
},
"value": {
"integerValue": "123"
}
}
},
{
"propertyFilter": {
"operator": "greaterThan",
"property": {
"name": "HourlyRate"
},
"value": {
"doubleValue": 50
}
}
},
{
"propertyFilter": {
"operator": "lessThan",
"property": {
"name": "HourlyRate"
},
"value": {
"doubleValue": 100
}
}
}
]
}
}
}
}
with the following response:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "FAILED_PRECONDITION",
"message": "no matching index found.",
"locationType": "header",
"location": "If-Match"
}
],
"code": 412,
"message": "no matching index found."
}
}
The JSON API does not yet support local index generation, but we've documented a process that you can follow to generate the xml definition of the index at https://developers.google.com/datastore/docs/tools/indexconfig#Datastore_Manual_index_configuration
Please give this a shot and let us know if it doesn't work.
This is a temporary solution that we hope to replace with automatic local index generation as soon as we can.
The error "no matching index found." indicates that an index needs to be added for the query to work. See the auto index generation documentation.
In this case you need an index with the properties DepartmentCode and HourlyRate (in that order).
For gcloud-node I fixed it with those 3 links:
https://github.com/GoogleCloudPlatform/gcloud-node/issues/369
https://github.com/GoogleCloudPlatform/gcloud-node/blob/master/system-test/data/index.yaml
and most important link:
https://cloud.google.com/appengine/docs/python/config/indexconfig#Python_About_index_yaml to write your index.yaml file
As explained in the last link, an index is what allows complex queries to run faster by storing the result set of the queries in an index. When you get no matching index found it means that you tried to run a complex query involving order or filter. So to make your query work, you need to create your index on the google datastore indexes by creating a config file manually to define your indexes that represent the query you are trying to run. Here is how you fix:
create an index.yaml file in a folder named for example indexes in your app directory by following the directives for the python conf file: https://cloud.google.com/appengine/docs/python/config/indexconfig#Python_About_index_yaml or get inspiration from the gcloud-node tests in https://github.com/GoogleCloudPlatform/gcloud-node/blob/master/system-test/data/index.yaml
create the indexes from the config file with this command:
gcloud preview datastore create-indexes indexes/index.yaml
see https://cloud.google.com/sdk/gcloud/reference/preview/datastore/create-indexes
wait for the indexes to serve on your developer console in Cloud Datastore/Indexes, the interface should display "serving" once the index is built
once it is serving your query should work
For example for this query:
var q = ds.createQuery('project')
.filter('tags =', category)
.order('-date');
index.yaml looks like:
indexes:
- kind: project
ancestor: no
properties:
- name: tags
- name: date
direction: desc
Try not to order the result. After removing orderby(), it worked for me.

Google Calendar API is not showing event list

I am trying to retrieve events from a Google calendar. I am calling this URL:
GET https://www.googleapis.com/calendar/v3/calendars/riteshmehandiratta%40gmail.com/events
Authorization: Bearer ya29.AHES6ZSvz3O7V2p7z_k_ZWAiUZqWX35Eyx5V_J4XC5pVSNxLjS6CNzQ
and I am getting this response:
{
"kind": "calendar#events",
"etag": "\"ZrhdJMCgpoUK_a5fT7XOC6xn46g/_4_AQ2FVvAtAEiDFDj8_pH_usqc\"",
"summary": "riteshmehandiratta#gmail.com",
"updated": "2013-02-18T03:45:37.728Z",
"timeZone": "Asia/Calcutta",
"accessRole": "owner",
"defaultReminders": [
{
"method": "email",
"minutes": 10
},
{
"method": "popup",
"minutes": 10
}
],
"nextPageToken": "CigKGnR0ZG1xbjAyNHQ1Y3RycjYwY2x0ZGxtcTk0GAEggIDA28aNo-cT"
}
There are many events in the calendar for the past, future and for the current date.
Why its not giving the calendar event list?
there is definitely something weird here, in the response you are posting, i see you are getting the nextPageToken tag, so there actually ARE more results, you can call the next result "page", using a similar request with the variable pageToken added, something like
GET https://www.googleapis.com/calendar/v3/calendars/riteshmehandiratta%40gmail.com/events?pageToken=CigKGnR0ZG1xbjAyNHQ1Y3RycjYwY2x0ZGxtcTk0GAEggIDA28aNo-cT
that way you'll get more results.
Anyway this is weird because the nextPageToken doesn't show up if you don't limit the query with some variable like maxResults. Please check if you are not limiting the query somewhere else.
Maybe you can find useful for making test, the documentation page, that has at the bottom a request form that can build the query for you.
Hope this helps, regards
I saw the same problem. Sometimes the list API will return an empty item list with a nextPageToken, even if I did not limit the number of responses. The solution is to check if there is a nextPageToken, and make another request for the next page until you get a response without a nextPageToken.
I looped through the requests until there wasn't a nextPage token, appending the event lists to a local list, and this provided a full list of the events.

Resources