Hi, all -
I’m working on a Notion integration for a client that requires me to pass a complex API GET call, modify the return payload, and then pass that modified result into a PATCH call. (I’m trying to collect the body of one Notion page, then append it to another).
Initially, I thought about doing one Custom Request for the GET, a step to modify the return payload, then another Custom Request to PATCH. However, I need the solution to be scalable as the size/length of what the GET returns will vary significantly.
I settled on trying to do the entire thing via a Custom Code (Python). Here’s what I have so far:
source_id = input_data['source_id']
destination_id = input_data['destination_id']
headers = {
'Notion-Version': "2021-08-16",
'Authorization': "REDACTED",
'Content-Type': 'application/json'
}
get = requests.get(f"https://api.notion.com/v1/blocks/{source_id}/children", headers=headers).json()
new_payload = {'children': get['results']}
patch = requests.patch(f"https://api.notion.com/v1/blocks/{destination_id}/children", headers=headers, data=new_payload)
output = patch.text
Problem is, when I modify get
by replacing the results
key with children
(which I need to do in order for the subsequent PATCH to work), new_payload
becomes a Python dictionary, which is not JSON serializable. Therefore, when I run the code, patch returns an error 400: Error parsing JSON body.
Outside of Zapier, the solution would be to import json and use json.dumps() to convert new_payload
into the correct format, but I understand that isn’t an option within a Zapier code block. Is there any other way to convert a Python dictionary into a JSON serializable variable that I can then put in another request?
I also tried simply passing new_payload
into the output, and then doing a new Custom Request action using Data Pass-Through, but I run into the same “Error parsing JSON body” issue.
Thanks in advance!