Updating Zapier Storage programmatically

Viewed 188

I have been working with the Zapier storage api through the store.zapier.com endpoint and have been successful at setting and retrieving values. However I have recently found a need to store more complex information that I would like to update over time.

The data I am storing at the moment looks like the following:

{
"task_id_1": {"google_id": "google_id_1", "due_on": "2018-10-24T17:00:00.000Z"},
"task_id_2": {"google_id": "google_id_2", "due_on": "2018-10-23T20:00:00.000Z"}, 
"task_id_3": {"google_id": "google_id_3", "due_on": "2018-10-25T21:00:00.000Z"},
}

What I would like to do is update the "due_on" child value of any arbitrary task_id_n without having to delete and add it again. Reading the API information at store.zapier.com I see you can send a patch request combined with a specific action to have better control over the stored data. I attempt to use the patch request and the "set_child_value" action as follows:

def update_child(self, parent_key, child_key, child_value):

        header = self.generate_header()

        data = {
            "action" : "set_child_value",
            "data" : {
                "key" :  parent_key,
                "value" : {child_key : child_value}
            }
        }

        result = requests.patch(self.URL, headers=header, json=data)
        return result

When I send this request Zapier responds with a 200 status code but the storage is not updated. Any ideas what I might be missing?

2 Answers

I was able to update specific child values by modifying my request from a PATCH to a PUT. I had to do away with the data structure of:

data = {
            "action" : "set_child_value",
            "data" : {
                "key" :  parent_key,
                "value" : {child_key : child_value}
            }

and instead send it along as:

data = {
            parent_key : {child_key : child_value}
           }

My updated request looks like:

def update_child(self, parent_key, child_key, child_value):

        header = self.generate_header()

        data = {
            parent_key : {child_key : child_value}
            }


        result = requests.put(self.URL, headers=header, json=data)
        return result

Never really resolved the issue with the patch method I was attempting before, it does work for other Zapier storage methods such as "pop_from_list" and "push_to_list". Anyhow this is a suitable solution for anyone who runs into the same problem.

Zapier Store doesn't seem to be validating the request body past the "action" and "data" fields.

When you make a request with the "data" field set to an array, you trigger a validation error that describes the schema for the data field (What a way to find documentation for an API! smh).

In the request body, the data field schema for "set_child_value" action is:

{
    "action" : {
        "enum": [
            "delete",
            "increment_by",
            "set_child_value",
            "list_pop",
            "set_value_if",
            "remove_child_value",
            "list_push"
        ]
    },
    "data" : {
        "key" :  {
            "type": "object"
        },        
        "values" : {
            "type": "object"
        }
    }
}

Note that it's "values" and not "value"

Related