I managed to store a JSON file in Zapier Storage through a POST request and it worked fine. Now I want to fetch that JSON data using Python code running on my local machine. I can connect to the storage and see there’s data there, but I’m only getting metadata instead of the actual JSON content I stored.
Here’s my Python code:
import urllib.request
import json
import codecs
reader = codecs.getreader("utf-8")
api_key = "my_secret_key"
def FetchData(storage_id, api_key):
endpoint = 'https://hooks.zapier.com/storage/'
req = urllib.request.urlopen(endpoint)
result = json.load(reader(req))
return result
response = FetchData(storage_id, api_key)
print(response)
But this only returns:
{'attempt': '7b642c58-89fa-52e9-b41f-f284gbh8c791',
'id': '3c49e32b-1261-57eg-09d2-601b1e15c676',
'request_id': '7b642c58-89fa-52e9-b41f-f284gbh8c791',
'status': 'success'}
What I actually need is the stored JSON:
{'CustomerName': 'John Doe',
'Location': 'New York'}
What am I missing here?
To retrieve the stored JSON, ensure you include the storage_id in your URL and use the API key for authentication. Here’s a corrected example of your FetchData function:
def FetchData(storage_id, api_key):
endpoint = f’https://hooks.zapier.com/storage/{storage_id}’
req = urllib.request.Request(endpoint)
req.add_header(‘X-API-Key’, api_key)
response = urllib.request.urlopen(req)
result = json.load(reader(response))
return result
This should resolve your issue as it specifies which data to access.
Your endpoint URL is missing the storage_id parameter. Right now you’re hitting the base storage endpoint without telling it which data to grab. Fix your FetchData function by adding the storage_id to the URL: endpoint = f'https://hooks.zapier.com/storage/{storage_id}'
. You’re also not using that api_key parameter anywhere. Zapier Storage needs authentication, so add your API key to the request headers or as a query parameter. The metadata response you’re getting means the request is reaching Zapier but can’t access your stored content because there’s no storage identifier.
you’re missing the storage_id in your url and the api key isn’t being passed right. ditch urllib and use requests instead - it’s way easier. try requests.get(f'https://hooks.zapier.com/storage/{storage_id}', headers={'Authorization': f'Bearer {api_key}'})
. that metadata response usually means auth problems.