Real World Use Case: A JSON file in your local windows machine needs to be sent to a webhook url. The code will be written in Python.
Copy and Run the Python code in your Python IDE
import requests
import json
# Path of the JSON file in your local machine
json_file_path = r'C:\Users\Bobot\jsonfile.json'
# The webhook URL
webhook_url = 'https://hooks.zapier.com/hooks/catch/7408007/u6sy0ca/'
# Read the JSON file
try:
with open(json_file_path, 'r') as file:
json_data = json.load(file)
except FileNotFoundError:
print(f"File not found: {json_file_path}")
exit(1)
except json.JSONDecodeError:
print(f"Invalid JSON format in file: {json_file_path}")
exit(1)
# Send the JSON data to the webhook
try:
response = requests.post(webhook_url, json=json_data)
response.raise_for_status() # Raise an error for bad status codes
print(f"Successfully sent JSON data to webhook. Response: {response.text}")
except requests.exceptions.RequestException as e:
print(f"Failed to send JSON data to webhook. Error: {e}")
