0

In my Chatfuel block I collect a {{user input}} and POST a JSON in a Zapier webhook. So far so good. After that, my local Pyhon reads this JSON from Zapier storage successfully

url = 'https://store.zapier.com/api/records?secret=password'
response = urllib.request.urlopen(url).read().decode('utf-8')
data = json.loads(response)

and analyze it generating another JSON as output:

json0={
 "messages": [
   {"text": analysis_output}]
 }

Then Python3 posts this JSON in a GET webhook in Zapier:

import requests
r = requests.post('https://hooks.zapier.com/hooks/catch/2843360/8sx1xl/', json=json0)
r.status_code

enter image description here

enter image description here

Zapier Webhook successfully gets the JSON and sends it to Storage.

enter image description here

enter image description here

Key-Value pairs are set and then Chatfuel tries to read from storage:

GET https://store.zapier.com/api/records?secret=password2

But the JSON structure obtained is wrong, what was verified with this code:

url = 'https://store.zapier.com/api/records?secret=password2'
response = urllib.request.urlopen(url).read().decode('utf-8')
data = json.loads(response)
data

that returns:

{'messages': "text: Didn't know I could order several items"}

when the right one for Chatfuel to work should be:

{'messages': [{"text: Didn't know I could order several items"}]}

That is, there are two mais problems:

1) There is a missing " { [ " in the JSON

2) The JSON is appending new information to the existing one, instead of generating a brand new JSON, what cause the JSON to have 5 different parts.

I am looking for possible solutions for this issue.

razimbres
  • 4,715
  • 5
  • 23
  • 50
  • Hey there! Can you update your question to include exactly how you set the data in storage? Also, when in doubt, set the value of a key to be full json, and then parse/dump it as needed. This way, Zapier will never mess with how your data is stored. – xavdid Jan 10 '18 at 03:15
  • Question updated xavdid – razimbres Jan 10 '18 at 19:54

1 Answers1

0

David here, from the Zapier Platform team.

First off, you don't need quotes around your keys, we take care of that for you. Currently, your json will look like:

{ "'messages'": { "'text'": "<DATA FROM STEP 1>" } }

So the first change is to take out those.

Next, if you want to store an array, use the Push Value Onto List action instead. It takes a top-level key and stores your values in a key in that object called list. Given the following setup:

The resulting structure in JSON is

{ "demo": {"list": [ "5" ]} }

It seems like you want to store an extra level down; an array of json objects:

[ { "text": "this is text" } ]

That's not supported out of the box, as all list items are stored as strings. You can store json strings though, and parse them back into an object when you need to access them like an object!

Does that answer your question?

xavdid
  • 5,092
  • 3
  • 20
  • 32