google-cloud-firestoremake.com

Integromat automation problem - can't store an array in Google Firestore


Overview - I'm trying to sync some data to google firestore using Integromat. However I cannot seem to find the correct way to save an array as the output for a particular field. It seems like this should be easy but everything I've tried has failed so far.

Example, using the simplest form of this I have an input string like so

Input JSON: { "Brand": "Ford", "widgets": [0,1,2] }

And I basically just want to save that in the same structure into firebase, but I can't seem to configure the 'Update Firestore Document' module correctly. The closest I can do is to save it as a string, so it looks like this in firebase:

Output Firestore: { "Brand": "Ford", "widgets": "0,1,2" }

Below I'm attaching images of the integromat setup, showing how I'm trying to hookup the output values into the firestore module. When I try and pass the array directly I get the error message. "Array of objects expected in the parameter 'Value'"

00 - Basic 2 node setup in integromat

01 - input json in integromat

02 - output from input module

03 - saved ok as string

04 - set to store as array won't work

05 - error message

10 - desired output example

11 - actual output so far, save as string in firestore


Solution

  • I have reviewed your integration and one thing that needs to be fixed is the way you are passing the Array of Values in Google Cloud FireStore through Integromat. When reviewing the API the expected format for FireStore looks something like this,

    {
        "fields": {
            "widgets": {
                "arrayValue": {
                    "values": [
                        {
                            "integerValue": 0
                        },
                        {
                            "integerValue": 1
                        },
                        {
                            "integerValue": 2
                        }
                    ]
                }
            },
            "brand": {
                "stringValue": "Ford"
            }
        }
    }
    

    But, Since the app is developed in Integromat there are few changes while you are using Map instead of setting each item in Firestore Array. After reviewing it, Integromat expects objects with the following fields as arrays that you need to create and pass instead of using widgets[] as you have done in the current implementation.

    [
      value : 0,
      valueType : "integerValue"
    ]
    

    To achieve this, I have created the following Scenario(Not Sure how operation effective is it, but I get it working), enter image description here

    Data Structure Used is following which you can use through the generator and is used for Aggregator and Parse JSON module,

    [{
        "value": 0,
        "valueType": "integerValue"
    }, {
        "value": 1,
        "valueType": "integerValue"
    }, {
        "value": 2,
        "valueType": "integerValue"
    }]
    

    Array Aggregator in second last step will then aggregate value and valueType and will be used in Google FireStore as,

    enter image description here