Creating a Firestore Structured Query for a Trigger
When using a Zap to trigger on new documents within a Firestore collection, it's important to build a Structured Query that returns the selected documents in the correct order, otherwise your Zap may never see the new documents.
The orderBy
property in your query needs to ensure that the new documents are at the "top" of the search results, so that the Zap can see those documents. In most cases, you'll want to use DESCENDING
, like this:
"orderBy": [{
"field": {
"fieldPath": "someKeyOfYourChoice"
},
"direction": "DESCENDING"
}]
If your field has spaces in it, you will need to surround it with backticks. For example:
"orderBy": [{
"field": {
"fieldPath": "`a field with spaces`"
},
"direction": "DESCENDING"
}]
You can learn more about the correct syntax/structure here: https://cloud.google.com/firestore/docs/reference/rest/v1beta1/StructuredQuery#Order
Creating a Firestore Structured Query for a Search
When using a Zap to search for a specific document within a Firestore collection, it's important to build a Structured Query that contains the appropriate where
clause, like this:
"where": {
"fieldFilter": {
"field": {
"fieldPath": "whenPlayed"
},
"op": "EQUAL",
"value": {
"stringValue": "some-compare-to-value"
}
}
}
In your Zap, the "compare to" value is probably something that you'll want to connect with a previous step within your Zap, using the "plus" button on the right-hand side of the input field within the Zap Editor.
You can learn more about the correct syntax/structure here: https://cloud.google.com/firestore/docs/reference/rest/v1beta1/StructuredQuery#Filter
Invalid data error (Couldn't parse JSON object)
Sometimes you will see an error that says "Invalid data; couldn't parse JSON object, array, or value. Perhaps you're using invalid characters in your key names."
This error occurs when the fields you are trying to send to Firebase contain invalid characters. Firebase prohibits key names from containing:
- . (period)
- $ (dollar sign)
- [ (left square bracket)
- ] (right square bracket)
(hash or pound sign)
- / (forward slash)
To get around the error, you will need to manually assign names to the keys. See the Customizing Fields to Store section for details.
My Firebase Zap isn't triggering when I add new records
New records need to appear at the top of your data so the Zap can see the most recent records. If you aren’t using push IDs, your records need to be ordered lexicographically or by priority so new records appear at the top.
A simple way to accomplish this is by calling setWithPriority
and using Firebase.ServerValue.TIMESTAMP
to order by timestamp.
Error: Empty key in "Path to data". Probably tried to use a field which was empty as part of the path
Make sure you remove the beginning and ending /
from the Path field.
For example, /customers/new/
becomes customers/new
.
I'm getting "Firebase paths/keys cannot contain the characters $ # . [ ]" but there are no invalid characters included in the path/keys
Users sometimes encounter this error if anything that is being supplied in the value has a pipe ( | ) character in it. For example:
This has to due with the way our system encodes key/value pairs. The recommend solution is to not include invalid characters in the value that is included or use a Formatter step to remove the characters.